@kontextmind/kxm 0.7.99 → 0.7.101

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.
@@ -2986,7 +2986,7 @@ var require_compile = __commonJS({
2986
2986
  const schOrFunc = root.refs[ref];
2987
2987
  if (schOrFunc)
2988
2988
  return schOrFunc;
2989
- let _sch = resolve11.call(this, root, ref);
2989
+ let _sch = resolve12.call(this, root, ref);
2990
2990
  if (_sch === void 0) {
2991
2991
  const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
2992
2992
  const { schemaId } = this.opts;
@@ -3013,7 +3013,7 @@ var require_compile = __commonJS({
3013
3013
  function sameSchemaEnv(s1, s2) {
3014
3014
  return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
3015
3015
  }
3016
- function resolve11(root, ref) {
3016
+ function resolve12(root, ref) {
3017
3017
  let sch;
3018
3018
  while (typeof (sch = this.refs[ref]) == "string")
3019
3019
  ref = sch;
@@ -3838,7 +3838,7 @@ var require_fast_uri = __commonJS({
3838
3838
  }
3839
3839
  return uri;
3840
3840
  }
3841
- function resolve11(baseURI, relativeURI, options) {
3841
+ function resolve12(baseURI, relativeURI, options) {
3842
3842
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
3843
3843
  const {
3844
3844
  parsed: baseParsed,
@@ -4200,7 +4200,7 @@ var require_fast_uri = __commonJS({
4200
4200
  var fastUri = {
4201
4201
  SCHEMES,
4202
4202
  normalize,
4203
- resolve: resolve11,
4203
+ resolve: resolve12,
4204
4204
  resolveComponent,
4205
4205
  equal,
4206
4206
  serialize,
@@ -14779,7 +14779,7 @@ var require_dist = __commonJS({
14779
14779
 
14780
14780
  // plugins/kxm/src/runtime-service.ts
14781
14781
  import { createHash as createHash7 } from "node:crypto";
14782
- import { existsSync as existsSync6, readdirSync as readdirSync3, readFileSync as readFileSync4 } from "node:fs";
14782
+ import { existsSync as existsSync7, readdirSync as readdirSync3, readFileSync as readFileSync4 } from "node:fs";
14783
14783
  import { join as join6 } from "node:path";
14784
14784
 
14785
14785
  // plugins/kxm/src/project-config.ts
@@ -15194,7 +15194,7 @@ function defaultSpawn(command, args, options) {
15194
15194
  if (options.signal?.aborted) {
15195
15195
  return Promise.resolve({ stdout: "", stderr: "", code: null, started: false, observedChildExit: false, error: new Error("process_aborted") });
15196
15196
  }
15197
- return new Promise((resolve11) => {
15197
+ return new Promise((resolve12) => {
15198
15198
  const stdout = [];
15199
15199
  const stderr = [];
15200
15200
  let outputBytes = 0;
@@ -15225,7 +15225,7 @@ function defaultSpawn(command, args, options) {
15225
15225
  const started = Boolean(child?.pid);
15226
15226
  if (started && !observedChildExit) error ??= new Error("process_exit_unobserved");
15227
15227
  const unverifiedDescendants = stopping || started && !observedChildExit;
15228
- resolve11({
15228
+ resolve12({
15229
15229
  stdout: Buffer.concat(stdout).toString("utf8"),
15230
15230
  stderr: Buffer.concat(stderr).toString("utf8"),
15231
15231
  code,
@@ -16781,10 +16781,13 @@ function readResource(registry, root, file, logicalPath, kind, id, containmentRo
16781
16781
  parent = dirname2(parent);
16782
16782
  }
16783
16783
  if (!stat.isFile()) fail2("path", "resource_not_file", label, "configuration resource must be a regular file");
16784
- const value = parseRestrictedYaml2(readFileSync(file), label);
16784
+ return { kind, ...id === void 0 ? {} : { id }, file, logicalPath, value: resourceValue(registry, readFileSync(file), label, kind) };
16785
+ }
16786
+ function resourceValue(registry, input, label, kind) {
16787
+ const value = parseRestrictedYaml2(input, label);
16785
16788
  const issues = registry.validate(kind, value, label);
16786
16789
  if (issues.length > 0) throw new KxmConfigError(issues);
16787
- return { kind, ...id === void 0 ? {} : { id }, file, logicalPath, value };
16790
+ return value;
16788
16791
  }
16789
16792
  function readTemplateProvenance(registry, root) {
16790
16793
  const file = join2(root, ".kxm", "template-provenance.yaml");
@@ -16833,7 +16836,7 @@ function readTemplateProvenance(registry, root) {
16833
16836
  }
16834
16837
  return value;
16835
16838
  }
16836
- function listNamedResources(registry, root, directory, logicalDirectory, kind) {
16839
+ function listNamedResources(registry, root, directory, logicalDirectory, kind, replacedId) {
16837
16840
  const resources = /* @__PURE__ */ new Map();
16838
16841
  if (!existsSync3(directory)) return resources;
16839
16842
  const stat = lstatSync(directory);
@@ -16854,6 +16857,7 @@ function listNamedResources(registry, root, directory, logicalDirectory, kind) {
16854
16857
  }
16855
16858
  const id = basename(entry.name, ".yaml");
16856
16859
  if (kind === "model" && id === "inventory") continue;
16860
+ if (id === replacedId) continue;
16857
16861
  if (!resourceIdentifier(id)) {
16858
16862
  issues.push(issue2("path", "resource_id_invalid", displayPath(root, join2(directory, entry.name)), `filename-derived identity ${id} is invalid or platform-reserved`));
16859
16863
  continue;
@@ -17454,6 +17458,9 @@ function assertNoRegisteredGates(options) {
17454
17458
  }
17455
17459
  }
17456
17460
  function loadKxmProject(projectRoot, options = {}) {
17461
+ return loadProjectBundle(projectRoot, options);
17462
+ }
17463
+ function loadProjectBundle(projectRoot, options, workflowCandidate) {
17457
17464
  assertNoRegisteredGates(options);
17458
17465
  const root = resolve(projectRoot);
17459
17466
  const legacyPresent = legacyConfigFilesAt(root);
@@ -17487,7 +17494,15 @@ function loadKxmProject(projectRoot, options = {}) {
17487
17494
  if (earlyIssues.length > 0) throw new KxmConfigError(earlyIssues);
17488
17495
  const agents = listNamedResources(registry, root, join2(root, ".kxm", "agents"), ".kxm/agents", "agent");
17489
17496
  const models = listNamedResources(registry, root, join2(root, ".kxm", "models"), ".kxm/models", "model");
17490
- const workflows = listNamedResources(registry, root, join2(root, ".kxm", "workflows"), ".kxm/workflows", "workflow");
17497
+ const workflows = listNamedResources(registry, root, join2(root, ".kxm", "workflows"), ".kxm/workflows", "workflow", workflowCandidate?.id);
17498
+ if (workflowCandidate) {
17499
+ const { id, document } = workflowCandidate;
17500
+ const logicalPath = `.kxm/workflows/${id}.yaml`;
17501
+ if (!resourceIdentifier(id)) fail2("path", "resource_id_invalid", logicalPath, `filename-derived identity ${id} is invalid or platform-reserved`);
17502
+ const collision = [...workflows.keys()].find((candidate) => candidate.toLocaleLowerCase("en-US") === id.toLocaleLowerCase("en-US"));
17503
+ if (collision) fail2("path", "resource_id_collision", logicalPath, `${id} case-folds to existing ${collision}`);
17504
+ workflows.set(id, { kind: "workflow", id, file: join2(root, logicalPath), logicalPath, value: resourceValue(registry, document, logicalPath, "workflow") });
17505
+ }
17491
17506
  const gatePath = join2(root, ".kxm", "gates.yaml");
17492
17507
  const gateRegistry = existsSync3(gatePath) ? readResource(registry, root, gatePath, ".kxm/gates.yaml", "gate-registry") : void 0;
17493
17508
  const environments = [];
@@ -17646,11 +17661,14 @@ function legacyConfigFilesAt(root) {
17646
17661
 
17647
17662
  // plugins/kxm/src/runtime-store.ts
17648
17663
  import { createHash as createHash5, randomUUID } from "node:crypto";
17649
- import { existsSync as existsSync5, lstatSync as lstatSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync2, writeFileSync as writeFileSync2 } from "node:fs";
17650
- import { dirname as dirname5, join as join5, resolve as resolve4 } from "node:path";
17664
+ import { existsSync as existsSync6, lstatSync as lstatSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, realpathSync as realpathSync2, writeFileSync as writeFileSync2 } from "node:fs";
17665
+ import { dirname as dirname5, join as join5, resolve as resolve5 } from "node:path";
17651
17666
 
17652
17667
  // plugins/kxm/src/sqlite.ts
17668
+ import { existsSync as existsSync4 } from "node:fs";
17653
17669
  import { createRequire } from "node:module";
17670
+ import { resolve as resolve2 } from "node:path";
17671
+ import { pathToFileURL } from "node:url";
17654
17672
  var requireFromHere = createRequire(import.meta.url);
17655
17673
  function loadNative() {
17656
17674
  try {
@@ -17687,10 +17705,16 @@ var DatabaseSync = class {
17687
17705
  this.inner.close();
17688
17706
  }
17689
17707
  };
17708
+ function openReadOnlyDatabase(path) {
17709
+ if (existsSync4(`${path}-wal`)) return new DatabaseSync(path, { readOnly: true });
17710
+ const uri = pathToFileURL(resolve2(path));
17711
+ uri.searchParams.set("immutable", "1");
17712
+ return new DatabaseSync(uri.href, { readOnly: true });
17713
+ }
17690
17714
 
17691
17715
  // plugins/kxm/src/bindings.ts
17692
17716
  import { homedir } from "node:os";
17693
- import { dirname as dirname3, isAbsolute as isAbsolute2, join as join3, parse, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
17717
+ import { dirname as dirname3, isAbsolute as isAbsolute2, join as join3, parse, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
17694
17718
  var MAX_BINDING_RECORD_BYTES = 256 * 1024;
17695
17719
  var BINDING_LABEL = "Runtime-local repository bindings";
17696
17720
  function bindingIssue(phase, code, message) {
@@ -17706,17 +17730,17 @@ function kxmUserStateRoot(options = {}) {
17706
17730
  const explicit = options.stateRoot ?? env.KXM_STATE_HOME?.trim();
17707
17731
  if (explicit) {
17708
17732
  if (!isAbsolute2(explicit)) bindingError("path", "local_state_root_not_absolute", "KXM_STATE_HOME must be an absolute host-local path");
17709
- return resolve2(explicit);
17733
+ return resolve3(explicit);
17710
17734
  }
17711
17735
  if (platform === "win32") {
17712
17736
  const localAppData = env.LOCALAPPDATA?.trim();
17713
17737
  const base2 = localAppData && isAbsolute2(localAppData) ? localAppData : join3(home, "AppData", "Local");
17714
- return resolve2(base2, "KXM");
17738
+ return resolve3(base2, "KXM");
17715
17739
  }
17716
- if (platform === "darwin") return resolve2(home, "Library", "Application Support", "KXM");
17740
+ if (platform === "darwin") return resolve3(home, "Library", "Application Support", "KXM");
17717
17741
  const xdgState = env.XDG_STATE_HOME?.trim();
17718
17742
  const base = xdgState && isAbsolute2(xdgState) ? xdgState : join3(home, ".local", "state");
17719
- return resolve2(base, "kxm");
17743
+ return resolve3(base, "kxm");
17720
17744
  }
17721
17745
 
17722
17746
  // plugins/kxm/src/sync-transform.ts
@@ -18055,7 +18079,7 @@ import { createHash as createHash4, randomBytes } from "node:crypto";
18055
18079
  import {
18056
18080
  chmodSync,
18057
18081
  copyFileSync,
18058
- existsSync as existsSync4,
18082
+ existsSync as existsSync5,
18059
18083
  lstatSync as lstatSync2,
18060
18084
  mkdirSync,
18061
18085
  readdirSync as readdirSync2,
@@ -18063,14 +18087,14 @@ import {
18063
18087
  unlinkSync,
18064
18088
  writeFileSync
18065
18089
  } from "node:fs";
18066
- import { basename as basename2, dirname as dirname4, join as join4, resolve as resolve3 } from "node:path";
18090
+ import { basename as basename2, dirname as dirname4, join as join4, resolve as resolve4 } from "node:path";
18067
18091
  function databaseError(code, file, message) {
18068
18092
  const issue3 = { phase: "semantic", code, file, message };
18069
18093
  return new KxmConfigError([issue3]);
18070
18094
  }
18071
18095
  function checkedParent(path, description) {
18072
18096
  const parent = dirname4(path);
18073
- if (!existsSync4(parent)) mkdirSync(parent, { recursive: true, mode: 448 });
18097
+ if (!existsSync5(parent)) mkdirSync(parent, { recursive: true, mode: 448 });
18074
18098
  const stat = lstatSync2(parent, { throwIfNoEntry: false });
18075
18099
  if (!stat || stat.isSymbolicLink() || !stat.isDirectory()) {
18076
18100
  throw databaseError("runtime_path_invalid", description, `${description} parent must be a regular directory, not a link`);
@@ -18292,14 +18316,14 @@ function fileSha256(filePath) {
18292
18316
  return `sha256:${createHash4("sha256").update(bytes).digest("hex")}`;
18293
18317
  }
18294
18318
  function backupDatabaseFile(sourcePath, targetPath, storeId) {
18295
- const resolvedSource = resolve3(sourcePath);
18296
- const resolvedTarget = resolve3(targetPath);
18319
+ const resolvedSource = resolve4(sourcePath);
18320
+ const resolvedTarget = resolve4(targetPath);
18297
18321
  const sourceStat = lstatSync2(resolvedSource, { throwIfNoEntry: false });
18298
18322
  if (!sourceStat || !sourceStat.isFile() || sourceStat.isSymbolicLink()) {
18299
18323
  throw databaseError("runtime_path_invalid", resolvedSource, `source database ${resolvedSource} must be a regular file, not a link or directory`);
18300
18324
  }
18301
18325
  checkedParent(resolvedTarget, "backup target");
18302
- if (existsSync4(resolvedTarget)) {
18326
+ if (existsSync5(resolvedTarget)) {
18303
18327
  unlinkSync(resolvedTarget);
18304
18328
  }
18305
18329
  const sourceDb = new DatabaseSync(resolvedSource);
@@ -18343,8 +18367,8 @@ function backupDatabaseFile(sourcePath, targetPath, storeId) {
18343
18367
  };
18344
18368
  }
18345
18369
  function restoreDatabaseFile(backupPath, targetPath, storeId, expectedSchemaVersion, maxSupportedVersion) {
18346
- const resolvedBackup = resolve3(backupPath);
18347
- const resolvedTarget = resolve3(targetPath);
18370
+ const resolvedBackup = resolve4(backupPath);
18371
+ const resolvedTarget = resolve4(targetPath);
18348
18372
  const backupStat = lstatSync2(resolvedBackup, { throwIfNoEntry: false });
18349
18373
  if (!backupStat || !backupStat.isFile() || backupStat.isSymbolicLink()) {
18350
18374
  throw databaseError("runtime_path_invalid", resolvedBackup, `backup database ${resolvedBackup} must be a regular file, not a link or directory`);
@@ -18377,7 +18401,7 @@ function restoreDatabaseFile(backupPath, targetPath, storeId, expectedSchemaVers
18377
18401
  }
18378
18402
  checkedParent(resolvedTarget, "restore target");
18379
18403
  for (const file of [resolvedTarget, `${resolvedTarget}-wal`, `${resolvedTarget}-shm`]) {
18380
- if (existsSync4(file)) {
18404
+ if (existsSync5(file)) {
18381
18405
  try {
18382
18406
  unlinkSync(file);
18383
18407
  } catch {
@@ -18430,12 +18454,12 @@ function discoverUserRuntime(env, stores, files) {
18430
18454
  }
18431
18455
  const runtimeDir = join4(stateRoot, "runtime");
18432
18456
  const registryPath = join4(runtimeDir, "registry.db");
18433
- if (existsSync4(registryPath)) {
18457
+ if (existsSync5(registryPath)) {
18434
18458
  const storeId = stores.some((store) => store.storeId === "registry") ? "runtime-registry" : "registry";
18435
18459
  pushStore(stores, storeId, registryPath);
18436
18460
  }
18437
18461
  const projectsDir = join4(runtimeDir, "projects");
18438
- if (!existsSync4(projectsDir)) return;
18462
+ if (!existsSync5(projectsDir)) return;
18439
18463
  let entries;
18440
18464
  try {
18441
18465
  entries = readdirSync2(projectsDir, { withFileTypes: true });
@@ -18445,13 +18469,13 @@ function discoverUserRuntime(env, stores, files) {
18445
18469
  for (const entry of entries) {
18446
18470
  if (!entry.isDirectory()) continue;
18447
18471
  const dbPath = join4(projectsDir, entry.name, "run-events.db");
18448
- if (!existsSync4(dbPath)) continue;
18472
+ if (!existsSync5(dbPath)) continue;
18449
18473
  const safe = entry.name.replace(/[^a-zA-Z0-9_.-]/g, "_");
18450
18474
  let storeId = `events:${safe}`;
18451
18475
  if (stores.some((store) => store.storeId === storeId)) storeId = `events:runtime:${safe}`;
18452
18476
  pushStore(stores, storeId, dbPath);
18453
18477
  const sidecar = `${dbPath}.run-prompts.json`;
18454
- if (existsSync4(sidecar)) {
18478
+ if (existsSync5(sidecar)) {
18455
18479
  const id = `${storeId}:run-prompts`;
18456
18480
  if (!files.some((file) => file.id === id || file.sourcePath === sidecar)) {
18457
18481
  files.push({ id, sourcePath: sidecar });
@@ -18460,17 +18484,17 @@ function discoverUserRuntime(env, stores, files) {
18460
18484
  }
18461
18485
  }
18462
18486
  function discoverBackupSources(projectRoot, options = {}) {
18463
- const root = resolve3(projectRoot);
18487
+ const root = resolve4(projectRoot);
18464
18488
  const stores = [];
18465
18489
  const files = [];
18466
- const hubPath = options.hubDataPath ? resolve3(options.hubDataPath) : join4(root, ".kxm", "state", "kxm.db");
18467
- if (existsSync4(hubPath)) pushStore(stores, "hub-store", hubPath);
18490
+ const hubPath = options.hubDataPath ? resolve4(options.hubDataPath) : join4(root, ".kxm", "state", "kxm.db");
18491
+ if (existsSync5(hubPath)) pushStore(stores, "hub-store", hubPath);
18468
18492
  const registryPath = join4(root, ".kxm", "runtime", "registry.db");
18469
- if (existsSync4(registryPath)) pushStore(stores, "registry", registryPath);
18493
+ if (existsSync5(registryPath)) pushStore(stores, "registry", registryPath);
18470
18494
  const bindingsPath = join4(root, ".kxm", "runtime", "bindings.db");
18471
- if (existsSync4(bindingsPath)) pushStore(stores, "binding-store", bindingsPath);
18495
+ if (existsSync5(bindingsPath)) pushStore(stores, "binding-store", bindingsPath);
18472
18496
  const eventsDir = join4(root, ".kxm", "runtime", "events");
18473
- if (existsSync4(eventsDir)) {
18497
+ if (existsSync5(eventsDir)) {
18474
18498
  const entries = readdirSync2(eventsDir, { withFileTypes: true });
18475
18499
  for (const entry of entries) {
18476
18500
  if (entry.isFile() && entry.name.endsWith(".db")) {
@@ -18483,13 +18507,13 @@ function discoverBackupSources(projectRoot, options = {}) {
18483
18507
  return { stores, files };
18484
18508
  }
18485
18509
  function backupPlainFile(sourcePath, targetPath, id) {
18486
- const resolvedSource = resolve3(sourcePath);
18510
+ const resolvedSource = resolve4(sourcePath);
18487
18511
  const sourceStat = lstatSync2(resolvedSource, { throwIfNoEntry: false });
18488
18512
  if (!sourceStat || !sourceStat.isFile() || sourceStat.isSymbolicLink()) {
18489
18513
  throw databaseError("runtime_path_invalid", resolvedSource, `backup file ${resolvedSource} must be a regular file, not a link or directory`);
18490
18514
  }
18491
18515
  checkedParent(targetPath, "backup target");
18492
- if (existsSync4(targetPath)) unlinkSync(targetPath);
18516
+ if (existsSync5(targetPath)) unlinkSync(targetPath);
18493
18517
  copyFileSync(resolvedSource, targetPath);
18494
18518
  try {
18495
18519
  chmodSync(targetPath, 384);
@@ -18513,7 +18537,7 @@ function backupFilename(sourcePath, id, used) {
18513
18537
  }
18514
18538
  function restorePlainFile(backupFilePath, targetPath) {
18515
18539
  checkedParent(targetPath, "restore target");
18516
- if (existsSync4(targetPath)) unlinkSync(targetPath);
18540
+ if (existsSync5(targetPath)) unlinkSync(targetPath);
18517
18541
  copyFileSync(backupFilePath, targetPath);
18518
18542
  try {
18519
18543
  chmodSync(targetPath, 384);
@@ -18530,14 +18554,14 @@ function backupDiscoverOptions(options) {
18530
18554
  };
18531
18555
  }
18532
18556
  function planBackup(options = {}) {
18533
- const projectRoot = options.projectRoot ? resolve3(options.projectRoot) : process.cwd();
18557
+ const projectRoot = options.projectRoot ? resolve4(options.projectRoot) : process.cwd();
18534
18558
  const discovered = discoverBackupSources(projectRoot, backupDiscoverOptions(options));
18535
18559
  if (discovered.stores.length === 0) {
18536
18560
  throw databaseError("backup_no_stores", projectRoot, "no existing SQLite stores found to backup");
18537
18561
  }
18538
18562
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
18539
18563
  const timestamp = createdAt.replace(/[:.]/g, "-");
18540
- const outDir = options.outDir ? resolve3(options.outDir) : join4(projectRoot, ".kxm", "backups", `backup-${timestamp}`);
18564
+ const outDir = options.outDir ? resolve4(options.outDir) : join4(projectRoot, ".kxm", "backups", `backup-${timestamp}`);
18541
18565
  const usedFilenames = /* @__PURE__ */ new Set();
18542
18566
  const stores = discovered.stores.map((store) => ({
18543
18567
  storeId: store.storeId,
@@ -18554,7 +18578,7 @@ function planBackup(options = {}) {
18554
18578
  function createBackup(options = {}) {
18555
18579
  const { projectRoot, outDir, createdAt, stores, files } = planBackup(options);
18556
18580
  const backupId = `bk_${randomBytes(8).toString("hex")}`;
18557
- if (!existsSync4(outDir)) {
18581
+ if (!existsSync5(outDir)) {
18558
18582
  mkdirSync(outDir, { recursive: true, mode: 448 });
18559
18583
  }
18560
18584
  const backedUpStores = [];
@@ -18607,7 +18631,7 @@ function createBackup(options = {}) {
18607
18631
  return { manifest, outDir };
18608
18632
  }
18609
18633
  function planRestore(manifestPathOrDir, options = {}) {
18610
- let manifestPath = resolve3(manifestPathOrDir);
18634
+ let manifestPath = resolve4(manifestPathOrDir);
18611
18635
  const stat = lstatSync2(manifestPath, { throwIfNoEntry: false });
18612
18636
  if (!stat) {
18613
18637
  throw databaseError("runtime_path_invalid", manifestPath, `manifest path ${manifestPath} does not exist`);
@@ -18615,7 +18639,7 @@ function planRestore(manifestPathOrDir, options = {}) {
18615
18639
  if (stat.isDirectory()) {
18616
18640
  manifestPath = join4(manifestPath, "manifest.json");
18617
18641
  }
18618
- if (!existsSync4(manifestPath)) {
18642
+ if (!existsSync5(manifestPath)) {
18619
18643
  throw databaseError("runtime_path_invalid", manifestPath, `backup manifest ${manifestPath} not found`);
18620
18644
  }
18621
18645
  const manifestDir = dirname4(manifestPath);
@@ -18635,7 +18659,7 @@ function planRestore(manifestPathOrDir, options = {}) {
18635
18659
  const stores = [];
18636
18660
  for (const store of manifest.stores) {
18637
18661
  const backupFilePath = join4(manifestDir, store.backupFile);
18638
- if (!existsSync4(backupFilePath)) {
18662
+ if (!existsSync5(backupFilePath)) {
18639
18663
  throw databaseError("restore_file_missing", backupFilePath, `backup file ${store.backupFile} missing from ${manifestDir}`);
18640
18664
  }
18641
18665
  const actualSha256 = fileSha256(backupFilePath);
@@ -18657,14 +18681,14 @@ function planRestore(manifestPathOrDir, options = {}) {
18657
18681
  let targetPath = store.sourcePath;
18658
18682
  if (options.projectRoot && manifest.projectRoot && targetPath.startsWith(manifest.projectRoot)) {
18659
18683
  const rel = targetPath.slice(manifest.projectRoot.length).replace(/^[\\/]+/, "");
18660
- targetPath = join4(resolve3(options.projectRoot), rel);
18684
+ targetPath = join4(resolve4(options.projectRoot), rel);
18661
18685
  }
18662
18686
  stores.push({ storeId: store.storeId, backupFilePath, targetPath, schemaVersion: store.schemaVersion, maxSupportedVersion });
18663
18687
  }
18664
18688
  const files = [];
18665
18689
  for (const file of manifest.files ?? []) {
18666
18690
  const backupFilePath = join4(manifestDir, file.backupFile);
18667
- if (!existsSync4(backupFilePath)) {
18691
+ if (!existsSync5(backupFilePath)) {
18668
18692
  throw databaseError("restore_file_missing", backupFilePath, `backup file ${file.backupFile} missing from ${manifestDir}`);
18669
18693
  }
18670
18694
  const actualSha256 = fileSha256(backupFilePath);
@@ -18678,7 +18702,7 @@ function planRestore(manifestPathOrDir, options = {}) {
18678
18702
  let targetPath = file.sourcePath;
18679
18703
  if (options.projectRoot && manifest.projectRoot && targetPath.startsWith(manifest.projectRoot)) {
18680
18704
  const rel = targetPath.slice(manifest.projectRoot.length).replace(/^[\\/]+/, "");
18681
- targetPath = join4(resolve3(options.projectRoot), rel);
18705
+ targetPath = join4(resolve4(options.projectRoot), rel);
18682
18706
  }
18683
18707
  files.push({ id: file.id, backupFilePath, targetPath });
18684
18708
  }
@@ -18705,7 +18729,7 @@ function restoreBackup(manifestPathOrDir, options = {}) {
18705
18729
 
18706
18730
  // plugins/kxm/src/runtime-store.ts
18707
18731
  function kxmRuntimePaths(options = {}) {
18708
- const stateRoot = options.stateRoot ? resolve4(options.stateRoot) : kxmUserStateRoot({ ...options.env ? { env: options.env } : {}, ...options.homeDir ? { homeDir: options.homeDir } : {} });
18732
+ const stateRoot = options.stateRoot ? resolve5(options.stateRoot) : kxmUserStateRoot({ ...options.env ? { env: options.env } : {}, ...options.homeDir ? { homeDir: options.homeDir } : {} });
18709
18733
  const runtimeDir = join5(stateRoot, "runtime");
18710
18734
  return {
18711
18735
  stateRoot,
@@ -18723,9 +18747,9 @@ function runtimeError(code, file, message) {
18723
18747
  function projectRuntimeKey(projectRoot) {
18724
18748
  let canonical;
18725
18749
  try {
18726
- canonical = realpathSync2.native(resolve4(projectRoot));
18750
+ canonical = realpathSync2.native(resolve5(projectRoot));
18727
18751
  } catch {
18728
- canonical = resolve4(projectRoot);
18752
+ canonical = resolve5(projectRoot);
18729
18753
  }
18730
18754
  const folded = process.platform === "win32" ? canonical.toLocaleLowerCase("en-US") : canonical;
18731
18755
  return createHash5("sha256").update(folded, "utf8").digest("hex").slice(0, 24);
@@ -18735,8 +18759,8 @@ function kxmProjectRunEventsPath(projectRoot, env) {
18735
18759
  }
18736
18760
  function projectRuntimeOwnsRun(projectRoot, runId, env) {
18737
18761
  const path = kxmProjectRunEventsPath(projectRoot, env);
18738
- if (!existsSync5(path)) return false;
18739
- const database = new DatabaseSync(path, { readOnly: true });
18762
+ if (!existsSync6(path)) return false;
18763
+ const database = openReadOnlyDatabase(path);
18740
18764
  try {
18741
18765
  database.exec("PRAGMA busy_timeout = 5000");
18742
18766
  return database.prepare("SELECT 1 FROM runs WHERE run_id = ?").get(runId) !== void 0;
@@ -18773,7 +18797,7 @@ var KxmRuntimeRegistry = class {
18773
18797
  path;
18774
18798
  database;
18775
18799
  constructor(path) {
18776
- this.path = resolve4(path);
18800
+ this.path = resolve5(path);
18777
18801
  this.database = openDatabase(this.path, "runtime registry", {
18778
18802
  schema: REGISTRY_SCHEMA,
18779
18803
  version: KXM_REGISTRY_SCHEMA_VERSION,
@@ -18872,7 +18896,7 @@ var KxmRuntimeRegistry = class {
18872
18896
  return rows.map((row) => ({ projectRoot: row.project_root, projectId: row.project_id }));
18873
18897
  }
18874
18898
  registerProject(registration) {
18875
- const projectRoot = resolve4(registration.projectRoot);
18899
+ const projectRoot = resolve5(registration.projectRoot);
18876
18900
  const projectKey = projectRuntimeKey(projectRoot);
18877
18901
  this.database.exec("BEGIN IMMEDIATE");
18878
18902
  try {
@@ -19299,7 +19323,7 @@ var KxmRunEventStore = class {
19299
19323
  syncRedactor = new KxmSyncRedactor();
19300
19324
  database;
19301
19325
  constructor(path) {
19302
- this.path = resolve4(path);
19326
+ this.path = resolve5(path);
19303
19327
  this.database = openDatabase(this.path, "run event store", {
19304
19328
  schema: EVENT_STORE_SCHEMA,
19305
19329
  version: KXM_EVENT_STORE_SCHEMA_VERSION,
@@ -19324,7 +19348,7 @@ var KxmRunEventStore = class {
19324
19348
  }
19325
19349
  readRunPrompts() {
19326
19350
  const sidecar = this.runPromptSidecarPath();
19327
- if (!existsSync5(sidecar)) return {};
19351
+ if (!existsSync6(sidecar)) return {};
19328
19352
  try {
19329
19353
  const parsed = JSON.parse(readFileSync3(sidecar, "utf8"));
19330
19354
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
@@ -23195,12 +23219,12 @@ function enqueueKxmScheduledRun(storePath, runId, configRevision, bound, start)
23195
23219
  if (owner.admitted.has(runId) || owner.queue.some((item) => item.runId === runId)) {
23196
23220
  return Promise.reject(runtimeError("run_busy", runId, `run ${runId} is already admitted or queued`));
23197
23221
  }
23198
- return new Promise((resolve11, reject) => {
23222
+ return new Promise((resolve12, reject) => {
23199
23223
  owner.queue.push({
23200
23224
  runId,
23201
23225
  configRevision,
23202
23226
  bound,
23203
- start: (token) => start(token).then(resolve11, reject),
23227
+ start: (token) => start(token).then(resolve12, reject),
23204
23228
  fail: (error) => reject(error)
23205
23229
  });
23206
23230
  pump(storePath, owner);
@@ -23261,7 +23285,7 @@ function kxmToolPolicyRevision(bundle) {
23261
23285
  return sha256Of(kxmCanonicalJson({ policies, gateRegistry: bundle.gateRegistry?.value ?? null }));
23262
23286
  }
23263
23287
  function collectMemoryFiles(dir, baseDir, ignoreSubdirs = /* @__PURE__ */ new Set()) {
23264
- if (!existsSync6(dir)) return [];
23288
+ if (!existsSync7(dir)) return [];
23265
23289
  const entries = readdirSync3(dir, { withFileTypes: true });
23266
23290
  const results = [];
23267
23291
  for (const entry of entries) {
@@ -23720,7 +23744,7 @@ function assertKxmConfigError(error) {
23720
23744
  // plugins/kxm/src/runtime-supervisor.ts
23721
23745
  import { spawn as spawn3 } from "node:child_process";
23722
23746
  import { createHash as createHash14, createHmac, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
23723
- import { chmodSync as chmodSync2, existsSync as existsSync15, lstatSync as lstatSync5, mkdirSync as mkdirSync9, readFileSync as readFileSync12, renameSync as renameSync5, rmSync as rmSync4, writeFileSync as writeFileSync9 } from "node:fs";
23747
+ import { chmodSync as chmodSync2, existsSync as existsSync16, lstatSync as lstatSync5, mkdirSync as mkdirSync9, readFileSync as readFileSync12, renameSync as renameSync5, rmSync as rmSync4, writeFileSync as writeFileSync9 } from "node:fs";
23724
23748
  import { createServer } from "node:http";
23725
23749
  import { dirname as dirname11, isAbsolute as isAbsolute6, join as join18 } from "node:path";
23726
23750
 
@@ -23847,7 +23871,7 @@ async function beginOneShotEvidence(root, intent, sensitive) {
23847
23871
  // plugins/kxm/src/prices.ts
23848
23872
  var import_yaml3 = __toESM(require_dist(), 1);
23849
23873
  import { createHash as createHash9 } from "node:crypto";
23850
- import { existsSync as existsSync7, readFileSync as readFileSync5, statSync, writeFileSync as writeFileSync3 } from "node:fs";
23874
+ import { existsSync as existsSync8, readFileSync as readFileSync5, statSync, writeFileSync as writeFileSync3 } from "node:fs";
23851
23875
  import { join as join8 } from "node:path";
23852
23876
 
23853
23877
  // plugins/kxm/src/price-calc.ts
@@ -24000,8 +24024,8 @@ function parsePriceCatalog(text) {
24000
24024
  return catalog;
24001
24025
  }
24002
24026
  function loadPriceCatalog(rootOrPath) {
24003
- const candidatePath = existsSync7(join8(rootOrPath, ".kxm", "prices.yaml")) ? join8(rootOrPath, ".kxm", "prices.yaml") : existsSync7(join8(rootOrPath, "prices.yaml")) ? join8(rootOrPath, "prices.yaml") : existsSync7(rootOrPath) && statSync(rootOrPath).isFile() ? rootOrPath : void 0;
24004
- if (!candidatePath || !existsSync7(candidatePath)) {
24027
+ const candidatePath = existsSync8(join8(rootOrPath, ".kxm", "prices.yaml")) ? join8(rootOrPath, ".kxm", "prices.yaml") : existsSync8(join8(rootOrPath, "prices.yaml")) ? join8(rootOrPath, "prices.yaml") : existsSync8(rootOrPath) && statSync(rootOrPath).isFile() ? rootOrPath : void 0;
24028
+ if (!candidatePath || !existsSync8(candidatePath)) {
24005
24029
  return void 0;
24006
24030
  }
24007
24031
  const content = readFileSync5(candidatePath, "utf8");
@@ -24023,19 +24047,19 @@ function loadPriceCatalogForEstimate(options) {
24023
24047
  // plugins/kxm/src/engine.ts
24024
24048
  var import_yaml7 = __toESM(require_dist(), 1);
24025
24049
  import { createHash as createHash13, randomBytes as randomBytes2, timingSafeEqual } from "node:crypto";
24026
- import { existsSync as existsSync11, readFileSync as readFileSync9 } from "node:fs";
24050
+ import { existsSync as existsSync12, readFileSync as readFileSync9 } from "node:fs";
24027
24051
  import { join as join14 } from "node:path";
24028
24052
 
24029
24053
  // plugins/kxm/src/routes.ts
24030
24054
  var import_yaml4 = __toESM(require_dist(), 1);
24031
- import { existsSync as existsSync8, readFileSync as readFileSync6, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4, readdirSync as readdirSync4 } from "node:fs";
24055
+ import { existsSync as existsSync9, readFileSync as readFileSync6, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4, readdirSync as readdirSync4 } from "node:fs";
24032
24056
  import { join as join9 } from "node:path";
24033
24057
  var RETIRED_POLICY = ".kxm/producers.yaml";
24034
24058
  var empty = () => ({ schema: "kxm.routes.v2", updatedAt: (/* @__PURE__ */ new Date()).toISOString(), admitted: [], disabled: [], roles: {} });
24035
24059
  function loadRoutePolicy(root) {
24036
- if (existsSync8(join9(root, RETIRED_POLICY))) throw new Error(`retired ${RETIRED_POLICY} present; use .kxm/routes.yaml (kxm.routes.v2)`);
24060
+ if (existsSync9(join9(root, RETIRED_POLICY))) throw new Error(`retired ${RETIRED_POLICY} present; use .kxm/routes.yaml (kxm.routes.v2)`);
24037
24061
  const path = join9(root, ".kxm", "routes.yaml");
24038
- if (!existsSync8(path)) return empty();
24062
+ if (!existsSync9(path)) return empty();
24039
24063
  const value = (0, import_yaml4.parse)(readFileSync6(path, "utf8"));
24040
24064
  if (value?.schema !== "kxm.routes.v2" || !Array.isArray(value.admitted)) throw new Error("invalid .kxm/routes.yaml");
24041
24065
  return { schema: "kxm.routes.v2", updatedAt: typeof value.updatedAt === "string" ? value.updatedAt : (/* @__PURE__ */ new Date()).toISOString(), admitted: value.admitted.filter((x) => typeof x === "string"), disabled: Array.isArray(value.disabled) ? value.disabled.filter((x) => typeof x === "string") : [], roles: value.roles && typeof value.roles === "object" ? Object.fromEntries(Object.entries(value.roles).filter(([, v]) => Array.isArray(v)).map(([k, v]) => [k, v.filter((x) => typeof x === "string")])) : {} };
@@ -24043,7 +24067,7 @@ function loadRoutePolicy(root) {
24043
24067
  function listRoleBindings(root) {
24044
24068
  const dir = join9(root, ".kxm", "roles");
24045
24069
  const result = {};
24046
- if (!existsSync8(dir)) return result;
24070
+ if (!existsSync9(dir)) return result;
24047
24071
  for (const file of readdirSync4(dir).filter((name) => name.endsWith(".yaml"))) {
24048
24072
  const role = file.slice(0, -5);
24049
24073
  const value = (0, import_yaml4.parse)(readFileSync6(join9(dir, file), "utf8"));
@@ -25006,8 +25030,8 @@ function memoryRecordToContextItem(record2, project) {
25006
25030
 
25007
25031
  // plugins/kxm/src/memory.ts
25008
25032
  var import_yaml5 = __toESM(require_dist(), 1);
25009
- import { existsSync as existsSync9, mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
25010
- import { extname as extname2, join as join10, resolve as resolve5 } from "node:path";
25033
+ import { existsSync as existsSync10, mkdirSync as mkdirSync4, readdirSync as readdirSync5, readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
25034
+ import { extname as extname2, join as join10, resolve as resolve6 } from "node:path";
25011
25035
  var MEMORY_SCHEMA = "kxm.memory.v1";
25012
25036
  var VALID_SCOPES = /* @__PURE__ */ new Set(["agent", "project", "run", "operator"]);
25013
25037
  var VALID_AUTHORITIES = /* @__PURE__ */ new Set(["instruction", "evidence", "promoted"]);
@@ -25105,14 +25129,14 @@ function parseMemoryRecord(raw, filename = "memory.md") {
25105
25129
  };
25106
25130
  }
25107
25131
  function memoryDirectories(repoRoot) {
25108
- const root = resolve5(repoRoot);
25132
+ const root = resolve6(repoRoot);
25109
25133
  const memoryDir = join10(root, ".kxm", "memory");
25110
25134
  const candidatesDir = join10(memoryDir, "candidates");
25111
25135
  return { memoryDir, candidatesDir };
25112
25136
  }
25113
25137
  function loadAuthoredMemory(repoRoot) {
25114
25138
  const { memoryDir } = memoryDirectories(repoRoot);
25115
- if (!existsSync9(memoryDir)) return [];
25139
+ if (!existsSync10(memoryDir)) return [];
25116
25140
  const records = [];
25117
25141
  const entries = readdirSync5(memoryDir, { withFileTypes: true });
25118
25142
  for (const entry of entries) {
@@ -25135,7 +25159,7 @@ function loadAuthoredMemory(repoRoot) {
25135
25159
  // plugins/kxm/src/skills.ts
25136
25160
  var import_yaml6 = __toESM(require_dist(), 1);
25137
25161
  import { createHash as createHash10 } from "node:crypto";
25138
- import { existsSync as existsSync10, mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync8, renameSync, rmSync, statSync as statSync2, writeFileSync as writeFileSync6 } from "node:fs";
25162
+ import { existsSync as existsSync11, mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync8, renameSync, rmSync, statSync as statSync2, writeFileSync as writeFileSync6 } from "node:fs";
25139
25163
  import { dirname as dirname7, join as join11 } from "node:path";
25140
25164
  var SKILL_CANDIDATE_SCHEMA = "kxm.skill-candidate.v1";
25141
25165
  var SKILL_EVALUATION_SCHEMA = "kxm.skill-evaluation.v1";
@@ -25254,7 +25278,7 @@ var SkillLifecycle = class {
25254
25278
  appendHistory(id, record2) {
25255
25279
  const line = `${JSON.stringify(record2)}
25256
25280
  `;
25257
- if (existsSync10(this.historyFile(id))) {
25281
+ if (existsSync11(this.historyFile(id))) {
25258
25282
  const existing = readFileSync8(this.historyFile(id), "utf8");
25259
25283
  const lines = existing.split("\n").filter((entry) => entry.trim());
25260
25284
  this.write(this.historyFile(id), [...lines.slice(-499), line.trim()].join("\n") + "\n");
@@ -25264,12 +25288,12 @@ var SkillLifecycle = class {
25264
25288
  }
25265
25289
  history(id) {
25266
25290
  const file = this.historyFile(id);
25267
- if (!existsSync10(file)) return [];
25291
+ if (!existsSync11(file)) return [];
25268
25292
  return readFileSync8(file, "utf8").split("\n").filter((line) => line.trim()).map((line) => JSON.parse(line));
25269
25293
  }
25270
25294
  readMetadata(state, id) {
25271
25295
  const { metadata } = this.paths(state, id);
25272
- if (!existsSync10(metadata)) {
25296
+ if (!existsSync11(metadata)) {
25273
25297
  throw new SkillLifecycleError("skill_not_found", `skill ${id} not found in ${state}`);
25274
25298
  }
25275
25299
  return JSON.parse(readFileSync8(metadata, "utf8"));
@@ -25277,7 +25301,7 @@ var SkillLifecycle = class {
25277
25301
  move(from, to, id) {
25278
25302
  const fromDir = join11(this.dir(from), id);
25279
25303
  const toDir = join11(this.dir(to), id);
25280
- if (!existsSync10(fromDir)) {
25304
+ if (!existsSync11(fromDir)) {
25281
25305
  throw new SkillLifecycleError("skill_not_found", `skill ${id} not found in ${from}`);
25282
25306
  }
25283
25307
  if (this.dryRun) {
@@ -25285,7 +25309,7 @@ var SkillLifecycle = class {
25285
25309
  return;
25286
25310
  }
25287
25311
  mkdirSync5(this.dir(to), { recursive: true });
25288
- if (existsSync10(toDir)) rmSync(toDir, { recursive: true, force: true });
25312
+ if (existsSync11(toDir)) rmSync(toDir, { recursive: true, force: true });
25289
25313
  renameSync(fromDir, toDir);
25290
25314
  }
25291
25315
  /** Submit a new skill candidate. Content is redacted of secret material at
@@ -25328,7 +25352,7 @@ var SkillLifecycle = class {
25328
25352
  const contentSha256 = skillContentSha256(content);
25329
25353
  const id = skillIdFor(name, contentSha256);
25330
25354
  const { metadata, skill } = this.paths("candidate", id);
25331
- if (existsSync10(metadata)) {
25355
+ if (existsSync11(metadata)) {
25332
25356
  throw new SkillLifecycleError(
25333
25357
  "skill_candidate_exists",
25334
25358
  `identical candidate ${id} already exists; changed behavior requires changed content`
@@ -25487,7 +25511,7 @@ var SkillLifecycle = class {
25487
25511
  }
25488
25512
  list(state) {
25489
25513
  const dir = this.dir(state);
25490
- if (!existsSync10(dir)) return [];
25514
+ if (!existsSync11(dir)) return [];
25491
25515
  const ids = readdirSorted(dir);
25492
25516
  return ids.map((id) => {
25493
25517
  try {
@@ -25719,14 +25743,14 @@ import { join as join13 } from "node:path";
25719
25743
 
25720
25744
  // plugins/kxm/src/artifacts-exist.ts
25721
25745
  import { lstatSync as lstatSync4, realpathSync as realpathSync3, statSync as statSync3 } from "node:fs";
25722
- import { isAbsolute as isAbsolute3, relative as relative3, resolve as resolve6 } from "node:path";
25746
+ import { isAbsolute as isAbsolute3, relative as relative3, resolve as resolve7 } from "node:path";
25723
25747
  function staysUnder(root, candidate) {
25724
25748
  const child = relative3(root, candidate);
25725
25749
  return child === "" || !isAbsolute3(child) && child !== ".." && !child.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`);
25726
25750
  }
25727
25751
  function verifyArtifactExists(rootInput, pathInput) {
25728
- const lexicalRoot = resolve6(rootInput);
25729
- const lexicalPath = resolve6(pathInput);
25752
+ const lexicalRoot = resolve7(rootInput);
25753
+ const lexicalPath = resolve7(pathInput);
25730
25754
  if (!staysUnder(lexicalRoot, lexicalPath)) {
25731
25755
  return { ok: false, error: "artifact_outside_workspace_assets", path: lexicalPath };
25732
25756
  }
@@ -25925,8 +25949,8 @@ var CommandObserver = class {
25925
25949
  this.requestStop("error", "lost-close");
25926
25950
  }
25927
25951
  run() {
25928
- return new Promise((resolve11) => {
25929
- this.resolveOutcome = resolve11;
25952
+ return new Promise((resolve12) => {
25953
+ this.resolveOutcome = resolve12;
25930
25954
  try {
25931
25955
  this.start();
25932
25956
  } catch (error) {
@@ -27252,8 +27276,8 @@ var KxmRunScheduler = class _KxmRunScheduler {
27252
27276
  resolve: (_value) => void 0,
27253
27277
  reject: (_error) => void 0
27254
27278
  };
27255
- const settled = new Promise((resolve11, reject) => {
27256
- pending.resolve = resolve11;
27279
+ const settled = new Promise((resolve12, reject) => {
27280
+ pending.resolve = resolve12;
27257
27281
  pending.reject = reject;
27258
27282
  });
27259
27283
  void settled.then(void 0, () => void 0);
@@ -27652,7 +27676,7 @@ function unreconciledPanelAttemptId(state) {
27652
27676
  function resolveProducerRoute(projectRoot, step, agentId) {
27653
27677
  let agentModel;
27654
27678
  const agentFile = join14(projectRoot, ".kxm", "agents", `${agentId}.yaml`);
27655
- if (existsSync11(agentFile)) {
27679
+ if (existsSync12(agentFile)) {
27656
27680
  try {
27657
27681
  const parsed = (0, import_yaml7.parse)(readFileSync9(agentFile, "utf8"));
27658
27682
  if (typeof parsed?.model === "string") {
@@ -28858,7 +28882,7 @@ function unsupportedStep(plan, step, producerId) {
28858
28882
  return void 0;
28859
28883
  }
28860
28884
  function readYamlRecord(path) {
28861
- if (!existsSync11(path)) return void 0;
28885
+ if (!existsSync12(path)) return void 0;
28862
28886
  try {
28863
28887
  const parsed = (0, import_yaml7.parse)(readFileSync9(path, "utf8"));
28864
28888
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
@@ -28900,7 +28924,7 @@ function unsupportedLiveWrite(projectRoot, step, agentId, selector, maxConcurren
28900
28924
  };
28901
28925
  }
28902
28926
  const rosterPath = join14(projectRoot, ".kxm", "roster.yaml");
28903
- if (!existsSync11(rosterPath)) return void 0;
28927
+ if (!existsSync12(rosterPath)) return void 0;
28904
28928
  const roster = readYamlRecord(rosterPath);
28905
28929
  if (!roster || roster.schema !== "kxm.developer-roster.v1") {
28906
28930
  return { reason: "step_unsupported", field: "model", detail: "live write steps require a readable kxm.developer-roster.v1" };
@@ -29781,9 +29805,9 @@ var RuntimeHubClient = class {
29781
29805
  };
29782
29806
 
29783
29807
  // plugins/kxm/src/hub-binding.ts
29784
- import { existsSync as existsSync12, mkdirSync as mkdirSync6, readFileSync as readFileSync10, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync7 } from "node:fs";
29808
+ import { existsSync as existsSync13, mkdirSync as mkdirSync6, readFileSync as readFileSync10, renameSync as renameSync2, rmSync as rmSync2, writeFileSync as writeFileSync7 } from "node:fs";
29785
29809
  import { homedir as homedir2 } from "node:os";
29786
- import { dirname as dirname8, isAbsolute as isAbsolute4, join as join16, resolve as resolve7 } from "node:path";
29810
+ import { dirname as dirname8, isAbsolute as isAbsolute4, join as join16, resolve as resolve8 } from "node:path";
29787
29811
  var HUB_BINDING_SCHEMA = "kxm.hub-binding.v1";
29788
29812
  var HubBindingError = class extends Error {
29789
29813
  constructor(message) {
@@ -29795,17 +29819,17 @@ function resolveUserStateRoot(env) {
29795
29819
  const explicit = env.KXM_STATE_HOME?.trim();
29796
29820
  if (explicit) {
29797
29821
  if (!isAbsolute4(explicit)) throw new HubBindingError("local_state_root_not_absolute");
29798
- return resolve7(explicit);
29822
+ return resolve8(explicit);
29799
29823
  }
29800
29824
  if (process.platform === "win32") {
29801
29825
  const localAppData = env.LOCALAPPDATA?.trim();
29802
29826
  const base2 = localAppData && isAbsolute4(localAppData) ? localAppData : join16(homedir2(), "AppData", "Local");
29803
- return resolve7(base2, "KXM");
29827
+ return resolve8(base2, "KXM");
29804
29828
  }
29805
- if (process.platform === "darwin") return resolve7(homedir2(), "Library", "Application Support", "KXM");
29829
+ if (process.platform === "darwin") return resolve8(homedir2(), "Library", "Application Support", "KXM");
29806
29830
  const xdgState = env.XDG_STATE_HOME?.trim();
29807
29831
  const base = xdgState && isAbsolute4(xdgState) ? xdgState : join16(homedir2(), ".local", "state");
29808
- return resolve7(base, "kxm");
29832
+ return resolve8(base, "kxm");
29809
29833
  }
29810
29834
  function hubBindingFile(env = process.env) {
29811
29835
  return join16(resolveUserStateRoot(env), "hub-binding.json");
@@ -29828,7 +29852,7 @@ function isIsoTimestamp(value) {
29828
29852
  }
29829
29853
  function readHubBinding(env = process.env) {
29830
29854
  const file = hubBindingFile(env);
29831
- if (!existsSync12(file)) return void 0;
29855
+ if (!existsSync13(file)) return void 0;
29832
29856
  let parsed;
29833
29857
  try {
29834
29858
  parsed = JSON.parse(readFileSync10(file, "utf8"));
@@ -29853,9 +29877,9 @@ function readHubBinding(env = process.env) {
29853
29877
  }
29854
29878
 
29855
29879
  // plugins/kxm/src/hub-env.ts
29856
- import { existsSync as existsSync13, mkdirSync as mkdirSync7, readFileSync as readFileSync11, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync8 } from "node:fs";
29880
+ import { existsSync as existsSync14, mkdirSync as mkdirSync7, readFileSync as readFileSync11, renameSync as renameSync3, rmSync as rmSync3, writeFileSync as writeFileSync8 } from "node:fs";
29857
29881
  import { homedir as homedir3 } from "node:os";
29858
- import { dirname as dirname9, isAbsolute as isAbsolute5, join as join17, resolve as resolve8 } from "node:path";
29882
+ import { dirname as dirname9, isAbsolute as isAbsolute5, join as join17, resolve as resolve9 } from "node:path";
29859
29883
  var HUB_ENV_SCHEMA = "kxm.hub-env.v1";
29860
29884
  var HubEnvError = class extends Error {
29861
29885
  constructor(message) {
@@ -29867,24 +29891,24 @@ function resolveUserStateRoot2(env) {
29867
29891
  const explicit = env.KXM_STATE_HOME?.trim();
29868
29892
  if (explicit) {
29869
29893
  if (!isAbsolute5(explicit)) throw new HubEnvError("local_state_root_not_absolute");
29870
- return resolve8(explicit);
29894
+ return resolve9(explicit);
29871
29895
  }
29872
29896
  if (process.platform === "win32") {
29873
29897
  const localAppData = env.LOCALAPPDATA?.trim();
29874
29898
  const base2 = localAppData && isAbsolute5(localAppData) ? localAppData : join17(homedir3(), "AppData", "Local");
29875
- return resolve8(base2, "KXM");
29899
+ return resolve9(base2, "KXM");
29876
29900
  }
29877
- if (process.platform === "darwin") return resolve8(homedir3(), "Library", "Application Support", "KXM");
29901
+ if (process.platform === "darwin") return resolve9(homedir3(), "Library", "Application Support", "KXM");
29878
29902
  const xdgState = env.XDG_STATE_HOME?.trim();
29879
29903
  const base = xdgState && isAbsolute5(xdgState) ? xdgState : join17(homedir3(), ".local", "state");
29880
- return resolve8(base, "kxm");
29904
+ return resolve9(base, "kxm");
29881
29905
  }
29882
29906
  function hubEnvFile(env = process.env) {
29883
29907
  return join17(resolveUserStateRoot2(env), "hub-env.json");
29884
29908
  }
29885
29909
  function readHubEnvRecord(env = process.env) {
29886
29910
  const file = hubEnvFile(env);
29887
- if (!existsSync13(file)) return void 0;
29911
+ if (!existsSync14(file)) return void 0;
29888
29912
  let parsed;
29889
29913
  try {
29890
29914
  parsed = JSON.parse(readFileSync11(file, "utf8"));
@@ -29927,7 +29951,7 @@ function resolveClientHubAuthToken(env, project) {
29927
29951
  }
29928
29952
 
29929
29953
  // plugins/kxm/src/logger.ts
29930
- import { appendFileSync, existsSync as existsSync14, mkdirSync as mkdirSync8, renameSync as renameSync4, statSync as statSync4, unlinkSync as unlinkSync2 } from "node:fs";
29954
+ import { appendFileSync, existsSync as existsSync15, mkdirSync as mkdirSync8, renameSync as renameSync4, statSync as statSync4, unlinkSync as unlinkSync2 } from "node:fs";
29931
29955
  import { dirname as dirname10 } from "node:path";
29932
29956
  var LOG_LEVEL_PRIORITY = {
29933
29957
  debug: 10,
@@ -29965,7 +29989,7 @@ function redactLogValue(val, key) {
29965
29989
  function rotateLogFiles(filePath, maxFiles) {
29966
29990
  for (let i = maxFiles; i >= 1; i--) {
29967
29991
  const current = `${filePath}.${i}`;
29968
- if (existsSync14(current)) {
29992
+ if (existsSync15(current)) {
29969
29993
  if (i >= maxFiles) {
29970
29994
  try {
29971
29995
  unlinkSync2(current);
@@ -29979,7 +30003,7 @@ function rotateLogFiles(filePath, maxFiles) {
29979
30003
  }
29980
30004
  }
29981
30005
  }
29982
- if (existsSync14(filePath)) {
30006
+ if (existsSync15(filePath)) {
29983
30007
  try {
29984
30008
  renameSync4(filePath, `${filePath}.1`);
29985
30009
  } catch {
@@ -29996,7 +30020,7 @@ function createLogger(options) {
29996
30020
  const shouldStdout = options.stdout ?? !isDaemon;
29997
30021
  const correlationDefaults = options.correlation ?? {};
29998
30022
  let currentSize = 0;
29999
- if (filePath && existsSync14(filePath)) {
30023
+ if (filePath && existsSync15(filePath)) {
30000
30024
  try {
30001
30025
  currentSize = statSync4(filePath).size;
30002
30026
  } catch {
@@ -30123,7 +30147,7 @@ function supervisorErrorFile(paths) {
30123
30147
  }
30124
30148
  function clearSupervisorError(paths) {
30125
30149
  const file = supervisorErrorFile(paths);
30126
- if (existsSync15(file)) rmSync4(file, { force: true });
30150
+ if (existsSync16(file)) rmSync4(file, { force: true });
30127
30151
  }
30128
30152
  function recordSupervisorError(paths, message) {
30129
30153
  try {
@@ -30146,7 +30170,7 @@ function readRecentSupervisorError(paths) {
30146
30170
  }
30147
30171
  }
30148
30172
  function kxmSupervisorStatus(paths) {
30149
- if (!existsSync15(paths.registryDb)) return { running: false };
30173
+ if (!existsSync16(paths.registryDb)) return { running: false };
30150
30174
  const registry = new KxmRuntimeRegistry(paths.registryDb);
30151
30175
  try {
30152
30176
  const record2 = registry.supervisor();
@@ -30301,8 +30325,8 @@ async function waitForDriveSessions(settled, graceMs) {
30301
30325
  try {
30302
30326
  await Promise.race([
30303
30327
  Promise.allSettled(settled),
30304
- new Promise((resolve11) => {
30305
- timeout = setTimeout(resolve11, graceMs);
30328
+ new Promise((resolve12) => {
30329
+ timeout = setTimeout(resolve12, graceMs);
30306
30330
  timeout.unref?.();
30307
30331
  })
30308
30332
  ]);
@@ -31254,8 +31278,8 @@ var PiSession = class {
31254
31278
  }
31255
31279
  const id = `cmd_${++this.commandCounter}`;
31256
31280
  const payload = { ...command, id };
31257
- return new Promise((resolve11, reject) => {
31258
- this.pendingCommands.set(id, { resolve: resolve11, reject });
31281
+ return new Promise((resolve12, reject) => {
31282
+ this.pendingCommands.set(id, { resolve: resolve12, reject });
31259
31283
  try {
31260
31284
  this.process.stdin.write(JSON.stringify(payload) + "\n");
31261
31285
  } catch (err) {
@@ -31275,7 +31299,7 @@ var PiSession = class {
31275
31299
  return { outcome: "cancelled", text: "aborted", usage: {} };
31276
31300
  }
31277
31301
  this.status = "busy";
31278
- return new Promise((resolve11, reject) => {
31302
+ return new Promise((resolve12, reject) => {
31279
31303
  let signalCleanup;
31280
31304
  if (signal) {
31281
31305
  const onAbort = () => {
@@ -31289,7 +31313,7 @@ var PiSession = class {
31289
31313
  signalCleanup = () => signal.removeEventListener("abort", onAbort);
31290
31314
  }
31291
31315
  this.activePrompt = {
31292
- resolve: resolve11,
31316
+ resolve: resolve12,
31293
31317
  reject,
31294
31318
  allowedOutcomes,
31295
31319
  text: "",
@@ -31541,8 +31565,8 @@ function createKxmPiProducer(options = {}) {
31541
31565
 
31542
31566
  // plugins/kxm/src/improve.ts
31543
31567
  import { createHash as createHash15 } from "node:crypto";
31544
- import { existsSync as existsSync16, mkdirSync as mkdirSync10, writeFileSync as writeFileSync10 } from "node:fs";
31545
- import { join as join20, relative as relative4, resolve as resolve9 } from "node:path";
31568
+ import { existsSync as existsSync17, mkdirSync as mkdirSync10, writeFileSync as writeFileSync10 } from "node:fs";
31569
+ import { join as join20, relative as relative4, resolve as resolve10 } from "node:path";
31546
31570
  var CANDIDATE_SCHEMA = "kxm.candidate.v1";
31547
31571
  var IMPROVEMENT_REPORT_SCHEMA = "kxm.improvement-report.v2";
31548
31572
  var IMPROVEMENT_REPORT_V1_SCHEMA = "kxm.improvement-report.v1";
@@ -31798,8 +31822,8 @@ function groupRoutingRecords(records, options = {}) {
31798
31822
  }).map((entry) => entry.row);
31799
31823
  }
31800
31824
  function buildImprovementReport(records, options = {}) {
31801
- const projectRoot = options.projectRoot ? resolve9(options.projectRoot) : process.cwd();
31802
- const candidatesDir = options.candidatesDir ? resolve9(options.candidatesDir) : join20(projectRoot, ".kxm", "candidates");
31825
+ const projectRoot = options.projectRoot ? resolve10(options.projectRoot) : process.cwd();
31826
+ const candidatesDir = options.candidatesDir ? resolve10(options.candidatesDir) : join20(projectRoot, ".kxm", "candidates");
31803
31827
  const promotionPolicy = options.promotionPolicy ?? "manual_pr";
31804
31828
  const groups = groupRoutingRecords(records, options);
31805
31829
  const candidates = [];
@@ -31835,7 +31859,7 @@ function buildImprovementReport(records, options = {}) {
31835
31859
  createdAt: nowIso()
31836
31860
  };
31837
31861
  if (!options.dryRun) {
31838
- if (!existsSync16(candidatesDir)) {
31862
+ if (!existsSync17(candidatesDir)) {
31839
31863
  mkdirSync10(candidatesDir, { recursive: true });
31840
31864
  }
31841
31865
  writeFileSync10(diffFilePath, diff, "utf8");
@@ -32371,7 +32395,7 @@ Instructions for Operator:
32371
32395
 
32372
32396
  // plugins/kxm/src/modes.ts
32373
32397
  var import_yaml8 = __toESM(require_dist(), 1);
32374
- import { existsSync as existsSync17, readFileSync as readFileSync14 } from "node:fs";
32398
+ import { existsSync as existsSync18, readFileSync as readFileSync14 } from "node:fs";
32375
32399
  import { join as join21 } from "node:path";
32376
32400
  var DEFAULT_MODES_CONFIG = Object.freeze({
32377
32401
  schema: "kxm.modes.v1",
@@ -32436,7 +32460,7 @@ function loadModesConfig(projectRoot) {
32436
32460
  return DEFAULT_MODES_CONFIG;
32437
32461
  }
32438
32462
  const modesPath = join21(projectRoot, ".kxm", "modes.yaml");
32439
- if (!existsSync17(modesPath)) {
32463
+ if (!existsSync18(modesPath)) {
32440
32464
  return DEFAULT_MODES_CONFIG;
32441
32465
  }
32442
32466
  try {
@@ -32528,7 +32552,7 @@ function calculatePromptFootprint(resolved, projectRoot = process.cwd(), catalog
32528
32552
  for (const relPath of resolved.contextFiles) {
32529
32553
  const fullPath = join21(projectRoot, relPath);
32530
32554
  let chars = 0;
32531
- if (existsSync17(fullPath)) {
32555
+ if (existsSync18(fullPath)) {
32532
32556
  try {
32533
32557
  chars = readFileSync14(fullPath, "utf8").length;
32534
32558
  } catch {
@@ -32662,9 +32686,9 @@ ${divider}
32662
32686
 
32663
32687
  // plugins/kxm/src/ssh-remote.ts
32664
32688
  import { spawnSync as spawnSync5 } from "node:child_process";
32665
- import { existsSync as existsSync18, mkdirSync as mkdirSync11, readFileSync as readFileSync15, readdirSync as readdirSync8, rmSync as rmSync5, statSync as statSync5 } from "node:fs";
32689
+ import { existsSync as existsSync19, mkdirSync as mkdirSync11, readFileSync as readFileSync15, readdirSync as readdirSync8, rmSync as rmSync5, statSync as statSync5 } from "node:fs";
32666
32690
  import { homedir as homedir4 } from "node:os";
32667
- import { join as join22, resolve as resolve10 } from "node:path";
32691
+ import { join as join22, resolve as resolve11 } from "node:path";
32668
32692
  var MAX_SSH_OUTPUT_BYTES = 50 * 1024;
32669
32693
  var MAX_SSH_OUTPUT_LINES = 2e3;
32670
32694
  var DEFAULT_SOCKET_DIR = ".kxm/run/ssh-sockets";
@@ -32691,7 +32715,7 @@ function truncateSshOutput(raw) {
32691
32715
  }
32692
32716
  function parseSshConfig(configPath) {
32693
32717
  const targetPath = configPath ?? join22(homedir4(), ".ssh", "config");
32694
- if (!existsSync18(targetPath)) {
32718
+ if (!existsSync19(targetPath)) {
32695
32719
  return [];
32696
32720
  }
32697
32721
  try {
@@ -32772,8 +32796,8 @@ function resolveSshHostG(host, execFn = spawnSync5) {
32772
32796
  }
32773
32797
  }
32774
32798
  function ensureSocketDir(socketDir = DEFAULT_SOCKET_DIR) {
32775
- const resolved = resolve10(socketDir);
32776
- if (!existsSync18(resolved)) {
32799
+ const resolved = resolve11(socketDir);
32800
+ if (!existsSync19(resolved)) {
32777
32801
  mkdirSync11(resolved, { recursive: true, mode: 448 });
32778
32802
  }
32779
32803
  return resolved;