@amaster.ai/employee-runtime-connector 0.1.1-beta.136 → 0.1.1-beta.138

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.
@@ -6,6 +6,7 @@ export const BUILD_SUPPORTED_CAPABILITIES = Object.freeze([
6
6
  "run_wakeup",
7
7
  "context_envelope_v1",
8
8
  "managed_project_instructions_v1",
9
+ "artifact_template_catalog_v1",
9
10
  "final_model_context_attestation_v1",
10
11
  "runtime_actions_v2",
11
12
  "run_exit_live_path_closure_v1",
@@ -19,6 +20,23 @@ export const BUILD_SUPPORTED_CAPABILITIES = Object.freeze([
19
20
  ]);
20
21
 
21
22
  const DYNAMIC_READINESS = Object.freeze({
23
+ artifact_template_catalog_v1: {
24
+ reasonCode: "artifact_template_catalog_not_ready",
25
+ ready: (input) => {
26
+ const catalog = input.templateCatalog;
27
+ return catalog?.status === "ready"
28
+ && catalog.bundleAttested === true
29
+ && catalog.materialized === true
30
+ && catalog.readable === true
31
+ && catalog.executorReadable === true
32
+ && Number.isSafeInteger(catalog.fileCount)
33
+ && catalog.fileCount > 0
34
+ && typeof catalog.manifestSha256 === "string"
35
+ && /^[a-f0-9]{64}$/u.test(catalog.manifestSha256)
36
+ && typeof catalog.targetDir === "string"
37
+ && catalog.targetDir === input.runtimeTemplatesRoot;
38
+ },
39
+ },
22
40
  final_model_context_attestation_v1: {
23
41
  reasonCode: "managed_pi_executor_required",
24
42
  ready: (input) => input.runnerKind === "cloud_managed"
@@ -4654,6 +4654,7 @@ var AMASTER_RUNTIME_CONNECTOR_CAPABILITIES = [
4654
4654
  "run_wakeup",
4655
4655
  "context_envelope_v1",
4656
4656
  "managed_project_instructions_v1",
4657
+ "artifact_template_catalog_v1",
4657
4658
  "final_model_context_attestation_v1",
4658
4659
  "model_call",
4659
4660
  "model_call_output_contract_v1",
@@ -15573,9 +15574,9 @@ var completeCompanyCreationReviewSchema = external_exports.object({
15573
15574
  }).strict();
15574
15575
 
15575
15576
  // src/amaster-runtime-daemon.mjs
15576
- import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync15, lstatSync as lstatSync9, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync2, readFileSync as readFileSync17, readdirSync as readdirSync11, realpathSync as realpathSync7, renameSync as renameSync9, rmSync as rmSync9, statSync as statSync9, symlinkSync as symlinkSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync11 } from "node:fs";
15577
+ import { chmodSync as chmodSync7, copyFileSync as copyFileSync2, existsSync as existsSync15, lstatSync as lstatSync9, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync2, readFileSync as readFileSync17, readdirSync as readdirSync11, realpathSync as realpathSync7, renameSync as renameSync9, rmSync as rmSync9, statSync as statSync10, symlinkSync as symlinkSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync11 } from "node:fs";
15577
15578
  import { arch as arch3, homedir as homedir3, hostname as hostname2, platform as platform3, tmpdir } from "node:os";
15578
- import { basename as basename6, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute9, join as join16, relative as relative8, resolve as resolve13 } from "node:path";
15579
+ import { basename as basename6, delimiter as delimiter3, dirname as dirname11, extname as extname3, isAbsolute as isAbsolute9, join as join16, relative as relative8, resolve as resolve14 } from "node:path";
15579
15580
  import { spawn, spawnSync as spawnSync5 } from "node:child_process";
15580
15581
 
15581
15582
  // src/amaster-runtime-daemon/common.mjs
@@ -24384,7 +24385,7 @@ function agentInstructionDeliveryAudit(bundle, delivery) {
24384
24385
  // src/amaster-runtime-daemon/config-state.mjs
24385
24386
  import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync10, renameSync as renameSync7, rmSync as rmSync6, writeFileSync as writeFileSync8 } from "node:fs";
24386
24387
  import { homedir as homedir2, hostname } from "node:os";
24387
- import { dirname as dirname7, join as join9 } from "node:path";
24388
+ import { dirname as dirname7, join as join9, parse as parse2, resolve as resolve5 } from "node:path";
24388
24389
 
24389
24390
  // src/amaster-runtime-daemon/capability-registry.mjs
24390
24391
  var BUILD_SUPPORTED_CAPABILITIES = Object.freeze([
@@ -24395,6 +24396,7 @@ var BUILD_SUPPORTED_CAPABILITIES = Object.freeze([
24395
24396
  "run_wakeup",
24396
24397
  "context_envelope_v1",
24397
24398
  "managed_project_instructions_v1",
24399
+ "artifact_template_catalog_v1",
24398
24400
  "final_model_context_attestation_v1",
24399
24401
  "runtime_actions_v2",
24400
24402
  "run_exit_live_path_closure_v1",
@@ -24407,6 +24409,13 @@ var BUILD_SUPPORTED_CAPABILITIES = Object.freeze([
24407
24409
  "headed_browser_auth"
24408
24410
  ]);
24409
24411
  var DYNAMIC_READINESS = Object.freeze({
24412
+ artifact_template_catalog_v1: {
24413
+ reasonCode: "artifact_template_catalog_not_ready",
24414
+ ready: (input) => {
24415
+ const catalog = input.templateCatalog;
24416
+ return catalog?.status === "ready" && catalog.bundleAttested === true && catalog.materialized === true && catalog.readable === true && catalog.executorReadable === true && Number.isSafeInteger(catalog.fileCount) && catalog.fileCount > 0 && typeof catalog.manifestSha256 === "string" && /^[a-f0-9]{64}$/u.test(catalog.manifestSha256) && typeof catalog.targetDir === "string" && catalog.targetDir === input.runtimeTemplatesRoot;
24417
+ }
24418
+ },
24410
24419
  final_model_context_attestation_v1: {
24411
24420
  reasonCode: "managed_pi_executor_required",
24412
24421
  ready: (input) => input.runnerKind === "cloud_managed" && input.executors.some((executor) => executor.kind === "pi")
@@ -24494,6 +24503,14 @@ function runtimeHome(env) {
24494
24503
  env.AMASTER_RUNTIME_STATE_HOME || env.AMASTER_RUNTIME_HOME || join9(homedir2(), ".amaster-employee")
24495
24504
  ));
24496
24505
  }
24506
+ function runtimeTemplatesRoot(env, home) {
24507
+ const configured = String(env.AMASTER_RUNTIME_TEMPLATES_ROOT ?? "").trim();
24508
+ const resolved = configured ? resolve5(expandHomePath(configured)) : resolve5(String(env.PI_CODING_AGENT_DIR ?? "")) === "/data/.pi" ? "/data/templates" : resolve5(join9(home, "templates"));
24509
+ if (resolved === parse2(resolved).root) {
24510
+ throw new Error("AMASTER_RUNTIME_TEMPLATES_ROOT must not be a filesystem root");
24511
+ }
24512
+ return resolved;
24513
+ }
24497
24514
  function stateFilePath(env) {
24498
24515
  return env.AMASTER_DAEMON_STATE_FILE ? expandHomePath(String(env.AMASTER_DAEMON_STATE_FILE)) : join9(runtimeHome(env), "runtime-connector-state.json");
24499
24516
  }
@@ -24553,6 +24570,7 @@ function buildConfig(env = process.env, flags = {}) {
24553
24570
  const token = String(flags.token ?? env.AMASTER_CONNECTOR_TOKEN ?? state.connectorToken ?? "");
24554
24571
  const authHeader = String(flags.authHeader ?? env.AMASTER_CONNECTOR_AUTH_HEADER ?? "");
24555
24572
  const home = runtimeHome(env);
24573
+ const templatesRoot = runtimeTemplatesRoot(env, home);
24556
24574
  const runtimeWorkspacesRoot = expandHomePath(
24557
24575
  String(flags.runtimeWorkspacesRoot ?? env.AMASTER_RUNTIME_WORKSPACES_ROOT ?? join9(home, "workspaces"))
24558
24576
  );
@@ -24677,6 +24695,7 @@ function buildConfig(env = process.env, flags = {}) {
24677
24695
  300
24678
24696
  ),
24679
24697
  browserSessionStateRoot,
24698
+ runtimeTemplatesRoot: templatesRoot,
24680
24699
  runtimeWorkspacesRoot,
24681
24700
  state
24682
24701
  };
@@ -26385,7 +26404,7 @@ async function postRuntimeConnectorJsonWithRetry(config, path, payload, options
26385
26404
  } catch (error) {
26386
26405
  lastError = error;
26387
26406
  if (attempt >= maxAttempts || !retryableRuntimeConnectorPost(error)) throw error;
26388
- if (delayMs > 0) await new Promise((resolve14) => setTimeout(resolve14, delayMs));
26407
+ if (delayMs > 0) await new Promise((resolve15) => setTimeout(resolve15, delayMs));
26389
26408
  }
26390
26409
  }
26391
26410
  throw lastError;
@@ -26411,7 +26430,7 @@ var bestEffortPostJson = bestEffortPostRuntimeConnectorJson;
26411
26430
  // src/amaster-runtime-daemon/runtime-artifact-upload.mjs
26412
26431
  import { createHash as createHash9 } from "node:crypto";
26413
26432
  import { closeSync as closeSync2, constants, fstatSync, lstatSync as lstatSync5, openSync as openSync2, readFileSync as readFileSync11, realpathSync as realpathSync5 } from "node:fs";
26414
- import { isAbsolute as isAbsolute5, relative as relative4, resolve as resolve5 } from "node:path";
26433
+ import { isAbsolute as isAbsolute5, relative as relative4, resolve as resolve6 } from "node:path";
26415
26434
  var SHA256_PATTERN3 = /^[a-f0-9]{64}$/;
26416
26435
  function requiredString(value, name) {
26417
26436
  if (typeof value !== "string" || !value.trim()) throw new Error(`Runtime Artifact ${name} is required`);
@@ -26430,9 +26449,9 @@ function sameFileSnapshot(left, right) {
26430
26449
  return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
26431
26450
  }
26432
26451
  function readOwnedWorkspaceFile(rootPath, sourceRelativePath, label = "Runtime workspace file", options = {}) {
26433
- const root = realpathSync5(resolve5(rootPath));
26452
+ const root = realpathSync5(resolve6(rootPath));
26434
26453
  const relativePath = ownedRelativePath(sourceRelativePath);
26435
- const sourcePath = resolve5(root, relativePath);
26454
+ const sourcePath = resolve6(root, relativePath);
26436
26455
  const pathStat = lstatSync5(sourcePath);
26437
26456
  if (!pathStat.isFile() || pathStat.isSymbolicLink() || !pathWithin2(realpathSync5(sourcePath), root)) {
26438
26457
  throw new Error(`${label} source is not an owned regular file`);
@@ -26748,7 +26767,7 @@ function createRuntimeArtifactIngestQueue({ ingest, onError }) {
26748
26767
  // src/amaster-runtime-daemon/workspace-guard.mjs
26749
26768
  import { createHash as createHash11 } from "node:crypto";
26750
26769
  import { existsSync as existsSync9, mkdirSync as mkdirSync7, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
26751
- import { basename as basename4, join as join10, isAbsolute as isAbsolute6, relative as relative5, resolve as resolve6 } from "node:path";
26770
+ import { basename as basename4, join as join10, isAbsolute as isAbsolute6, relative as relative5, resolve as resolve7 } from "node:path";
26752
26771
  function pathWithin3(candidate, root) {
26753
26772
  const rel = relative5(root, candidate);
26754
26773
  return rel === "" || !rel.startsWith("..") && !isAbsolute6(rel);
@@ -26757,10 +26776,10 @@ function resolveWorkspaceCwd(config, command) {
26757
26776
  const payload = asRecord(command.payload);
26758
26777
  const requested = readString(payload.workspacePath);
26759
26778
  const fallback = config.workspaceBindings[0] ?? process.cwd();
26760
- const cwd = realpathSync6(resolve6(expandHomePath(requested ?? fallback)));
26779
+ const cwd = realpathSync6(resolve7(expandHomePath(requested ?? fallback)));
26761
26780
  const allowlist = config.workspaceBindings.flatMap((entry) => {
26762
26781
  try {
26763
- return [realpathSync6(resolve6(expandHomePath(entry)))];
26782
+ return [realpathSync6(resolve7(expandHomePath(entry)))];
26764
26783
  } catch {
26765
26784
  return [];
26766
26785
  }
@@ -26803,7 +26822,7 @@ function workspaceLabel(sourceWorkspacePath, payload) {
26803
26822
  return readString(payload.workspaceName) ?? readString(payload.projectName) ?? readString(context.projectName) ?? basename4(sourceWorkspacePath) ?? "workspace";
26804
26823
  }
26805
26824
  function workspacesRoot(config) {
26806
- const root = resolve6(expandHomePath(config.runtimeWorkspacesRoot ?? "~/.amaster-employee/workspaces"));
26825
+ const root = resolve7(expandHomePath(config.runtimeWorkspacesRoot ?? "~/.amaster-employee/workspaces"));
26807
26826
  mkdirSync7(root, { recursive: true });
26808
26827
  return realpathSync6(root);
26809
26828
  }
@@ -26844,7 +26863,7 @@ function resolveExecutionWorkspace(config, command, opts = {}) {
26844
26863
 
26845
26864
  // src/amaster-runtime-daemon/workspace-gc.mjs
26846
26865
  import { existsSync as existsSync10, readdirSync as readdirSync7, statSync as statSync5 } from "node:fs";
26847
- import { join as join11, resolve as resolve7 } from "node:path";
26866
+ import { join as join11, resolve as resolve8 } from "node:path";
26848
26867
  function readIsoTime(value) {
26849
26868
  if (typeof value !== "string" || !value.trim()) return null;
26850
26869
  const time = new Date(value).getTime();
@@ -26926,7 +26945,7 @@ function summarizeWorkdir(path, manifest, nowMs) {
26926
26945
  };
26927
26946
  }
26928
26947
  function planManagedWorkspaceGcDryRun(input) {
26929
- const root = resolve7(String(input.root ?? ""));
26948
+ const root = resolve8(String(input.root ?? ""));
26930
26949
  const now = input.now instanceof Date ? input.now : /* @__PURE__ */ new Date();
26931
26950
  const nowMs = now.getTime();
26932
26951
  const ttlHours = Math.max(1, Number(input.ttlHours ?? 72));
@@ -26973,7 +26992,9 @@ function planManagedWorkspaceGcDryRun(input) {
26973
26992
  // src/amaster-runtime-daemon/preset-templates.mjs
26974
26993
  import { createHash as createHash12 } from "node:crypto";
26975
26994
  import {
26995
+ accessSync,
26976
26996
  chmodSync as chmodSync5,
26997
+ constants as constants2,
26977
26998
  existsSync as existsSync11,
26978
26999
  lstatSync as lstatSync6,
26979
27000
  mkdirSync as mkdirSync8,
@@ -26982,10 +27003,11 @@ import {
26982
27003
  readdirSync as readdirSync8,
26983
27004
  renameSync as renameSync8,
26984
27005
  rmSync as rmSync7,
27006
+ statSync as statSync6,
26985
27007
  unlinkSync as unlinkSync2,
26986
27008
  writeFileSync as writeFileSync9
26987
27009
  } from "node:fs";
26988
- import { dirname as dirname8, extname, isAbsolute as isAbsolute7, join as join12, parse as parse2, resolve as resolve8, sep as sep3 } from "node:path";
27010
+ import { dirname as dirname8, extname, isAbsolute as isAbsolute7, join as join12, parse as parse3, resolve as resolve9, sep as sep3 } from "node:path";
26989
27011
  import { fileURLToPath } from "node:url";
26990
27012
  var PRESET_TEMPLATE_MANIFEST_FILE = ".mirrorx-preset-templates.json";
26991
27013
  var MAX_PRESET_TEMPLATE_FILES = 256;
@@ -27002,8 +27024,42 @@ function lstatIfExists(path) {
27002
27024
  throw error;
27003
27025
  }
27004
27026
  }
27027
+ function modeAllows(stat, identity2, ownerBit, groupBit, otherBit) {
27028
+ if (!identity2 || identity2.uid === 0) return true;
27029
+ if (stat.uid === identity2.uid) return (stat.mode & ownerBit) !== 0;
27030
+ if (stat.gid === identity2.gid) return (stat.mode & groupBit) !== 0;
27031
+ return (stat.mode & otherBit) !== 0;
27032
+ }
27033
+ function assertCatalogReadableByExecutor(targetDir, fileNames, identity2) {
27034
+ if (!identity2) {
27035
+ accessSync(targetDir, constants2.R_OK | constants2.X_OK);
27036
+ for (const name of fileNames) accessSync(join12(targetDir, name), constants2.R_OK);
27037
+ return;
27038
+ }
27039
+ let current = targetDir;
27040
+ for (; ; ) {
27041
+ const stat = statSync6(current);
27042
+ if (!stat.isDirectory() || !modeAllows(stat, identity2, 64, 8, 1)) {
27043
+ throw new Error(`preset_template_executor_path_unreadable: ${current}`);
27044
+ }
27045
+ const parent = dirname8(current);
27046
+ if (parent === current) break;
27047
+ current = parent;
27048
+ }
27049
+ const targetStat = statSync6(targetDir);
27050
+ if (!modeAllows(targetStat, identity2, 256, 32, 4)) {
27051
+ throw new Error(`preset_template_executor_catalog_unreadable: ${targetDir}`);
27052
+ }
27053
+ for (const name of fileNames) {
27054
+ const path = join12(targetDir, name);
27055
+ const stat = statSync6(path);
27056
+ if (!stat.isFile() || !modeAllows(stat, identity2, 256, 32, 4)) {
27057
+ throw new Error(`preset_template_executor_file_unreadable: ${name}`);
27058
+ }
27059
+ }
27060
+ }
27005
27061
  function validTemplateName(value) {
27006
- return typeof value === "string" && value.length > 0 && value !== "." && value !== ".." && !value.includes("\0") && !value.includes("/") && !value.includes("\\") && !isAbsolute7(value) && parse2(value).base === value && extname(value).toLowerCase() === ".md";
27062
+ return typeof value === "string" && value.length > 0 && value !== "." && value !== ".." && !value.includes("\0") && !value.includes("/") && !value.includes("\\") && !isAbsolute7(value) && parse3(value).base === value && extname(value).toLowerCase() === ".md";
27007
27063
  }
27008
27064
  function readManifest(manifestPath, { strict }) {
27009
27065
  try {
@@ -27060,8 +27116,8 @@ function removeRetiredPresetFiles(targetDir, previousManifest, nextNames) {
27060
27116
  }
27061
27117
  }
27062
27118
  function materializeBundledPresetTemplates(input) {
27063
- const sourceDir = resolve8(input.sourceDir);
27064
- const targetDir = resolve8(input.targetDir);
27119
+ const sourceDir = resolve9(input.sourceDir);
27120
+ const targetDir = resolve9(input.targetDir);
27065
27121
  if (sourceDir === targetDir || sourceDir.startsWith(`${targetDir}${sep3}`) || targetDir.startsWith(`${sourceDir}${sep3}`)) {
27066
27122
  throw new Error("preset_template_source_target_overlap");
27067
27123
  }
@@ -27101,25 +27157,42 @@ function materializeBundledPresetTemplates(input) {
27101
27157
  targetDir
27102
27158
  };
27103
27159
  }
27104
- function runtimePresetTemplateTarget(env = process.env) {
27105
- const configured = typeof env.AMASTER_RUNTIME_TEMPLATES_ROOT === "string" ? env.AMASTER_RUNTIME_TEMPLATES_ROOT.trim() : "";
27106
- if (configured) return resolve8(configured);
27107
- const piHome = typeof env.PI_CODING_AGENT_DIR === "string" ? resolve8(env.PI_CODING_AGENT_DIR) : null;
27108
- return piHome === "/data/.pi" ? "/data/templates" : null;
27109
- }
27110
- function materializeRuntimePresetTemplates(env = process.env, options = {}) {
27111
- const targetDir = options.targetDir ?? runtimePresetTemplateTarget(env);
27112
- if (!targetDir) return { status: "skipped", reason: "not_pi_cli_runtime" };
27113
- const sourceDir = options.sourceDir ?? fileURLToPath(new URL("./templates/", import.meta.url));
27160
+ function materializeRuntimePresetTemplates(input) {
27161
+ const sourceDir = input.sourceDir ?? fileURLToPath(new URL("./templates/", import.meta.url));
27162
+ const materialized = materializeBundledPresetTemplates({
27163
+ sourceDir,
27164
+ targetDir: input.targetDir
27165
+ });
27166
+ const manifestBody = readFileSync12(
27167
+ join12(materialized.targetDir, PRESET_TEMPLATE_MANIFEST_FILE)
27168
+ );
27169
+ const manifest = JSON.parse(manifestBody.toString("utf8"));
27170
+ for (const file of manifest.files) {
27171
+ const body = readFileSync12(join12(materialized.targetDir, file.name));
27172
+ if (sha256(body) !== file.sha256) {
27173
+ throw new Error(`preset_template_materialized_digest_mismatch: ${file.name}`);
27174
+ }
27175
+ }
27176
+ assertCatalogReadableByExecutor(
27177
+ materialized.targetDir,
27178
+ [PRESET_TEMPLATE_MANIFEST_FILE, ...manifest.files.map((file) => file.name)],
27179
+ input.executorIdentity ?? null
27180
+ );
27114
27181
  return {
27115
27182
  status: "ready",
27116
- ...materializeBundledPresetTemplates({ sourceDir, targetDir })
27183
+ ready: true,
27184
+ bundleAttested: true,
27185
+ materialized: true,
27186
+ readable: true,
27187
+ executorReadable: true,
27188
+ manifestSha256: sha256(manifestBody),
27189
+ ...materialized
27117
27190
  };
27118
27191
  }
27119
27192
 
27120
27193
  // src/amaster-runtime-daemon/runtime-status-summary.mjs
27121
- import { existsSync as existsSync12, readdirSync as readdirSync9, statSync as statSync6 } from "node:fs";
27122
- import { dirname as dirname9, join as join13, resolve as resolve9 } from "node:path";
27194
+ import { existsSync as existsSync12, readdirSync as readdirSync9, statSync as statSync7 } from "node:fs";
27195
+ import { dirname as dirname9, join as join13, resolve as resolve10 } from "node:path";
27123
27196
  function runtimeStatusDirectoryEntries(path) {
27124
27197
  try {
27125
27198
  return readdirSync9(path, { withFileTypes: true });
@@ -27135,7 +27208,7 @@ function runtimeStatusDirectorySizeBytes(path) {
27135
27208
  if (!current) continue;
27136
27209
  let stat;
27137
27210
  try {
27138
- stat = statSync6(current, { throwIfNoEntry: false });
27211
+ stat = statSync7(current, { throwIfNoEntry: false });
27139
27212
  } catch {
27140
27213
  continue;
27141
27214
  }
@@ -27207,7 +27280,7 @@ function runtimeStatusOutboxDir(config) {
27207
27280
  }
27208
27281
  function runtimeStatusRunCompletionDir(config) {
27209
27282
  const explicit = config.AMASTER_RUN_COMPLETION_STATE_DIR ?? config.runCompletionStateDir;
27210
- if (typeof explicit === "string" && explicit.trim()) return resolve9(explicit);
27283
+ if (typeof explicit === "string" && explicit.trim()) return resolve10(explicit);
27211
27284
  const statePath = config.AMASTER_DAEMON_STATE_FILE ?? config.daemonStateFile;
27212
27285
  return join13(dirname9(stateFilePath({
27213
27286
  AMASTER_DAEMON_STATE_FILE: statePath
@@ -27219,7 +27292,7 @@ function countRuntimeStatusJsonEntries(dir) {
27219
27292
  }
27220
27293
  function summarizeRuntimeLocalState(input) {
27221
27294
  const config = input.config ?? {};
27222
- const root = resolve9(String(config.AMASTER_RUNTIME_WORKSPACES_ROOT ?? config.runtimeWorkspacesRoot ?? input.runtimeWorkspacesRoot ?? ""));
27295
+ const root = resolve10(String(config.AMASTER_RUNTIME_WORKSPACES_ROOT ?? config.runtimeWorkspacesRoot ?? input.runtimeWorkspacesRoot ?? ""));
27223
27296
  const now = input.now instanceof Date ? input.now : /* @__PURE__ */ new Date();
27224
27297
  const workdirs = walkRuntimeStatusManagedWorkdirs(root);
27225
27298
  let managedWorkdirBytes = 0;
@@ -27477,7 +27550,7 @@ function resolvePiModelContextBudget({
27477
27550
  // src/amaster-runtime-daemon/pi-final-context-attestor.mjs
27478
27551
  import { createHash as createHash13 } from "node:crypto";
27479
27552
  import { lstatSync as lstatSync7, readFileSync as readFileSync14 } from "node:fs";
27480
- import { resolve as resolve10 } from "node:path";
27553
+ import { resolve as resolve11 } from "node:path";
27481
27554
  var MANAGED_PI_FINAL_CONTEXT_ATTESTOR_FILENAME = "amaster-final-model-context-attestor.js";
27482
27555
  var MANAGED_PI_PROJECT_INSTRUCTION_FILENAME = "amaster-project-instructions.js";
27483
27556
  var MANAGED_PI_FINAL_CONTEXT_SCHEMA_VERSION = "mirrorx.pi-final-model-context-attestation.v4";
@@ -27502,7 +27575,7 @@ function requiredInteger(value, name, minimum = 0) {
27502
27575
  return value;
27503
27576
  }
27504
27577
  function managedPiProjectInstructionExtensionSource(input) {
27505
- const projectInstructionPath = resolve10(requiredString3(input.projectInstructionPath, "projectInstructionPath"));
27578
+ const projectInstructionPath = resolve11(requiredString3(input.projectInstructionPath, "projectInstructionPath"));
27506
27579
  const projectInstructionSha256 = requiredString3(input.projectInstructionSha256, "projectInstructionSha256");
27507
27580
  if (!/^[a-f0-9]{64}$/.test(projectInstructionSha256)) {
27508
27581
  throw new Error("pi_project_instruction_extension_invalid: projectInstructionSha256");
@@ -27558,8 +27631,8 @@ export default function amasterProjectInstructions(pi) {
27558
27631
  function managedPiFinalContextAttestorExtensionSource(input) {
27559
27632
  const contract = {
27560
27633
  schemaVersion: MANAGED_PI_FINAL_CONTEXT_SCHEMA_VERSION,
27561
- receiptPath: resolve10(requiredString3(input.receiptPath, "receiptPath")),
27562
- projectInstructionPath: resolve10(requiredString3(input.projectInstructionPath, "projectInstructionPath")),
27634
+ receiptPath: resolve11(requiredString3(input.receiptPath, "receiptPath")),
27635
+ projectInstructionPath: resolve11(requiredString3(input.projectInstructionPath, "projectInstructionPath")),
27563
27636
  projectInstructionSha256: requiredString3(input.projectInstructionSha256, "projectInstructionSha256"),
27564
27637
  provider: requiredString3(input.provider, "provider"),
27565
27638
  model: requiredString3(input.model, "model"),
@@ -27826,7 +27899,7 @@ export default function amasterFinalModelContextAttestor(pi) {
27826
27899
  `;
27827
27900
  }
27828
27901
  function readPiFinalContextAttestation(input) {
27829
- const receiptPath = resolve10(requiredString3(input.receiptPath, "receiptPath"));
27902
+ const receiptPath = resolve11(requiredString3(input.receiptPath, "receiptPath"));
27830
27903
  const stat = lstatSync7(receiptPath);
27831
27904
  if (!stat.isFile() || stat.isSymbolicLink()) throw new Error("pi_final_context_attestation_unsafe");
27832
27905
  const receipt = JSON.parse(readFileSync14(receiptPath, "utf8"));
@@ -27860,8 +27933,8 @@ function readPiFinalContextAttestation(input) {
27860
27933
  // src/amaster-runtime-daemon/workspace-status.mjs
27861
27934
  import { spawnSync as spawnSync4 } from "node:child_process";
27862
27935
  import { createHash as createHash14 } from "node:crypto";
27863
- import { existsSync as existsSync13, readdirSync as readdirSync10, readFileSync as readFileSync15, statSync as statSync7 } from "node:fs";
27864
- import { basename as basename5, extname as extname2, isAbsolute as isAbsolute8, join as join14, relative as relative6, resolve as resolve11 } from "node:path";
27936
+ import { existsSync as existsSync13, readdirSync as readdirSync10, readFileSync as readFileSync15, statSync as statSync8 } from "node:fs";
27937
+ import { basename as basename5, extname as extname2, isAbsolute as isAbsolute8, join as join14, relative as relative6, resolve as resolve12 } from "node:path";
27865
27938
  var WORKSPACE_RUNTIME_SERVICES_FILENAME = ".amaster-runtime-services.json";
27866
27939
  var ARTIFACT_EXTENSIONS = /* @__PURE__ */ new Map([
27867
27940
  [".md", "markdown"],
@@ -27958,7 +28031,7 @@ function artifactSha256(filePath, relativePath, stat, opts = {}) {
27958
28031
  return hash;
27959
28032
  }
27960
28033
  function scanArtifactCandidates(cwd, opts = {}) {
27961
- const root = resolve11(cwd);
28034
+ const root = resolve12(cwd);
27962
28035
  const maxCandidates = opts.maxCandidates ?? MAX_CANDIDATES;
27963
28036
  const maxEntries = opts.maxEntries ?? MAX_SCAN_ENTRIES;
27964
28037
  const candidates = [];
@@ -27993,11 +28066,11 @@ function scanArtifactCandidates(cwd, opts = {}) {
27993
28066
  const type = ARTIFACT_EXTENSIONS.get(ext) ?? "file";
27994
28067
  let stat;
27995
28068
  try {
27996
- stat = statSync7(fullPath);
28069
+ stat = statSync8(fullPath);
27997
28070
  } catch {
27998
28071
  continue;
27999
28072
  }
28000
- if (!statusPathWithin(resolve11(fullPath), root) || stat.size > MAX_HASH_BYTES) continue;
28073
+ if (!statusPathWithin(resolve12(fullPath), root) || stat.size > MAX_HASH_BYTES) continue;
28001
28074
  candidates.push({
28002
28075
  relativePath,
28003
28076
  name: basename5(fullPath),
@@ -28057,7 +28130,7 @@ function sanitizeRuntimeService(entry) {
28057
28130
  };
28058
28131
  }
28059
28132
  function readRuntimeServicesSnapshot(cwd) {
28060
- const snapshotPath = join14(resolve11(cwd), WORKSPACE_RUNTIME_SERVICES_FILENAME);
28133
+ const snapshotPath = join14(resolve12(cwd), WORKSPACE_RUNTIME_SERVICES_FILENAME);
28061
28134
  if (!existsSync13(snapshotPath)) return [];
28062
28135
  try {
28063
28136
  const parsed = JSON.parse(readFileSync15(snapshotPath, "utf8"));
@@ -28299,12 +28372,12 @@ import {
28299
28372
  mkdirSync as mkdirSync9,
28300
28373
  readFileSync as readFileSync16,
28301
28374
  rmSync as rmSync8,
28302
- statSync as statSync8,
28375
+ statSync as statSync9,
28303
28376
  writeFileSync as writeFileSync10
28304
28377
  } from "node:fs";
28305
28378
  import { createServer as createHttpServer } from "node:http";
28306
28379
  import { connect as connectTcp, isIP } from "node:net";
28307
- import { dirname as dirname10, join as join15, relative as relative7, resolve as resolve12 } from "node:path";
28380
+ import { dirname as dirname10, join as join15, relative as relative7, resolve as resolve13 } from "node:path";
28308
28381
  var MARKER_NAME = ".amaster-browser-session.json";
28309
28382
  var HUMAN_LEASE_INACTIVITY_MS = 30 * 60 * 1e3;
28310
28383
  var HUMAN_LEASE_HARD_CAP_MS = 2 * 60 * 60 * 1e3;
@@ -28516,14 +28589,14 @@ function pathWithin4(candidate, root) {
28516
28589
  function ensureExecutable(path) {
28517
28590
  if (!path) return false;
28518
28591
  try {
28519
- const stat = statSync8(path);
28592
+ const stat = statSync9(path);
28520
28593
  return stat.isFile() && (stat.mode & 73) !== 0;
28521
28594
  } catch {
28522
28595
  return false;
28523
28596
  }
28524
28597
  }
28525
28598
  function ensurePrivateRoot(stateRoot) {
28526
- const root = resolve12(stateRoot);
28599
+ const root = resolve13(stateRoot);
28527
28600
  if (existsSync14(root) && lstatSync8(root).isSymbolicLink()) {
28528
28601
  throw brokerError("browser_session_profile_root_symlink");
28529
28602
  }
@@ -28549,7 +28622,7 @@ function expectedOwner(payload) {
28549
28622
  }
28550
28623
  function exactProfile(stateRoot, payload, { create = false } = {}) {
28551
28624
  const root = ensurePrivateRoot(stateRoot);
28552
- const profilePath = resolve12(root, profileName(payload));
28625
+ const profilePath = resolve13(root, profileName(payload));
28553
28626
  if (!pathWithin4(profilePath, root) || dirname10(profilePath) !== root) {
28554
28627
  throw brokerError("browser_session_profile_path_invalid");
28555
28628
  }
@@ -28853,8 +28926,8 @@ function createBrowserSessionBroker({
28853
28926
  throw brokerError("browser_session_agent_lease_expired");
28854
28927
  }
28855
28928
  const root = ensurePrivateRoot(stateRoot);
28856
- const expectedPath = resolve12(root, profileName(payload));
28857
- if (resolve12(payload.userDataDir) !== expectedPath) {
28929
+ const expectedPath = resolve13(root, profileName(payload));
28930
+ if (resolve13(payload.userDataDir) !== expectedPath) {
28858
28931
  throw brokerError("browser_session_profile_path_invalid");
28859
28932
  }
28860
28933
  const marker = JSON.parse(readFileSync16(join15(expectedPath, MARKER_NAME), "utf8"));
@@ -29020,7 +29093,7 @@ function createSourceCompletionStopPolicy({
29020
29093
  }
29021
29094
 
29022
29095
  // src/amaster-runtime-daemon.mjs
29023
- var CONNECTOR_VERSION = "0.1.1-beta.136";
29096
+ var CONNECTOR_VERSION = "0.1.1-beta.138";
29024
29097
  var CONNECTOR_CONTRACT_VERSION = "2026-06-04.v1";
29025
29098
  var SOURCE_ACQUISITION_CAPABILITY2 = source_acquisition_compatibility_default.profileVersion;
29026
29099
  var daemonRequire = createRequire(import.meta.url);
@@ -29079,7 +29152,7 @@ function resultOutboxPendingCount(config) {
29079
29152
  }
29080
29153
  function runCompletionStateDir(config) {
29081
29154
  const explicit = readString(process.env.AMASTER_RUN_COMPLETION_STATE_DIR);
29082
- if (explicit) return resolve13(expandHomePath(explicit));
29155
+ if (explicit) return resolve14(expandHomePath(explicit));
29083
29156
  return join16(dirname11(stateFilePath(process.env)), "run-completion-state");
29084
29157
  }
29085
29158
  function runCompletionStateInvalidDir(config) {
@@ -29243,7 +29316,7 @@ function piExtraArgsDiagnostics(value) {
29243
29316
  }
29244
29317
  function safeExpandPath(value) {
29245
29318
  const text = readString(value);
29246
- return text ? resolve13(expandHomePath(text)) : null;
29319
+ return text ? resolve14(expandHomePath(text)) : null;
29247
29320
  }
29248
29321
  function safeJsonObjectFromFile(filePath) {
29249
29322
  try {
@@ -29258,7 +29331,7 @@ function safeDirectorySummary(pathValue) {
29258
29331
  return { configured: false, available: false, entryCount: 0 };
29259
29332
  }
29260
29333
  try {
29261
- const stat = statSync9(pathValue);
29334
+ const stat = statSync10(pathValue);
29262
29335
  if (!stat.isDirectory()) {
29263
29336
  return { configured: true, available: false, entryCount: 0, reason: "not_directory" };
29264
29337
  }
@@ -29292,7 +29365,7 @@ function safeSkillRootSummary(kind, source, pathValue) {
29292
29365
  if (name.startsWith(".")) continue;
29293
29366
  const skillDir = join16(pathValue, name);
29294
29367
  try {
29295
- if (!statSync9(skillDir).isDirectory()) continue;
29368
+ if (!statSync10(skillDir).isDirectory()) continue;
29296
29369
  if (!existsSync15(join16(skillDir, "SKILL.md"))) continue;
29297
29370
  skillCount += 1;
29298
29371
  if (skillCount >= MAX_PI_CAPABILITY_SOURCE_ENTRIES) {
@@ -29321,7 +29394,7 @@ function safeJsonConfigSummary(source, pathValue, counter) {
29321
29394
  return { source, configured: false, available: false, parseable: false };
29322
29395
  }
29323
29396
  try {
29324
- const stat = statSync9(pathValue);
29397
+ const stat = statSync10(pathValue);
29325
29398
  if (!stat.isFile()) {
29326
29399
  return { source, configured: true, available: false, parseable: false, reason: "not_file" };
29327
29400
  }
@@ -29481,7 +29554,7 @@ function sourceAcquisitionPackageMetadata(packageName, location = "pi-config") {
29481
29554
  const packageBase = location === "runtime" ? readString(process.env.PI_RUNTIME_ROOT) : readString(process.env.PI_CODING_AGENT_DIR ?? process.env.PI_AGENT_HOME);
29482
29555
  if (!packageBase) return null;
29483
29556
  const packagePath = join16(
29484
- resolve13(expandHomePath(packageBase)),
29557
+ resolve14(expandHomePath(packageBase)),
29485
29558
  ...location === "runtime" ? [] : ["npm"],
29486
29559
  "node_modules",
29487
29560
  ...packageName.split("/"),
@@ -29497,7 +29570,7 @@ function sourceAcquisitionBrowserExecutableReady() {
29497
29570
  const executable = readString(process.env.AMASTER_BROWSER_EXECUTABLE_PATH);
29498
29571
  if (!executable || !isAbsolute9(executable)) return false;
29499
29572
  try {
29500
- const stat = statSync9(executable);
29573
+ const stat = statSync10(executable);
29501
29574
  return stat.isFile() && (stat.mode & 73) !== 0;
29502
29575
  } catch {
29503
29576
  return false;
@@ -29664,7 +29737,7 @@ function browserSessionRuntimeReadiness(config) {
29664
29737
  }
29665
29738
  var browserSessionBrokers = /* @__PURE__ */ new Map();
29666
29739
  function browserSessionBrokerFor(config) {
29667
- const key = resolve13(config.browserSessionStateRoot);
29740
+ const key = resolve14(config.browserSessionStateRoot);
29668
29741
  let broker = browserSessionBrokers.get(key);
29669
29742
  if (!broker) {
29670
29743
  const { chromium } = daemonRequire("playwright-core");
@@ -29679,7 +29752,7 @@ function browserSessionBrokerFor(config) {
29679
29752
  }
29680
29753
  function browserSessionRuntimeStatus(config) {
29681
29754
  const readiness = browserSessionRuntimeReadiness(config);
29682
- const broker = browserSessionBrokers.get(resolve13(config.browserSessionStateRoot));
29755
+ const broker = browserSessionBrokers.get(resolve14(config.browserSessionStateRoot));
29683
29756
  return broker ? { ...readiness, ...broker.status() } : readiness;
29684
29757
  }
29685
29758
  function runtimeAdvertisedCapabilities(config, sourceAcquisition, browserSessionBroker) {
@@ -29687,6 +29760,8 @@ function runtimeAdvertisedCapabilities(config, sourceAcquisition, browserSession
29687
29760
  legacyConfiguredCapabilities: config.legacyConfiguredCapabilities,
29688
29761
  sourceAcquisition,
29689
29762
  browserSessionBroker,
29763
+ templateCatalog: config.templateCatalog,
29764
+ runtimeTemplatesRoot: config.runtimeTemplatesRoot,
29690
29765
  runnerKind: config.runnerKind,
29691
29766
  executors: config.executors
29692
29767
  });
@@ -29920,7 +29995,7 @@ ${authBlock} -H 'content-type: application/json' \\
29920
29995
  # Control-plane side: create a command for daemon poll.
29921
29996
  COMMAND_ID="$(curl -fsS -X POST "$BASE_URL/api/amaster/runtime-connectors/$CONNECTOR_ID/commands" \\
29922
29997
  ${authBlock} -H 'content-type: application/json' \\
29923
- --data-binary '{"commandType":"wakeup","requiredCapabilities":["run_wakeup","context_envelope_v1","managed_project_instructions_v1","final_model_context_attestation_v1","runtime_actions_v2"],"payload":{"smoke":true,"executorKind":"${smokeExecutorKind}"}}' | jq -r '.commandId')"
29998
+ --data-binary '{"commandType":"wakeup","requiredCapabilities":["run_wakeup","context_envelope_v1","managed_project_instructions_v1","artifact_template_catalog_v1","final_model_context_attestation_v1","runtime_actions_v2"],"payload":{"smoke":true,"executorKind":"${smokeExecutorKind}"}}' | jq -r '.commandId')"
29924
29999
  echo "created command: $COMMAND_ID"
29925
30000
 
29926
30001
  # Daemon side: poll, ack, and complete the command.
@@ -30387,8 +30462,8 @@ async function sourceAcquisitionRuntimeProfile(config, command) {
30387
30462
  throw new Error("source_acquisition_profile_invalid");
30388
30463
  }
30389
30464
  const profileName2 = createHash16("sha256").update(`${companyId}\0${bindingId}\0${localOpaqueRef}`).digest("hex");
30390
- const stateRoot = resolve13(config.browserSessionStateRoot);
30391
- const userDataDir = resolve13(stateRoot, profileName2);
30465
+ const stateRoot = resolve14(config.browserSessionStateRoot);
30466
+ const userDataDir = resolve14(stateRoot, profileName2);
30392
30467
  if (!pathWithin3(userDataDir, stateRoot)) throw new Error("source_acquisition_browser_profile_invalid");
30393
30468
  const markerPath = join16(userDataDir, ".amaster-browser-session.json");
30394
30469
  if (!existsSync15(userDataDir) || lstatSync9(userDataDir).isSymbolicLink() || !lstatSync9(userDataDir).isDirectory() || !existsSync15(markerPath) || lstatSync9(markerPath).isSymbolicLink()) throw new Error("source_acquisition_browser_profile_invalid");
@@ -30454,7 +30529,7 @@ function safeAgentInstructionMaterializationTarget(workspace, filePath) {
30454
30529
  const segments = normalized.split("/").filter(Boolean);
30455
30530
  if (segments.length === 0 || segments.some((segment) => segment === "." || segment === "..")) return null;
30456
30531
  const relativePath = segments.join("/");
30457
- const targetPath = resolve13(workspace.cwd, relativePath);
30532
+ const targetPath = resolve14(workspace.cwd, relativePath);
30458
30533
  if (!pathWithin3(targetPath, workspace.cwd)) return null;
30459
30534
  return { relativePath, targetPath };
30460
30535
  }
@@ -30568,7 +30643,7 @@ async function materializeEffectiveAgentInstructions(config, command, workspace,
30568
30643
  }
30569
30644
  const readBackFiles = Object.fromEntries(materialized.map((entry) => [
30570
30645
  entry.path,
30571
- readFileSync17(resolve13(workspace.cwd, entry.path), "utf8")
30646
+ readFileSync17(resolve14(workspace.cwd, entry.path), "utf8")
30572
30647
  ]));
30573
30648
  if (stableInstructionFilesHash(readBackFiles) !== readString(instructionContract.contentHash)) {
30574
30649
  throw new Error("context_envelope_materialized_hash_mismatch");
@@ -30784,7 +30859,7 @@ function attachPiFinalContextAttestor(profile, input) {
30784
30859
  const receiptPath = join16(profile.profileRoot, "tmp", "final-model-context-receipt.json");
30785
30860
  const contract = {
30786
30861
  receiptPath,
30787
- projectInstructionPath: resolve13(input.cwd, "AGENTS.md"),
30862
+ projectInstructionPath: resolve14(input.cwd, "AGENTS.md"),
30788
30863
  projectInstructionSha256: projectInstruction.sha256,
30789
30864
  provider: input.modelContextBudget.provider,
30790
30865
  model: input.modelContextBudget.model,
@@ -30831,6 +30906,7 @@ function buildExecutorEnv(config, command, workspace) {
30831
30906
  AMASTER_RUNTIME_WORKSPACE: cwd,
30832
30907
  AMASTER_RUNTIME_EXECUTION_WORKDIR: cwd,
30833
30908
  AMASTER_RUNTIME_SOURCE_WORKSPACE: workspaceContext.sourceWorkspacePath ?? cwd,
30909
+ AMASTER_RUNTIME_TEMPLATES_ROOT: config.runtimeTemplatesRoot,
30834
30910
  ...workspaceContext.executorHome ? { AMASTER_RUNTIME_EXECUTOR_HOME: workspaceContext.executorHome } : {},
30835
30911
  ...commandUsesPiExecutor(command) ? { PI_TELEMETRY_TASK_RUN_ID: runId } : {},
30836
30912
  PAPERCLIP_RUN_ID: readString(runtimeAuth.runId) ?? runId,
@@ -30917,7 +30993,7 @@ function resolveNativeSessionRequest(command, workspace) {
30917
30993
  try {
30918
30994
  cwdMatched = realpathSync7(requestedCwd) === realpathSync7(sourceWorkspacePath);
30919
30995
  } catch {
30920
- cwdMatched = resolve13(requestedCwd) === resolve13(sourceWorkspacePath);
30996
+ cwdMatched = resolve14(requestedCwd) === resolve14(sourceWorkspacePath);
30921
30997
  }
30922
30998
  }
30923
30999
  const used = Boolean(enabled && requested && sessionId && requestedCwd && cwdMatched);
@@ -31523,7 +31599,7 @@ function realOrResolvedPath(value) {
31523
31599
  try {
31524
31600
  return realpathSync7(value);
31525
31601
  } catch {
31526
- return resolve13(value);
31602
+ return resolve14(value);
31527
31603
  }
31528
31604
  }
31529
31605
  var LSOF_COMMAND = process.platform === "darwin" && existsSync15("/usr/sbin/lsof") ? "/usr/sbin/lsof" : "lsof";
@@ -33419,7 +33495,7 @@ async function completeCommand(config, command, status, result3, error) {
33419
33495
  }
33420
33496
  function resultOutboxDir(config) {
33421
33497
  const explicit = readString(process.env.AMASTER_RESULT_OUTBOX_DIR);
33422
- if (explicit) return resolve13(expandHomePath(explicit));
33498
+ if (explicit) return resolve14(expandHomePath(explicit));
33423
33499
  return join16(dirname11(stateFilePath(process.env)), "result-outbox");
33424
33500
  }
33425
33501
  function resultOutboxInvalidDir(config) {
@@ -33934,14 +34010,14 @@ async function materializeIssueCheckpoint(config, command, workspace) {
33934
34010
  const file = asRecord(rawFile);
33935
34011
  const relativePath = safeCheckpointRelativePath(readString(file.path));
33936
34012
  if (!relativePath) throw new Error("issue checkpoint manifest contains an invalid file path");
33937
- const sourceCandidate = resolve13(filesRoot, relativePath);
33938
- const target = resolve13(workspaceRoot, relativePath);
34013
+ const sourceCandidate = resolve14(filesRoot, relativePath);
34014
+ const target = resolve14(workspaceRoot, relativePath);
33939
34015
  if (!pathWithin3(sourceCandidate, filesRoot) || !pathWithin3(target, workspaceRoot)) {
33940
34016
  throw new Error(`issue checkpoint path escapes its workspace: ${relativePath}`);
33941
34017
  }
33942
34018
  if (!existsSync15(sourceCandidate)) throw new Error(`issue checkpoint file is missing: ${relativePath}`);
33943
34019
  const source = realpathSync7(sourceCandidate);
33944
- if (!pathWithin3(source, filesRoot) || !statSync9(source).isFile()) {
34020
+ if (!pathWithin3(source, filesRoot) || !statSync10(source).isFile()) {
33945
34021
  throw new Error(`issue checkpoint source escapes its storage root: ${relativePath}`);
33946
34022
  }
33947
34023
  const expectedSha256 = readString(file.sha256);
@@ -33949,7 +34025,7 @@ async function materializeIssueCheckpoint(config, command, workspace) {
33949
34025
  if (!expectedSha256 || expectedByteSize === null || expectedByteSize <= 0) {
33950
34026
  throw new Error(`issue checkpoint evidence is incomplete: ${relativePath}`);
33951
34027
  }
33952
- if (hashFileSha256(source) !== expectedSha256 || statSync9(source).size !== expectedByteSize) {
34028
+ if (hashFileSha256(source) !== expectedSha256 || statSync10(source).size !== expectedByteSize) {
33953
34029
  throw new Error(`issue checkpoint integrity mismatch: ${relativePath}`);
33954
34030
  }
33955
34031
  totalBytes += expectedByteSize;
@@ -34002,14 +34078,14 @@ async function saveIssueCheckpoint(config, command, workspace, candidates) {
34002
34078
  for (const candidate of candidates.slice(0, 20)) {
34003
34079
  const relativePath = safeCheckpointRelativePath(candidate.rawPath);
34004
34080
  const source = readString(candidate.filePath);
34005
- if (!relativePath || !source || !existsSync15(source) || !statSync9(source).isFile()) continue;
34081
+ if (!relativePath || !source || !existsSync15(source) || !statSync10(source).isFile()) continue;
34006
34082
  const ownedSource = realpathSync7(source);
34007
34083
  if (!pathWithin3(ownedSource, workspaceRoot)) {
34008
34084
  throw new Error(`issue checkpoint source escapes its execution workspace: ${relativePath}`);
34009
34085
  }
34010
- const byteSize = statSync9(ownedSource).size;
34086
+ const byteSize = statSync10(ownedSource).size;
34011
34087
  if (byteSize <= 0 || totalBytes + byteSize > MAX_CHECKPOINT_BYTES) continue;
34012
- const target = resolve13(filesDir, relativePath);
34088
+ const target = resolve14(filesDir, relativePath);
34013
34089
  if (!pathWithin3(target, filesDir)) continue;
34014
34090
  mkdirSync10(dirname11(target), { recursive: true });
34015
34091
  copyFileSync2(ownedSource, target);
@@ -34268,7 +34344,7 @@ async function executeRunCommand(config, command) {
34268
34344
  const sharedPiHome = readString(process.env.PI_CODING_AGENT_DIR) ?? readString(process.env.PI_AGENT_HOME) ?? null;
34269
34345
  let agentDir = managedMcpProfile ? readString(managedMcpProfile.env.PI_CODING_AGENT_DIR) ?? readString(managedMcpProfile.env.PI_AGENT_HOME) ?? null : desktopDelegatedRunnerEnabled(config) ? readString(executorEnv.PI_AGENT_HOME) ?? readString(executorEnv.PI_CODING_AGENT_DIR) ?? null : readString(executorEnv.PI_CODING_AGENT_DIR) ?? readString(executorEnv.PI_AGENT_HOME) ?? null;
34270
34346
  piAgentDirForContextBudget = agentDir;
34271
- if (agentDir && sharedPiHome && resolve13(agentDir) === resolve13(sharedPiHome)) {
34347
+ if (agentDir && sharedPiHome && resolve14(agentDir) === resolve14(sharedPiHome)) {
34272
34348
  agentDir = null;
34273
34349
  }
34274
34350
  try {
@@ -34655,7 +34731,7 @@ async function executeRunCommand(config, command) {
34655
34731
  workspace,
34656
34732
  workspaceStatus.artifacts.map((artifact) => ({
34657
34733
  rawPath: artifact.relativePath,
34658
- filePath: resolve13(cwd, artifact.relativePath)
34734
+ filePath: resolve14(cwd, artifact.relativePath)
34659
34735
  }))
34660
34736
  ) : null;
34661
34737
  nativeSessionRollout = {
@@ -35110,20 +35186,25 @@ function reconcileStaleManagedMcpProfiles(config) {
35110
35186
  }
35111
35187
  }
35112
35188
  async function runOnce(config) {
35113
- const templates = materializeRuntimePresetTemplates(process.env);
35189
+ const templates = materializeRuntimePresetTemplates({
35190
+ targetDir: config.runtimeTemplatesRoot,
35191
+ executorIdentity: config.runnerKind === "cloud_managed" && config.piExecutorUid > 0 ? { uid: config.piExecutorUid, gid: config.piExecutorGid } : null
35192
+ });
35114
35193
  if (templates.status === "ready") {
35115
35194
  process.stderr.write(`MirrorX preset templates ready: files=${templates.fileCount} target=${templates.targetDir}
35116
35195
  `);
35117
35196
  }
35197
+ config = { ...config, templateCatalog: templates };
35118
35198
  reconcileStaleManagedMcpProfiles(config);
35119
35199
  config = await ensureRegistered(config);
35200
+ config = { ...config, templateCatalog: templates };
35120
35201
  try {
35121
35202
  await heartbeat(config, { logMode: "compact" });
35122
35203
  } catch (err) {
35123
35204
  if (!hasConnectorAuth(config) && isConnectorAuthFailure(err)) {
35124
35205
  process.stderr.write("AMaster daemon heartbeat was rejected without connector auth; re-registering once.\n");
35125
35206
  await register(config, { quiet: true });
35126
- config = buildConfig(process.env, {});
35207
+ config = { ...buildConfig(process.env, {}), templateCatalog: templates };
35127
35208
  await heartbeat(config, { logMode: "compact" });
35128
35209
  } else {
35129
35210
  throw err;
@@ -35240,21 +35321,26 @@ function statusSummary(config) {
35240
35321
  `);
35241
35322
  }
35242
35323
  async function runLoop(config) {
35243
- const templates = materializeRuntimePresetTemplates(process.env);
35324
+ const templates = materializeRuntimePresetTemplates({
35325
+ targetDir: config.runtimeTemplatesRoot,
35326
+ executorIdentity: config.runnerKind === "cloud_managed" && config.piExecutorUid > 0 ? { uid: config.piExecutorUid, gid: config.piExecutorGid } : null
35327
+ });
35244
35328
  if (templates.status === "ready") {
35245
35329
  process.stderr.write(`MirrorX preset templates ready: files=${templates.fileCount} target=${templates.targetDir}
35246
35330
  `);
35247
35331
  }
35332
+ config = { ...config, templateCatalog: templates };
35248
35333
  process.stderr.write(
35249
35334
  `AMaster daemon runtime safety controls resolved: pi_guard_mode=${config.piToolArgumentGuard.mode}
35250
35335
  `
35251
35336
  );
35252
35337
  reconcileStaleManagedMcpProfiles(config);
35253
35338
  config = await ensureRegistered(config);
35339
+ config = { ...config, templateCatalog: templates };
35254
35340
  let startupOrphanCheckPending = true;
35255
35341
  for (; ; ) {
35256
35342
  try {
35257
- config = buildConfig(process.env, {});
35343
+ config = { ...buildConfig(process.env, {}), templateCatalog: templates };
35258
35344
  maybeRunOrphanReaper(config, { force: startupOrphanCheckPending });
35259
35345
  await dispatchAvailableCommands(config, startupOrphanCheckPending ? { orphanCheck: "startup" } : {});
35260
35346
  startupOrphanCheckPending = false;
@@ -35264,7 +35350,7 @@ async function runLoop(config) {
35264
35350
  ${message}
35265
35351
  `);
35266
35352
  }
35267
- await new Promise((resolve14) => setTimeout(resolve14, config.pollIntervalSeconds * 1e3));
35353
+ await new Promise((resolve15) => setTimeout(resolve15, config.pollIntervalSeconds * 1e3));
35268
35354
  }
35269
35355
  }
35270
35356
  function help() {
@@ -35291,7 +35377,7 @@ Key env:
35291
35377
  AMASTER_NETWORK_DOMAINS, AMASTER_CONNECTOR_ID, AMASTER_DAEMON_STATE_FILE,
35292
35378
  AMASTER_MAX_CONCURRENT_COMMANDS, AMASTER_EXECUTOR_MAX_RSS_MB (default 0, disabled),
35293
35379
  AMASTER_RUNTIME_ORPHAN_REAPER_INTERVAL_SECONDS (default 300, set 0 to disable),
35294
- AMASTER_RUNTIME_TEMPLATES_ROOT (optional; defaults to /data/templates in pi-cli-runtime)
35380
+ AMASTER_RUNTIME_TEMPLATES_ROOT (optional; defaults to /data/templates for managed Pi, otherwise <runtime-home>/templates)
35295
35381
  `);
35296
35382
  }
35297
35383
  async function main() {
@@ -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.136";
10
+ const CONNECTOR_VERSION = "0.1.1-beta.138";
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.136",
3
+ "version": "0.1.1-beta.138",
4
4
  "description": "MirrorX runtime connector CLI and daemon",
5
5
  "license": "MIT",
6
6
  "type": "module",