@kontextmind/kxm 0.7.20 → 0.7.22

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.
@@ -299,7 +299,7 @@ var HubClient = class {
299
299
  while (!this.stopped && this.agent) {
300
300
  this.eventsAbort = new AbortController();
301
301
  try {
302
- const response = await fetch(
302
+ const response = await (this.options.fetchImpl ?? fetch)(
303
303
  `${this.options.serverUrl.replace(/\/$/, "")}/v1/events?agentId=${encodeURIComponent(this.agent.id)}`,
304
304
  {
305
305
  headers: this.headers(),
@@ -376,7 +376,7 @@ var HubClient = class {
376
376
  const signal = init.signal ? AbortSignal.any([init.signal, timeoutSignal]) : timeoutSignal;
377
377
  let response;
378
378
  try {
379
- response = await fetch(`${this.options.serverUrl.replace(/\/$/, "")}${path}`, {
379
+ response = await (this.options.fetchImpl ?? fetch)(`${this.options.serverUrl.replace(/\/$/, "")}${path}`, {
380
380
  ...init,
381
381
  signal,
382
382
  headers: { ...this.headers(includeIdentity), ...init.headers ?? {} }
@@ -14524,8 +14524,8 @@ var require_dist2 = __commonJS({
14524
14524
 
14525
14525
  // plugins/kxm/src/extension.ts
14526
14526
  import { spawnSync as spawnSync2 } from "node:child_process";
14527
- import { existsSync as existsSync10, mkdirSync as mkdirSync9, readFileSync as readFileSync14, renameSync as renameSync5, rmSync as rmSync4, writeFileSync as writeFileSync7 } from "node:fs";
14528
- import { dirname as dirname7, join as join14 } from "node:path";
14527
+ import { existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync14, renameSync as renameSync5, rmSync as rmSync4, writeFileSync as writeFileSync7 } from "node:fs";
14528
+ import { dirname as dirname7, join as join15 } from "node:path";
14529
14529
 
14530
14530
  // plugins/kxm/src/commands.ts
14531
14531
  import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
@@ -14834,7 +14834,7 @@ var HubClient = class {
14834
14834
  while (!this.stopped && this.agent) {
14835
14835
  this.eventsAbort = new AbortController();
14836
14836
  try {
14837
- const response = await fetch(
14837
+ const response = await (this.options.fetchImpl ?? fetch)(
14838
14838
  `${this.options.serverUrl.replace(/\/$/, "")}/v1/events?agentId=${encodeURIComponent(this.agent.id)}`,
14839
14839
  {
14840
14840
  headers: this.headers(),
@@ -14911,7 +14911,7 @@ var HubClient = class {
14911
14911
  const signal = init.signal ? AbortSignal.any([init.signal, timeoutSignal]) : timeoutSignal;
14912
14912
  let response;
14913
14913
  try {
14914
- response = await fetch(`${this.options.serverUrl.replace(/\/$/, "")}${path}`, {
14914
+ response = await (this.options.fetchImpl ?? fetch)(`${this.options.serverUrl.replace(/\/$/, "")}${path}`, {
14915
14915
  ...init,
14916
14916
  signal,
14917
14917
  headers: { ...this.headers(includeIdentity), ...init.headers ?? {} }
@@ -15923,8 +15923,7 @@ function loadKxmConfig(repoRoot = process.cwd(), options = {}) {
15923
15923
  // plugins/kxm/src/hub-autostart.ts
15924
15924
  import { spawn } from "node:child_process";
15925
15925
  import { closeSync, mkdirSync as mkdirSync5, openSync, readFileSync as readFileSync5 } from "node:fs";
15926
- import { dirname as dirname5, join as join5, resolve as resolve5 } from "node:path";
15927
- import { fileURLToPath } from "node:url";
15926
+ import { join as join6, resolve as resolve5 } from "node:path";
15928
15927
 
15929
15928
  // plugins/kxm/src/hub-binding.ts
15930
15929
  import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
@@ -16172,6 +16171,25 @@ function resolveHubCredentials(options = {}) {
16172
16171
  };
16173
16172
  }
16174
16173
 
16174
+ // plugins/kxm/src/repo-root.ts
16175
+ import { existsSync as existsSync5 } from "node:fs";
16176
+ import { dirname as dirname5, join as join5 } from "node:path";
16177
+ import { fileURLToPath } from "node:url";
16178
+ var ROOT_MARKERS = ["scripts/kxm-hub.mjs", "scripts/kxm.mjs"];
16179
+ var MAX_WALK_DEPTH = 10;
16180
+ function findKxmRepoRoot(fromUrl = import.meta.url) {
16181
+ let dir = dirname5(fileURLToPath(fromUrl));
16182
+ for (let depth = 0; depth < MAX_WALK_DEPTH; depth += 1) {
16183
+ if (ROOT_MARKERS.some((marker) => existsSync5(join5(dir, marker)))) return dir;
16184
+ const parent = dirname5(dir);
16185
+ if (parent === dir) break;
16186
+ dir = parent;
16187
+ }
16188
+ throw new Error(
16189
+ `kxm: cannot locate the KXM repo root from ${fileURLToPath(fromUrl)} (walked ${MAX_WALK_DEPTH} levels looking for ${ROOT_MARKERS[0]})`
16190
+ );
16191
+ }
16192
+
16175
16193
  // plugins/kxm/src/redact.ts
16176
16194
  var SECRET_PATTERNS = [
16177
16195
  /\bsk-[A-Za-z0-9_-]{8,}\b/g,
@@ -16215,7 +16233,7 @@ function defaultProcessExists(pid) {
16215
16233
  function readLiveHubClaim(stateDir, processExists2 = defaultProcessExists) {
16216
16234
  let parsed;
16217
16235
  try {
16218
- parsed = JSON.parse(readFileSync5(join5(stateDir, "hub.pid"), "utf8"));
16236
+ parsed = JSON.parse(readFileSync5(join6(stateDir, "hub.pid"), "utf8"));
16219
16237
  } catch {
16220
16238
  return void 0;
16221
16239
  }
@@ -16230,7 +16248,7 @@ function readLiveHubClaim(stateDir, processExists2 = defaultProcessExists) {
16230
16248
  };
16231
16249
  }
16232
16250
  function defaultHubWrapperScriptPath(moduleUrl = import.meta.url) {
16233
- return resolve5(dirname5(fileURLToPath(moduleUrl)), "../../../scripts/kxm-hub.mjs");
16251
+ return join6(findKxmRepoRoot(moduleUrl), "scripts", "kxm-hub.mjs");
16234
16252
  }
16235
16253
  function defaultHubSpawner(command, args, options) {
16236
16254
  const child = spawn(command, [...args], options);
@@ -16255,8 +16273,8 @@ async function ensureHubRunning(options) {
16255
16273
  }
16256
16274
  const workdir = resolve5(env.KXM_WORKDIR?.trim() || options.cwd);
16257
16275
  const workspaceDir = resolve5(workdir, env.KXM_WORKSPACE_DIR?.trim() || ".kxm");
16258
- const stateDir = resolve5(workdir, env.KXM_STATE_DIR?.trim() || join5(workspaceDir, "state"));
16259
- const logsDir = resolve5(workdir, env.KXM_LOGS_DIR?.trim() || join5(workspaceDir, "logs"));
16276
+ const stateDir = resolve5(workdir, env.KXM_STATE_DIR?.trim() || join6(workspaceDir, "state"));
16277
+ const logsDir = resolve5(workdir, env.KXM_LOGS_DIR?.trim() || join6(workspaceDir, "logs"));
16260
16278
  const processExists2 = options.processExists ?? defaultProcessExists;
16261
16279
  const live = readLiveHubClaim(stateDir, processExists2);
16262
16280
  if (live) return { status: "claim-alive", pid: live.pid };
@@ -16266,7 +16284,7 @@ async function ensureHubRunning(options) {
16266
16284
  if (health === "on") return { status: "url-healthy", url: serverUrl };
16267
16285
  }
16268
16286
  const credentials = resolveHubCredentials({ env });
16269
- const logPath = join5(logsDir, HUB_AUTOSTART_LOG_NAME);
16287
+ const logPath = join6(logsDir, HUB_AUTOSTART_LOG_NAME);
16270
16288
  mkdirSync5(logsDir, { recursive: true });
16271
16289
  const logFd = openSync(logPath, "a");
16272
16290
  let child;
@@ -16315,12 +16333,12 @@ async function ensureHubRunning(options) {
16315
16333
 
16316
16334
  // plugins/kxm/src/project-name.ts
16317
16335
  import { readFileSync as readFileSync6 } from "node:fs";
16318
- import { basename, join as join6 } from "node:path";
16336
+ import { basename, join as join7 } from "node:path";
16319
16337
  function defaultProjectName(cwd, env = process.env) {
16320
16338
  const fromEnv = env.KXM_PROJECT?.trim();
16321
16339
  if (fromEnv) return fromEnv;
16322
16340
  try {
16323
- const pkg = JSON.parse(readFileSync6(join6(cwd, "package.json"), "utf8"));
16341
+ const pkg = JSON.parse(readFileSync6(join7(cwd, "package.json"), "utf8"));
16324
16342
  if (typeof pkg.name === "string" && pkg.name.trim().length > 0) return pkg.name.trim();
16325
16343
  } catch {
16326
16344
  }
@@ -20304,11 +20322,11 @@ function emptyUsage() {
20304
20322
  }
20305
20323
 
20306
20324
  // plugins/kxm/src/providers/claude-bridge/config.ts
20307
- import { existsSync as existsSync5, readFileSync as readFileSync7 } from "node:fs";
20325
+ import { existsSync as existsSync6, readFileSync as readFileSync7 } from "node:fs";
20308
20326
  import { homedir as homedir5 } from "node:os";
20309
- import { join as join7 } from "node:path";
20327
+ import { join as join8 } from "node:path";
20310
20328
  function tryParseJson(path) {
20311
- if (!existsSync5(path)) return {};
20329
+ if (!existsSync6(path)) return {};
20312
20330
  try {
20313
20331
  return JSON.parse(readFileSync7(path, "utf-8"));
20314
20332
  } catch (error2) {
@@ -20317,10 +20335,10 @@ function tryParseJson(path) {
20317
20335
  }
20318
20336
  }
20319
20337
  function globalConfigPath(home = homedir5()) {
20320
- return join7(home, ".pi", "agent", "claude-bridge.json");
20338
+ return join8(home, ".pi", "agent", "claude-bridge.json");
20321
20339
  }
20322
20340
  function projectConfigPath(cwd) {
20323
- return join7(cwd, ".pi", "claude-bridge.json");
20341
+ return join8(cwd, ".pi", "claude-bridge.json");
20324
20342
  }
20325
20343
  function loadConfig(cwd, home = homedir5()) {
20326
20344
  const global = tryParseJson(globalConfigPath(home));
@@ -36210,7 +36228,7 @@ function diagnosticSummary(diagnostic) {
36210
36228
  // plugins/kxm/src/recovery.ts
36211
36229
  import { createHash as createHash6 } from "node:crypto";
36212
36230
  import { lstatSync, readFileSync as readFileSync8, renameSync as renameSync3, rmSync as rmSync3 } from "node:fs";
36213
- import { join as join8 } from "node:path";
36231
+ import { join as join9 } from "node:path";
36214
36232
  function workerStateKey(project, agentName) {
36215
36233
  const safeProject = project.replace(/[^A-Za-z0-9_.-]/g, "_").slice(0, 24) || "project";
36216
36234
  const safeName = agentName.replace(/[^A-Za-z0-9_.-]/g, "_").slice(0, 32) || "agent";
@@ -36219,10 +36237,10 @@ function workerStateKey(project, agentName) {
36219
36237
  }
36220
36238
  function legacyRecoveryEnvelopePath(stateDir, agentName) {
36221
36239
  const safeName = agentName.replace(/[^A-Za-z0-9_.-]/g, "_");
36222
- return join8(stateDir, `worker-recovery-${safeName}.json`);
36240
+ return join9(stateDir, `worker-recovery-${safeName}.json`);
36223
36241
  }
36224
36242
  function recoveryEnvelopePath(stateDir, agentName, project) {
36225
- return project ? join8(stateDir, `worker-recovery-${workerStateKey(project, agentName)}.json`) : legacyRecoveryEnvelopePath(stateDir, agentName);
36243
+ return project ? join9(stateDir, `worker-recovery-${workerStateKey(project, agentName)}.json`) : legacyRecoveryEnvelopePath(stateDir, agentName);
36226
36244
  }
36227
36245
  var recoveryReasons = /* @__PURE__ */ new Set([
36228
36246
  "missing_tool_result",
@@ -36347,13 +36365,13 @@ async function consumeWorkerRecoveryEnvelope(client, stateDir, agentName, projec
36347
36365
  // plugins/kxm/src/session-work.ts
36348
36366
  import { spawnSync } from "node:child_process";
36349
36367
  import { randomUUID } from "node:crypto";
36350
- import { existsSync as existsSync8, mkdirSync as mkdirSync8, readFileSync as readFileSync12, renameSync as renameSync4, writeFileSync as writeFileSync6 } from "node:fs";
36351
- import { join as join12 } from "node:path";
36368
+ import { existsSync as existsSync9, mkdirSync as mkdirSync8, readFileSync as readFileSync12, renameSync as renameSync4, writeFileSync as writeFileSync6 } from "node:fs";
36369
+ import { join as join13 } from "node:path";
36352
36370
 
36353
36371
  // plugins/kxm/src/local-snapshot.ts
36354
- import { existsSync as existsSync6, readdirSync, readFileSync as readFileSync10 } from "node:fs";
36372
+ import { existsSync as existsSync7, readdirSync, readFileSync as readFileSync10 } from "node:fs";
36355
36373
  import { homedir as homedir6 } from "node:os";
36356
- import { isAbsolute as isAbsolute3, join as join10, resolve as resolve6 } from "node:path";
36374
+ import { isAbsolute as isAbsolute3, join as join11, resolve as resolve6 } from "node:path";
36357
36375
 
36358
36376
  // plugins/kxm/src/sqlite.ts
36359
36377
  import { createRequire as createRequire2 } from "node:module";
@@ -36396,9 +36414,9 @@ var DatabaseSync = class {
36396
36414
 
36397
36415
  // plugins/kxm/src/telemetry.ts
36398
36416
  import { appendFileSync, mkdirSync as mkdirSync6, readFileSync as readFileSync9 } from "node:fs";
36399
- import { dirname as dirname6, join as join9 } from "node:path";
36417
+ import { dirname as dirname6, join as join10 } from "node:path";
36400
36418
  function telemetryPath(logsDir) {
36401
- return join9(logsDir, "telemetry.jsonl");
36419
+ return join10(logsDir, "telemetry.jsonl");
36402
36420
  }
36403
36421
  function readRoutingRecords(path) {
36404
36422
  const records = [];
@@ -36553,36 +36571,36 @@ function readOpenMessageMetadata(database) {
36553
36571
  return messages;
36554
36572
  }
36555
36573
  function resolveKxmSnapshotPaths(cwd, env = process.env) {
36556
- const stateDir = env.KXM_STATE_DIR?.trim() || join10(cwd, ".kxm", "state");
36574
+ const stateDir = env.KXM_STATE_DIR?.trim() || join11(cwd, ".kxm", "state");
36557
36575
  const configured = env.KXM_DATA_PATH?.trim();
36558
- const dataPath = configured ? resolve6(cwd, configured) : join10(stateDir, "kxm.db");
36576
+ const dataPath = configured ? resolve6(cwd, configured) : join11(stateDir, "kxm.db");
36559
36577
  return { dataPath, stateDir };
36560
36578
  }
36561
36579
  function resolveVnextStateRoot(stateDir, options) {
36562
- if (options?.vnextStateRoot && existsSync6(options.vnextStateRoot)) {
36580
+ if (options?.vnextStateRoot && existsSync7(options.vnextStateRoot)) {
36563
36581
  return resolve6(options.vnextStateRoot);
36564
36582
  }
36565
- if (existsSync6(join10(stateDir, "runtime", "registry.db")) || existsSync6(join10(stateDir, "runtime", "projects"))) {
36583
+ if (existsSync7(join11(stateDir, "runtime", "registry.db")) || existsSync7(join11(stateDir, "runtime", "projects"))) {
36566
36584
  return stateDir;
36567
36585
  }
36568
36586
  const env = options?.env ?? process.env;
36569
36587
  const explicit = env.KXM_STATE_HOME?.trim() || env.KXM_USER_STATE_DIR?.trim() || env.KXM_STATE_ROOT?.trim();
36570
- if (explicit && isAbsolute3(explicit) && existsSync6(resolve6(explicit))) {
36588
+ if (explicit && isAbsolute3(explicit) && existsSync7(resolve6(explicit))) {
36571
36589
  return resolve6(explicit);
36572
36590
  }
36573
36591
  let base;
36574
36592
  if (process.platform === "win32") {
36575
36593
  const localAppData = env.LOCALAPPDATA?.trim();
36576
- base = localAppData && isAbsolute3(localAppData) ? localAppData : join10(homedir6(), "AppData", "Local");
36594
+ base = localAppData && isAbsolute3(localAppData) ? localAppData : join11(homedir6(), "AppData", "Local");
36577
36595
  base = resolve6(base, "KXM");
36578
36596
  } else if (process.platform === "darwin") {
36579
36597
  base = resolve6(homedir6(), "Library", "Application Support", "KXM");
36580
36598
  } else {
36581
36599
  const xdgState = env.XDG_STATE_HOME?.trim();
36582
- base = xdgState && isAbsolute3(xdgState) ? xdgState : join10(homedir6(), ".local", "state");
36600
+ base = xdgState && isAbsolute3(xdgState) ? xdgState : join11(homedir6(), ".local", "state");
36583
36601
  base = resolve6(base, "kxm");
36584
36602
  }
36585
- if (existsSync6(base)) return base;
36603
+ if (existsSync7(base)) return base;
36586
36604
  return void 0;
36587
36605
  }
36588
36606
  function loadLocalMeshSnapshot(dataPath, stateDir, options) {
@@ -36593,7 +36611,7 @@ function loadLocalMeshSnapshot(dataPath, stateDir, options) {
36593
36611
  let legacyRuns = [];
36594
36612
  let legacyRunTotal = 0;
36595
36613
  let plans = [];
36596
- if (existsSync6(dataPath)) {
36614
+ if (existsSync7(dataPath)) {
36597
36615
  hasLegacy = true;
36598
36616
  const database = new DatabaseSync(dataPath, { readOnly: true });
36599
36617
  try {
@@ -36613,11 +36631,11 @@ function loadLocalMeshSnapshot(dataPath, stateDir, options) {
36613
36631
  let vnextRunTotal = 0;
36614
36632
  const vnextStateRoot = resolveVnextStateRoot(stateDir, options);
36615
36633
  if (vnextStateRoot) {
36616
- const runtimeDir = join10(vnextStateRoot, "runtime");
36617
- const registryDbPath = join10(runtimeDir, "registry.db");
36618
- const projectsDir = join10(runtimeDir, "projects");
36634
+ const runtimeDir = join11(vnextStateRoot, "runtime");
36635
+ const registryDbPath = join11(runtimeDir, "registry.db");
36636
+ const projectsDir = join11(runtimeDir, "projects");
36619
36637
  const projectKeys = /* @__PURE__ */ new Set();
36620
- if (existsSync6(registryDbPath)) {
36638
+ if (existsSync7(registryDbPath)) {
36621
36639
  hasVnext = true;
36622
36640
  try {
36623
36641
  const regDb = new DatabaseSync(registryDbPath, { readOnly: true });
@@ -36633,7 +36651,7 @@ function loadLocalMeshSnapshot(dataPath, stateDir, options) {
36633
36651
  } catch {
36634
36652
  }
36635
36653
  }
36636
- if (existsSync6(projectsDir)) {
36654
+ if (existsSync7(projectsDir)) {
36637
36655
  try {
36638
36656
  for (const entry of readdirSync(projectsDir, { withFileTypes: true })) {
36639
36657
  if (entry.isDirectory()) {
@@ -36644,8 +36662,8 @@ function loadLocalMeshSnapshot(dataPath, stateDir, options) {
36644
36662
  }
36645
36663
  }
36646
36664
  for (const key of projectKeys) {
36647
- const eventDbPath = join10(projectsDir, key, "run-events.db");
36648
- if (existsSync6(eventDbPath)) {
36665
+ const eventDbPath = join11(projectsDir, key, "run-events.db");
36666
+ if (existsSync7(eventDbPath)) {
36649
36667
  hasVnext = true;
36650
36668
  try {
36651
36669
  const eventDb = new DatabaseSync(eventDbPath, { readOnly: true });
@@ -36675,10 +36693,10 @@ function loadLocalMeshSnapshot(dataPath, stateDir, options) {
36675
36693
  }
36676
36694
  }
36677
36695
  const pids = [];
36678
- if (existsSync6(stateDir)) {
36696
+ if (existsSync7(stateDir)) {
36679
36697
  for (const file of readdirSync(stateDir).filter((name) => name.endsWith(".pid"))) {
36680
36698
  try {
36681
- const record2 = JSON.parse(readFileSync10(join10(stateDir, file), "utf8"));
36699
+ const record2 = JSON.parse(readFileSync10(join11(stateDir, file), "utf8"));
36682
36700
  pids.push({
36683
36701
  file,
36684
36702
  ...record2.role ? { role: record2.role } : {},
@@ -36717,8 +36735,8 @@ function loadLocalMeshSnapshot(dataPath, stateDir, options) {
36717
36735
  } else {
36718
36736
  source = "legacy";
36719
36737
  }
36720
- const telemetryFile = join10(stateDir, "telemetry.jsonl");
36721
- const spend = existsSync6(telemetryFile) ? readRoutingRecords(telemetryFile) : [];
36738
+ const telemetryFile = join11(stateDir, "telemetry.jsonl");
36739
+ const spend = existsSync7(telemetryFile) ? readRoutingRecords(telemetryFile) : [];
36722
36740
  return {
36723
36741
  source,
36724
36742
  agents: agents.sort((a, b) => Number(b.online) - Number(a.online) || a.name.localeCompare(b.name)),
@@ -36733,13 +36751,13 @@ function loadLocalMeshSnapshot(dataPath, stateDir, options) {
36733
36751
  }
36734
36752
 
36735
36753
  // plugins/kxm/src/kxm-update.ts
36736
- import { existsSync as existsSync7, readFileSync as readFileSync11, writeFileSync as writeFileSync5, mkdirSync as mkdirSync7 } from "node:fs";
36737
- import { join as join11 } from "node:path";
36754
+ import { existsSync as existsSync8, readFileSync as readFileSync11, writeFileSync as writeFileSync5, mkdirSync as mkdirSync7 } from "node:fs";
36755
+ import { join as join12 } from "node:path";
36738
36756
  var KXM_UPDATE_CACHE = "update-check.json";
36739
36757
  var CACHE_TTL_MS = 6 * 60 * 60 * 1e3;
36740
36758
  function readUpdateCache(stateDir, now = Date.now()) {
36741
- const path = join11(stateDir, KXM_UPDATE_CACHE);
36742
- if (!existsSync7(path)) return void 0;
36759
+ const path = join12(stateDir, KXM_UPDATE_CACHE);
36760
+ if (!existsSync8(path)) return void 0;
36743
36761
  try {
36744
36762
  const row = JSON.parse(readFileSync11(path, "utf8"));
36745
36763
  if (typeof row.checkedAt !== "number" || !row.notice || now - row.checkedAt > CACHE_TTL_MS) return void 0;
@@ -36907,9 +36925,9 @@ function buildSessionBrief(snapshot, current, hub, ship, updateLatest, cost, ses
36907
36925
  };
36908
36926
  }
36909
36927
  function readCachedSessionBrief(stateDir) {
36910
- const file = join12(stateDir, "session-brief.json");
36928
+ const file = join13(stateDir, "session-brief.json");
36911
36929
  try {
36912
- if (!existsSync8(file)) return void 0;
36930
+ if (!existsSync9(file)) return void 0;
36913
36931
  const raw = readFileSync12(file, "utf8");
36914
36932
  const parsed = JSON.parse(raw);
36915
36933
  if (parsed && parsed.schema === "kxm.session-brief.v1" && typeof parsed.generatedAt === "string") {
@@ -36926,7 +36944,7 @@ function readCachedSessionBrief(stateDir) {
36926
36944
  function writeCachedSessionBrief(stateDir, brief) {
36927
36945
  try {
36928
36946
  mkdirSync8(stateDir, { recursive: true, mode: 448 });
36929
- const file = join12(stateDir, "session-brief.json");
36947
+ const file = join13(stateDir, "session-brief.json");
36930
36948
  const tmp = `${file}.tmp.${randomUUID().slice(0, 8)}`;
36931
36949
  writeFileSync6(tmp, JSON.stringify(brief, null, 2), { encoding: "utf8", mode: 384 });
36932
36950
  renameSync4(tmp, file);
@@ -36935,8 +36953,8 @@ function writeCachedSessionBrief(stateDir, brief) {
36935
36953
  }
36936
36954
  function estimateSessionCost(stateDir) {
36937
36955
  try {
36938
- const telemetryFile = join12(stateDir, "telemetry.jsonl");
36939
- if (!existsSync8(telemetryFile)) return void 0;
36956
+ const telemetryFile = join13(stateDir, "telemetry.jsonl");
36957
+ if (!existsSync9(telemetryFile)) return void 0;
36940
36958
  const records = readRoutingRecords(telemetryFile);
36941
36959
  if (records.length === 0) return void 0;
36942
36960
  let totalCost = 0;
@@ -37111,11 +37129,11 @@ function kxmSlashCompletions(prefix) {
37111
37129
  }
37112
37130
 
37113
37131
  // plugins/kxm/src/workflow-tui.ts
37114
- import { existsSync as existsSync9, readFileSync as readFileSync13 } from "node:fs";
37115
- import { join as join13 } from "node:path";
37132
+ import { existsSync as existsSync10, readFileSync as readFileSync13 } from "node:fs";
37133
+ import { join as join14 } from "node:path";
37116
37134
  function loadActiveWorkflowProgress(repoRoot = process.cwd(), targetRunId) {
37117
- const dbPath = join13(repoConfigDirectory(repoRoot), "state", "kxm.db");
37118
- if (!existsSync9(dbPath)) return void 0;
37135
+ const dbPath = join14(repoConfigDirectory(repoRoot), "state", "kxm.db");
37136
+ if (!existsSync10(dbPath)) return void 0;
37119
37137
  let db;
37120
37138
  try {
37121
37139
  db = new DatabaseSync(dbPath, { readOnly: true });
@@ -37150,9 +37168,9 @@ function loadActiveWorkflowProgress(repoRoot = process.cwd(), targetRunId) {
37150
37168
  }
37151
37169
  let metrics;
37152
37170
  try {
37153
- const logsDir = join13(repoConfigDirectory(repoRoot), "logs");
37171
+ const logsDir = join14(repoConfigDirectory(repoRoot), "logs");
37154
37172
  const telemFile = telemetryPath(logsDir);
37155
- if (existsSync9(telemFile)) {
37173
+ if (existsSync10(telemFile)) {
37156
37174
  const records = readRoutingRecords(telemFile);
37157
37175
  const routingRunId = (routing) => "runId" in routing ? routing.runId : routing.workflowRunId;
37158
37176
  let matching = records.filter((r) => routingRunId(r.routing) === runId);
@@ -37413,12 +37431,12 @@ function piMeshExtension(pi) {
37413
37431
  let currentSessionBinding = { kind: "default" };
37414
37432
  function recoveryContextPath() {
37415
37433
  if (!stateDir || !agentName || !projectName) return void 0;
37416
- return join14(stateDir, `worker-context-${workerStateKey(projectName, agentName)}.json`);
37434
+ return join15(stateDir, `worker-context-${workerStateKey(projectName, agentName)}.json`);
37417
37435
  }
37418
37436
  function sessionRouteRequestPath() {
37419
37437
  const workerKey = process.env.KXM_WORKER_IDENTITY_KEY?.trim();
37420
37438
  if (!stateDir || !workerKey) return void 0;
37421
- return join14(stateDir, `worker-session-request-${workerKey}.json`);
37439
+ return join15(stateDir, `worker-session-request-${workerKey}.json`);
37422
37440
  }
37423
37441
  function requestSessionRoute(message, target) {
37424
37442
  if (process.env.KXM_WORKER_SESSION_ISOLATION !== "workflow" || sameBinding(currentSessionBinding, target)) {
@@ -37453,7 +37471,7 @@ function piMeshExtension(pi) {
37453
37471
  }
37454
37472
  function removeMatchingLegacyRecoveryContext() {
37455
37473
  if (!stateDir || !agentName || !projectName) return;
37456
- const legacy = join14(stateDir, `worker-context-${agentName.replace(/[^A-Za-z0-9_.-]/g, "_")}.json`);
37474
+ const legacy = join15(stateDir, `worker-context-${agentName.replace(/[^A-Za-z0-9_.-]/g, "_")}.json`);
37457
37475
  if (legacy === recoveryContextPath()) return;
37458
37476
  try {
37459
37477
  const candidate = JSON.parse(readFileSync14(legacy, "utf8"));
@@ -38063,8 +38081,8 @@ function piMeshExtension(pi) {
38063
38081
  const res = spawnSync2(kxmBin, ["memory", "brief"], { cwd, encoding: "utf8", windowsHide: true });
38064
38082
  let memText = res.status === 0 && res.stdout ? res.stdout.trim() : "";
38065
38083
  if (!memText) {
38066
- const script = join14(cwd, "scripts", "kxm.mjs");
38067
- if (existsSync10(script)) {
38084
+ const script = join15(cwd, "scripts", "kxm.mjs");
38085
+ if (existsSync11(script)) {
38068
38086
  const scriptRes = spawnSync2(process.execPath, [script, "memory", "brief"], { cwd, encoding: "utf8", windowsHide: true });
38069
38087
  if (scriptRes.status === 0 && scriptRes.stdout) memText = scriptRes.stdout.trim();
38070
38088
  }
@@ -16054,7 +16054,7 @@ var HubClient = class {
16054
16054
  while (!this.stopped && this.agent) {
16055
16055
  this.eventsAbort = new AbortController();
16056
16056
  try {
16057
- const response = await fetch(
16057
+ const response = await (this.options.fetchImpl ?? fetch)(
16058
16058
  `${this.options.serverUrl.replace(/\/$/, "")}/v1/events?agentId=${encodeURIComponent(this.agent.id)}`,
16059
16059
  {
16060
16060
  headers: this.headers(),
@@ -16131,7 +16131,7 @@ var HubClient = class {
16131
16131
  const signal = init.signal ? AbortSignal.any([init.signal, timeoutSignal]) : timeoutSignal;
16132
16132
  let response;
16133
16133
  try {
16134
- response = await fetch(`${this.options.serverUrl.replace(/\/$/, "")}${path}`, {
16134
+ response = await (this.options.fetchImpl ?? fetch)(`${this.options.serverUrl.replace(/\/$/, "")}${path}`, {
16135
16135
  ...init,
16136
16136
  signal,
16137
16137
  headers: { ...this.headers(includeIdentity), ...init.headers ?? {} }
@@ -17047,7 +17047,7 @@ async function deliverInboxNotification(messageId, delivered, notify) {
17047
17047
  }
17048
17048
 
17049
17049
  // plugins/kxm/src/mcp-server.ts
17050
- var VERSION = "0.7.20";
17050
+ var VERSION = "0.7.22";
17051
17051
  var inbox = /* @__PURE__ */ new Map();
17052
17052
  var notifiedInbox = /* @__PURE__ */ new Set();
17053
17053
  var meshClient;