@massa-ai/tools-api 1.36.0 → 1.38.0

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.
Files changed (2) hide show
  1. package/dist/index.js +364 -273
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1263,7 +1263,8 @@ var init_config = __esm(() => {
1263
1263
  },
1264
1264
  logging: {
1265
1265
  level: process.env.LOG_LEVEL || fileConfig.logging?.level || "info",
1266
- enableMetrics: process.env.ENABLE_METRICS === "true" || process.env.ENABLE_METRICS === undefined && !!fileConfig.logging?.enableMetrics
1266
+ enableMetrics: process.env.ENABLE_METRICS === "true" || process.env.ENABLE_METRICS === undefined && !!fileConfig.logging?.enableMetrics,
1267
+ file: process.env.MASSA_AI_LOG_FILE || fileConfig.logging?.file || undefined
1267
1268
  },
1268
1269
  synapse: {
1269
1270
  enabled: process.env.SYNAPSE_ENABLED !== "false",
@@ -6602,20 +6603,25 @@ var init_types = __esm(() => {
6602
6603
  var init_interfaces = () => {};
6603
6604
 
6604
6605
  // ../../packages/shared/dist/utils/logger.js
6606
+ import fs3 from "fs";
6607
+
6605
6608
  class Logger {
6606
6609
  _level;
6607
6610
  _enableMetrics;
6611
+ _logFilePath;
6608
6612
  _initialized = false;
6609
6613
  constructor() {}
6610
6614
  ensureInitialized() {
6611
6615
  if (!this._initialized) {
6612
6616
  try {
6613
- const configLevel = config.get("logging").level;
6614
- this._level = this.parseLogLevel(configLevel);
6615
- this._enableMetrics = config.get("logging").enableMetrics;
6617
+ const loggingConfig = config.get("logging");
6618
+ this._level = this.parseLogLevel(loggingConfig.level);
6619
+ this._enableMetrics = loggingConfig.enableMetrics;
6620
+ this._logFilePath = loggingConfig.file;
6616
6621
  } catch {
6617
6622
  this._level = LogLevel.INFO;
6618
6623
  this._enableMetrics = false;
6624
+ this._logFilePath = undefined;
6619
6625
  }
6620
6626
  this._initialized = true;
6621
6627
  }
@@ -6628,6 +6634,10 @@ class Logger {
6628
6634
  this.ensureInitialized();
6629
6635
  return this._enableMetrics;
6630
6636
  }
6637
+ get logFilePath() {
6638
+ this.ensureInitialized();
6639
+ return this._logFilePath;
6640
+ }
6631
6641
  parseLogLevel(level) {
6632
6642
  const levels = {
6633
6643
  debug: LogLevel.DEBUG,
@@ -6647,6 +6657,13 @@ class Logger {
6647
6657
  }
6648
6658
  write(message, _level) {
6649
6659
  console.error(message);
6660
+ const filePath = this.logFilePath;
6661
+ if (filePath) {
6662
+ try {
6663
+ fs3.appendFileSync(filePath, message + `
6664
+ `);
6665
+ } catch {}
6666
+ }
6650
6667
  }
6651
6668
  debug(message, meta) {
6652
6669
  if (this.shouldLog(LogLevel.DEBUG)) {
@@ -7056,7 +7073,7 @@ var init_hosts = __esm(() => {
7056
7073
  });
7057
7074
 
7058
7075
  // ../../packages/shared/dist/profile-switch/state.js
7059
- import fs3 from "fs";
7076
+ import fs4 from "fs";
7060
7077
  import path7 from "path";
7061
7078
  function namedError(name, message) {
7062
7079
  const err = new InstallStateError(message);
@@ -7083,7 +7100,7 @@ function validateShape(raw2, filePath) {
7083
7100
  function readInstallState(filePath) {
7084
7101
  let text;
7085
7102
  try {
7086
- text = fs3.readFileSync(filePath, "utf-8");
7103
+ text = fs4.readFileSync(filePath, "utf-8");
7087
7104
  } catch (err) {
7088
7105
  const code = err.code;
7089
7106
  if (code === "ENOENT")
@@ -7103,8 +7120,8 @@ function writeInstallState(filePath, state) {
7103
7120
  const text = `${JSON.stringify(validated, null, 2)}
7104
7121
  `;
7105
7122
  try {
7106
- fs3.mkdirSync(path7.dirname(filePath), { recursive: true });
7107
- fs3.writeFileSync(filePath, text);
7123
+ fs4.mkdirSync(path7.dirname(filePath), { recursive: true });
7124
+ fs4.writeFileSync(filePath, text);
7108
7125
  } catch (err) {
7109
7126
  throw UnwritableInstallStateError(filePath, err.message);
7110
7127
  }
@@ -7131,7 +7148,7 @@ var init_state = __esm(() => {
7131
7148
  });
7132
7149
 
7133
7150
  // ../../packages/shared/dist/profile-switch/lock.js
7134
- import fs4 from "fs";
7151
+ import fs5 from "fs";
7135
7152
  import path8 from "path";
7136
7153
  import os4 from "os";
7137
7154
  import crypto4 from "crypto";
@@ -7144,7 +7161,7 @@ function namedError2(name, message) {
7144
7161
  function readOwner(ownerPath) {
7145
7162
  let raw2;
7146
7163
  try {
7147
- raw2 = JSON.parse(fs4.readFileSync(ownerPath, "utf-8"));
7164
+ raw2 = JSON.parse(fs5.readFileSync(ownerPath, "utf-8"));
7148
7165
  } catch {
7149
7166
  return null;
7150
7167
  }
@@ -7160,7 +7177,7 @@ function releaseIfOwned(lockDir, ownerPath, token) {
7160
7177
  const owner = readOwner(ownerPath);
7161
7178
  if (owner === null || owner.token !== token)
7162
7179
  return;
7163
- fs4.rmSync(lockDir, { recursive: true, force: true });
7180
+ fs5.rmSync(lockDir, { recursive: true, force: true });
7164
7181
  }
7165
7182
  function acquireLock(stateFilePath, options = {}) {
7166
7183
  const lockDir = `${stateFilePath}.switch.lock`;
@@ -7169,11 +7186,11 @@ function acquireLock(stateFilePath, options = {}) {
7169
7186
  const identity = options.identity ?? DEFAULT_IDENTITY;
7170
7187
  const staleAfterMs = options.staleAfterMs ?? DEFAULT_STALE_AFTER_MS;
7171
7188
  const createFresh = () => {
7172
- fs4.mkdirSync(lockDir);
7189
+ fs5.mkdirSync(lockDir);
7173
7190
  const pid = identity.pid();
7174
7191
  const startedAt = identity.processStart(pid);
7175
7192
  if (startedAt == null) {
7176
- fs4.rmSync(lockDir, { recursive: true, force: true });
7193
+ fs5.rmSync(lockDir, { recursive: true, force: true });
7177
7194
  throw LockAcquireError(lockDir, "could not determine this process's start-time identity");
7178
7195
  }
7179
7196
  const token = crypto4.randomUUID();
@@ -7184,8 +7201,8 @@ function acquireLock(stateFilePath, options = {}) {
7184
7201
  token,
7185
7202
  timestamp: clock.now()
7186
7203
  };
7187
- fs4.mkdirSync(path8.dirname(ownerPath), { recursive: true });
7188
- fs4.writeFileSync(ownerPath, JSON.stringify(record));
7204
+ fs5.mkdirSync(path8.dirname(ownerPath), { recursive: true });
7205
+ fs5.writeFileSync(ownerPath, JSON.stringify(record));
7189
7206
  return { lockDir, release: () => releaseIfOwned(lockDir, ownerPath, token) };
7190
7207
  };
7191
7208
  try {
@@ -7200,11 +7217,11 @@ function acquireLock(stateFilePath, options = {}) {
7200
7217
  throw LockHeldError(lockDir);
7201
7218
  const reclaimDir = `${lockDir}.reclaim.${owner.token}`;
7202
7219
  try {
7203
- fs4.renameSync(lockDir, reclaimDir);
7220
+ fs5.renameSync(lockDir, reclaimDir);
7204
7221
  } catch {
7205
7222
  throw LockHeldError(lockDir);
7206
7223
  }
7207
- fs4.rmSync(reclaimDir, { recursive: true, force: true });
7224
+ fs5.rmSync(reclaimDir, { recursive: true, force: true });
7208
7225
  try {
7209
7226
  return createFresh();
7210
7227
  } catch {
@@ -7238,7 +7255,7 @@ var init_lock = __esm(() => {
7238
7255
  });
7239
7256
 
7240
7257
  // ../../packages/shared/dist/profile-switch/engine.js
7241
- import fs5 from "fs";
7258
+ import fs6 from "fs";
7242
7259
  import path9 from "path";
7243
7260
  import os5 from "os";
7244
7261
  import crypto5 from "crypto";
@@ -7272,7 +7289,7 @@ function listProfiles(opts = {}) {
7272
7289
  availableProfiles: []
7273
7290
  };
7274
7291
  }
7275
- const installed = fs5.existsSync(layout.activeDir);
7292
+ const installed = fs6.existsSync(layout.activeDir);
7276
7293
  const availableProfiles = listVariantProfiles(layout);
7277
7294
  const platform = state.platforms[host];
7278
7295
  return {
@@ -7288,9 +7305,9 @@ function listProfiles(opts = {}) {
7288
7305
  return { hosts };
7289
7306
  }
7290
7307
  function listVariantProfiles(layout) {
7291
- if (!fs5.existsSync(layout.variantsRoot))
7308
+ if (!fs6.existsSync(layout.variantsRoot))
7292
7309
  return [];
7293
- return fs5.readdirSync(layout.variantsRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
7310
+ return fs6.readdirSync(layout.variantsRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort();
7294
7311
  }
7295
7312
  function matchesGlob(filename, glob) {
7296
7313
  const starIdx = glob.indexOf("*");
@@ -7303,32 +7320,32 @@ function matchesGlob(filename, glob) {
7303
7320
  function assertStateWritable(stateFilePath) {
7304
7321
  const dir = path9.dirname(stateFilePath);
7305
7322
  try {
7306
- fs5.mkdirSync(dir, { recursive: true });
7323
+ fs6.mkdirSync(dir, { recursive: true });
7307
7324
  } catch (err) {
7308
7325
  throw UnwritableInstallStateError(stateFilePath, err.message);
7309
7326
  }
7310
- const checkPath = fs5.existsSync(stateFilePath) ? stateFilePath : dir;
7327
+ const checkPath = fs6.existsSync(stateFilePath) ? stateFilePath : dir;
7311
7328
  try {
7312
- fs5.accessSync(checkPath, fs5.constants.W_OK);
7329
+ fs6.accessSync(checkPath, fs6.constants.W_OK);
7313
7330
  } catch (err) {
7314
7331
  throw UnwritableInstallStateError(stateFilePath, err.message);
7315
7332
  }
7316
7333
  }
7317
7334
  function copyFileRouteVariant(layout, variantDir) {
7318
- fs5.mkdirSync(layout.activeDir, { recursive: true });
7335
+ fs6.mkdirSync(layout.activeDir, { recursive: true });
7319
7336
  let changed = 0;
7320
- for (const entry of fs5.readdirSync(variantDir, { withFileTypes: true })) {
7337
+ for (const entry of fs6.readdirSync(variantDir, { withFileTypes: true })) {
7321
7338
  if (!entry.isFile() || !matchesGlob(entry.name, layout.activeGlob))
7322
7339
  continue;
7323
- fs5.copyFileSync(path9.join(variantDir, entry.name), path9.join(layout.activeDir, entry.name));
7340
+ fs6.copyFileSync(path9.join(variantDir, entry.name), path9.join(layout.activeDir, entry.name));
7324
7341
  changed++;
7325
7342
  }
7326
7343
  return changed;
7327
7344
  }
7328
7345
  function repointOpencodeVariant(layout, variantDir) {
7329
- fs5.mkdirSync(layout.activeDir, { recursive: true });
7346
+ fs6.mkdirSync(layout.activeDir, { recursive: true });
7330
7347
  let changed = 0;
7331
- for (const entry of fs5.readdirSync(variantDir, { withFileTypes: true })) {
7348
+ for (const entry of fs6.readdirSync(variantDir, { withFileTypes: true })) {
7332
7349
  if (!entry.isFile() || !matchesGlob(entry.name, layout.activeGlob))
7333
7350
  continue;
7334
7351
  const dest = path9.join(layout.activeDir, entry.name);
@@ -7336,15 +7353,15 @@ function repointOpencodeVariant(layout, variantDir) {
7336
7353
  let destExists = true;
7337
7354
  let destIsSymlink = false;
7338
7355
  try {
7339
- destIsSymlink = fs5.lstatSync(dest).isSymbolicLink();
7356
+ destIsSymlink = fs6.lstatSync(dest).isSymbolicLink();
7340
7357
  } catch {
7341
7358
  destExists = false;
7342
7359
  }
7343
7360
  if (destExists && !destIsSymlink)
7344
7361
  continue;
7345
7362
  const tmp = `${dest}.massa-ai-switch.${crypto5.randomUUID()}`;
7346
- fs5.symlinkSync(target, tmp);
7347
- fs5.renameSync(tmp, dest);
7363
+ fs6.symlinkSync(target, tmp);
7364
+ fs6.renameSync(tmp, dest);
7348
7365
  changed++;
7349
7366
  }
7350
7367
  return changed;
@@ -7366,13 +7383,13 @@ function switchProfile(opts) {
7366
7383
  if (fileHosts.length === 0) {
7367
7384
  return { profile: opts.profile, dryRun, hosts: orderRows(universe, skipRows), restartRequired: false };
7368
7385
  }
7369
- const installedFileHosts = fileHosts.filter((h) => fs5.existsSync(h.layout.activeDir));
7386
+ const installedFileHosts = fileHosts.filter((h) => fs6.existsSync(h.layout.activeDir));
7370
7387
  if (installedFileHosts.length === 0)
7371
7388
  throw NoHostsDetectedError();
7372
7389
  const withAvailability = fileHosts.map((h) => {
7373
- const variantsRootExists = fs5.existsSync(h.layout.variantsRoot);
7390
+ const variantsRootExists = fs6.existsSync(h.layout.variantsRoot);
7374
7391
  const variantDir = h.layout.variantDir(opts.profile);
7375
- const available = variantsRootExists && fs5.existsSync(variantDir) && fs5.statSync(variantDir).isDirectory();
7392
+ const available = variantsRootExists && fs6.existsSync(variantDir) && fs6.statSync(variantDir).isDirectory();
7376
7393
  return { ...h, variantsRootExists, variantDir, available };
7377
7394
  });
7378
7395
  if (!withAvailability.some((h) => h.available)) {
@@ -11580,8 +11597,8 @@ var init_esm4 = __esm(() => {
11580
11597
  #children;
11581
11598
  nocase;
11582
11599
  #fs;
11583
- constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs: fs6 = defaultFS } = {}) {
11584
- this.#fs = fsFromOption(fs6);
11600
+ constructor(cwd = process.cwd(), pathImpl, sep2, { nocase, childrenCacheSize = 16 * 1024, fs: fs7 = defaultFS } = {}) {
11601
+ this.#fs = fsFromOption(fs7);
11585
11602
  if (cwd instanceof URL || cwd.startsWith("file://")) {
11586
11603
  cwd = fileURLToPath(cwd);
11587
11604
  }
@@ -12056,8 +12073,8 @@ var init_esm4 = __esm(() => {
12056
12073
  parseRootPath(dir) {
12057
12074
  return win32.parse(dir).root.toUpperCase();
12058
12075
  }
12059
- newRoot(fs6) {
12060
- return new PathWin32(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs: fs6 });
12076
+ newRoot(fs7) {
12077
+ return new PathWin32(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs: fs7 });
12061
12078
  }
12062
12079
  isAbsolute(p) {
12063
12080
  return p.startsWith("/") || p.startsWith("\\") || /^[a-z]:(\/|\\)/i.test(p);
@@ -12073,8 +12090,8 @@ var init_esm4 = __esm(() => {
12073
12090
  parseRootPath(_dir) {
12074
12091
  return "/";
12075
12092
  }
12076
- newRoot(fs6) {
12077
- return new PathPosix(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs: fs6 });
12093
+ newRoot(fs7) {
12094
+ return new PathPosix(this.rootPath, IFDIR, undefined, this.roots, this.nocase, this.childrenCache(), { fs: fs7 });
12078
12095
  }
12079
12096
  isAbsolute(p) {
12080
12097
  return p.startsWith("/");
@@ -13480,7 +13497,7 @@ var init_capture_policy = __esm(() => {
13480
13497
  });
13481
13498
 
13482
13499
  // ../../packages/core/dist/services/search/ignore-patterns.js
13483
- import fs6 from "fs/promises";
13500
+ import fs7 from "fs/promises";
13484
13501
  import path11 from "path";
13485
13502
  function buildExtensionGlob(extensions2) {
13486
13503
  return extensions2.map((ext2) => `**/*${ext2}`);
@@ -13505,7 +13522,7 @@ async function loadProjectIgnore(projectPath) {
13505
13522
  ig.add(DEFAULT_IGNORES);
13506
13523
  try {
13507
13524
  const gitignorePath = path11.join(projectPath, ".gitignore");
13508
- const gitignoreContent = await fs6.readFile(gitignorePath, "utf8");
13525
+ const gitignoreContent = await fs7.readFile(gitignorePath, "utf8");
13509
13526
  const rules = gitignoreContent.split(`
13510
13527
  `).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
13511
13528
  ig.add(rules);
@@ -13587,6 +13604,89 @@ var init_db_connection = __esm(() => {
13587
13604
  init_config();
13588
13605
  });
13589
13606
 
13607
+ // ../../packages/core/dist/kernel/sanitize/credential-scrub.js
13608
+ function markerFor(id) {
13609
+ return `[REDACTED:${id}]`;
13610
+ }
13611
+ function fullMatchRule(id, pattern) {
13612
+ const marker = markerFor(id);
13613
+ return {
13614
+ id,
13615
+ replace(text) {
13616
+ let count = 0;
13617
+ const replaced = text.replace(pattern, () => {
13618
+ count++;
13619
+ return marker;
13620
+ });
13621
+ return { text: replaced, count };
13622
+ }
13623
+ };
13624
+ }
13625
+ function scrubCredentials(payloadJson) {
13626
+ const redactions = {};
13627
+ for (const id of RULE_IDS)
13628
+ redactions[id] = 0;
13629
+ let text = payloadJson;
13630
+ for (const rule of RULES) {
13631
+ const { text: next, count } = rule.replace(text);
13632
+ text = next;
13633
+ redactions[rule.id] += count;
13634
+ }
13635
+ const total = Object.values(redactions).reduce((sum, n2) => sum + n2, 0);
13636
+ return {
13637
+ sanitized: text,
13638
+ redactions,
13639
+ total
13640
+ };
13641
+ }
13642
+ var PEM_PATTERN, JWT_PATTERN, AWS_KEY_PATTERN, SK_KEY_PATTERN, GITHUB_TOKEN_PATTERN, SLACK_TOKEN_PATTERN, BEARER_PATTERN, RULES, RULE_IDS;
13643
+ var init_credential_scrub = __esm(() => {
13644
+ PEM_PATTERN = /-----BEGIN [A-Z ]{0,32}PRIVATE KEY-----[\s\S]{0,8192}?-----END [A-Z ]{0,32}PRIVATE KEY-----/g;
13645
+ JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
13646
+ AWS_KEY_PATTERN = /\b(?:AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}\b/g;
13647
+ SK_KEY_PATTERN = /\bsk-[A-Za-z0-9_-]{20,}\b/g;
13648
+ GITHUB_TOKEN_PATTERN = /\bgh[pousr]_[A-Za-z0-9]{36,}\b|\bgithub_pat_[A-Za-z0-9_]{22,}\b/g;
13649
+ SLACK_TOKEN_PATTERN = /\bxox[baprs]-[A-Za-z0-9-]{18,}\b/g;
13650
+ BEARER_PATTERN = /(Bearer\s+)([A-Za-z0-9._~+/=-]{20,})/g;
13651
+ RULES = [
13652
+ fullMatchRule("pem", PEM_PATTERN),
13653
+ fullMatchRule("jwt", JWT_PATTERN),
13654
+ fullMatchRule("aws-key", AWS_KEY_PATTERN),
13655
+ fullMatchRule("sk-key", SK_KEY_PATTERN),
13656
+ fullMatchRule("github-token", GITHUB_TOKEN_PATTERN),
13657
+ fullMatchRule("slack-token", SLACK_TOKEN_PATTERN),
13658
+ {
13659
+ id: "bearer",
13660
+ replace(text) {
13661
+ let count = 0;
13662
+ const replaced = text.replace(BEARER_PATTERN, (_m, prefix) => {
13663
+ count++;
13664
+ return `${prefix}${markerFor("bearer")}`;
13665
+ });
13666
+ return { text: replaced, count };
13667
+ }
13668
+ }
13669
+ ];
13670
+ RULE_IDS = RULES.map((r2) => r2.id);
13671
+ });
13672
+
13673
+ // ../../packages/core/dist/kernel/sanitize/safe-error-summary.js
13674
+ function safeErrorSummary(error) {
13675
+ if (error instanceof Error) {
13676
+ return {
13677
+ name: error.name,
13678
+ message: scrubCredentials(error.message).sanitized
13679
+ };
13680
+ }
13681
+ return {
13682
+ name: "UnknownError",
13683
+ message: scrubCredentials(String(error)).sanitized
13684
+ };
13685
+ }
13686
+ var init_safe_error_summary = __esm(() => {
13687
+ init_credential_scrub();
13688
+ });
13689
+
13590
13690
  // ../../packages/core/dist/kernel/alias-resolver.js
13591
13691
  class ProjectIdentityAliasResolver {
13592
13692
  ttlMs;
@@ -13612,9 +13712,7 @@ class ProjectIdentityAliasResolver {
13612
13712
  this.cache.set(projectId, { canonical, expiresAt: this.now() + this.ttlMs });
13613
13713
  return canonical;
13614
13714
  } catch (error) {
13615
- logger.warn("[project-identity] alias resolution failed; using original id (sanitized)", {
13616
- name: error instanceof Error ? error.name : "unknown"
13617
- });
13715
+ logger.warn("[project-identity] alias resolution failed; using original id", safeErrorSummary(error));
13618
13716
  return projectId;
13619
13717
  }
13620
13718
  }
@@ -13671,10 +13769,11 @@ var DEFAULT_TTL_MS = 30000, DEFAULT_RESOLVE_TIMEOUT_MS = 250, sharedResolver = n
13671
13769
  var init_alias_resolver = __esm(() => {
13672
13770
  init_dist();
13673
13771
  init_db_connection();
13772
+ init_safe_error_summary();
13674
13773
  });
13675
13774
 
13676
13775
  // ../../packages/core/dist/services/search/index-manager.js
13677
- import fs7 from "fs";
13776
+ import fs8 from "fs";
13678
13777
  import path12 from "path";
13679
13778
 
13680
13779
  class IndexManager {
@@ -13770,7 +13869,7 @@ class IndexManager {
13770
13869
  for (const filePath of indexedFiles) {
13771
13870
  const fullPath = path12.join(projectPath, filePath);
13772
13871
  try {
13773
- const stat2 = await fs7.promises.stat(fullPath);
13872
+ const stat2 = await fs8.promises.stat(fullPath);
13774
13873
  fileMetadata[filePath] = {
13775
13874
  path: filePath,
13776
13875
  mtime: stat2.mtimeMs,
@@ -13823,7 +13922,7 @@ class IndexManager {
13823
13922
  }
13824
13923
  const fullPath = path12.join(projectPath, match2);
13825
13924
  try {
13826
- const stat2 = await fs7.promises.stat(fullPath);
13925
+ const stat2 = await fs8.promises.stat(fullPath);
13827
13926
  files.set(match2, {
13828
13927
  path: match2,
13829
13928
  mtime: stat2.mtimeMs,
@@ -35514,7 +35613,7 @@ var require_auth_config = __commonJS((exports, module) => {
35514
35613
  writeAuthConfig: () => writeAuthConfig
35515
35614
  });
35516
35615
  module.exports = __toCommonJS2(auth_config_exports);
35517
- var fs8 = __toESM2(__require("fs"));
35616
+ var fs9 = __toESM2(__require("fs"));
35518
35617
  var path13 = __toESM2(__require("path"));
35519
35618
  var import_token_util = require_token_util();
35520
35619
  function getAuthConfigPath() {
@@ -35527,10 +35626,10 @@ var require_auth_config = __commonJS((exports, module) => {
35527
35626
  function readAuthConfig() {
35528
35627
  try {
35529
35628
  const authPath = getAuthConfigPath();
35530
- if (!fs8.existsSync(authPath)) {
35629
+ if (!fs9.existsSync(authPath)) {
35531
35630
  return null;
35532
35631
  }
35533
- const content = fs8.readFileSync(authPath, "utf8");
35632
+ const content = fs9.readFileSync(authPath, "utf8");
35534
35633
  if (!content) {
35535
35634
  return null;
35536
35635
  }
@@ -35542,10 +35641,10 @@ var require_auth_config = __commonJS((exports, module) => {
35542
35641
  function writeAuthConfig(config3) {
35543
35642
  const authPath = getAuthConfigPath();
35544
35643
  const authDir = path13.dirname(authPath);
35545
- if (!fs8.existsSync(authDir)) {
35546
- fs8.mkdirSync(authDir, { mode: 504, recursive: true });
35644
+ if (!fs9.existsSync(authDir)) {
35645
+ fs9.mkdirSync(authDir, { mode: 504, recursive: true });
35547
35646
  }
35548
- fs8.writeFileSync(authPath, JSON.stringify(config3, null, 2), { mode: 384 });
35647
+ fs9.writeFileSync(authPath, JSON.stringify(config3, null, 2), { mode: 384 });
35549
35648
  }
35550
35649
  function isValidAccessToken(authConfig, expirationBufferMs = 0) {
35551
35650
  if (!authConfig.token)
@@ -35721,7 +35820,7 @@ var require_token_util = __commonJS((exports, module) => {
35721
35820
  });
35722
35821
  module.exports = __toCommonJS2(token_util_exports);
35723
35822
  var path13 = __toESM2(__require("path"));
35724
- var fs8 = __toESM2(__require("fs"));
35823
+ var fs9 = __toESM2(__require("fs"));
35725
35824
  var import_token_error = require_token_error();
35726
35825
  var import_token_io = require_token_io();
35727
35826
  var import_auth_config = require_auth_config();
@@ -35802,10 +35901,10 @@ var require_token_util = __commonJS((exports, module) => {
35802
35901
  throw new import_token_error.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");
35803
35902
  }
35804
35903
  const prjPath = path13.join(dir, ".vercel", "project.json");
35805
- if (!fs8.existsSync(prjPath)) {
35904
+ if (!fs9.existsSync(prjPath)) {
35806
35905
  throw new import_token_error.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");
35807
35906
  }
35808
- const prj = JSON.parse(fs8.readFileSync(prjPath, "utf8"));
35907
+ const prj = JSON.parse(fs9.readFileSync(prjPath, "utf8"));
35809
35908
  if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") {
35810
35909
  throw new TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");
35811
35910
  }
@@ -35818,9 +35917,9 @@ var require_token_util = __commonJS((exports, module) => {
35818
35917
  }
35819
35918
  const tokenPath = path13.join(dir, "com.vercel.token", `${projectId}.json`);
35820
35919
  const tokenJson = JSON.stringify(token);
35821
- fs8.mkdirSync(path13.dirname(tokenPath), { mode: 504, recursive: true });
35822
- fs8.writeFileSync(tokenPath, tokenJson);
35823
- fs8.chmodSync(tokenPath, 432);
35920
+ fs9.mkdirSync(path13.dirname(tokenPath), { mode: 504, recursive: true });
35921
+ fs9.writeFileSync(tokenPath, tokenJson);
35922
+ fs9.chmodSync(tokenPath, 432);
35824
35923
  return;
35825
35924
  }
35826
35925
  function loadToken(projectId) {
@@ -35829,10 +35928,10 @@ var require_token_util = __commonJS((exports, module) => {
35829
35928
  throw new import_token_error.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");
35830
35929
  }
35831
35930
  const tokenPath = path13.join(dir, "com.vercel.token", `${projectId}.json`);
35832
- if (!fs8.existsSync(tokenPath)) {
35931
+ if (!fs9.existsSync(tokenPath)) {
35833
35932
  return null;
35834
35933
  }
35835
- const token = JSON.parse(fs8.readFileSync(tokenPath, "utf8"));
35934
+ const token = JSON.parse(fs9.readFileSync(tokenPath, "utf8"));
35836
35935
  assertVercelOidcTokenResponse(token);
35837
35936
  return token;
35838
35937
  }
@@ -63262,26 +63361,26 @@ var require_process = __commonJS((exports, module) => {
63262
63361
 
63263
63362
  // ../../node_modules/detect-libc/lib/filesystem.js
63264
63363
  var require_filesystem = __commonJS((exports, module) => {
63265
- var fs8 = __require("fs");
63364
+ var fs9 = __require("fs");
63266
63365
  var LDD_PATH = "/usr/bin/ldd";
63267
63366
  var SELF_PATH = "/proc/self/exe";
63268
63367
  var MAX_LENGTH = 2048;
63269
63368
  var readFileSync2 = (path13) => {
63270
- const fd = fs8.openSync(path13, "r");
63369
+ const fd = fs9.openSync(path13, "r");
63271
63370
  const buffer = Buffer.alloc(MAX_LENGTH);
63272
- const bytesRead = fs8.readSync(fd, buffer, 0, MAX_LENGTH, 0);
63273
- fs8.close(fd, () => {});
63371
+ const bytesRead = fs9.readSync(fd, buffer, 0, MAX_LENGTH, 0);
63372
+ fs9.close(fd, () => {});
63274
63373
  return buffer.subarray(0, bytesRead);
63275
63374
  };
63276
63375
  var readFile = (path13) => new Promise((resolve4, reject) => {
63277
- fs8.open(path13, "r", (err, fd) => {
63376
+ fs9.open(path13, "r", (err, fd) => {
63278
63377
  if (err) {
63279
63378
  reject(err);
63280
63379
  } else {
63281
63380
  const buffer = Buffer.alloc(MAX_LENGTH);
63282
- fs8.read(fd, buffer, 0, MAX_LENGTH, 0, (_2, bytesRead) => {
63381
+ fs9.read(fd, buffer, 0, MAX_LENGTH, 0, (_2, bytesRead) => {
63283
63382
  resolve4(buffer.subarray(0, bytesRead));
63284
- fs8.close(fd, () => {});
63383
+ fs9.close(fd, () => {});
63285
63384
  });
63286
63385
  }
63287
63386
  });
@@ -99944,10 +100043,10 @@ Note that ${s.bold("include")} statements only accept relation fields.`, a12;
99944
100043
  super(t2, "P2023", r2);
99945
100044
  }
99946
100045
  };
99947
- var fs8 = new WeakMap;
100046
+ var fs9 = new WeakMap;
99948
100047
  function Ep(e) {
99949
- let t2 = fs8.get(e);
99950
- return t2 || (t2 = Object.entries(e), fs8.set(e, t2)), t2;
100048
+ let t2 = fs9.get(e);
100049
+ return t2 || (t2 = Object.entries(e), fs9.set(e, t2)), t2;
99951
100050
  }
99952
100051
  function hs(e, t2, r2) {
99953
100052
  switch (t2.type) {
@@ -107114,6 +107213,7 @@ var init_registry = __esm(() => {
107114
107213
  search_analytics: { storeId: "search_analytics", identityColumn: "project_id", mutable: true },
107115
107214
  search_events: { storeId: "search_events", identityColumn: "project_id", mutable: true },
107116
107215
  synapse_sessions: { storeId: "synapse_sessions", identityColumn: "workspace_id", mutable: true },
107216
+ managed_runs: { storeId: "managed_runs", identityColumn: "project_id", mutable: true },
107117
107217
  operation_log: { storeId: "operation_log", identityColumn: "project_id", mutable: false },
107118
107218
  project_identity_operations: {
107119
107219
  storeId: "project_identity_operations",
@@ -113391,6 +113491,89 @@ var init_reranker = __esm(() => {
113391
113491
  });
113392
113492
  });
113393
113493
 
113494
+ // ../../packages/core/dist/kernel/search-diagnostics.js
113495
+ function searchBackendUnavailable(component, cause) {
113496
+ return cause instanceof SearchServiceError ? cause : new SearchServiceError("SEARCH_BACKEND_UNAVAILABLE", component, { cause });
113497
+ }
113498
+ function storeCorruption(component, cause) {
113499
+ return cause instanceof SearchServiceError ? cause : new SearchServiceError("STORE_CORRUPTION", component, {
113500
+ cause,
113501
+ statusCode: 500
113502
+ });
113503
+ }
113504
+ function projectNotIndexed(projectId, message) {
113505
+ return new SearchServiceError("PROJECT_NOT_INDEXED", projectId, {
113506
+ message,
113507
+ statusCode: 404
113508
+ });
113509
+ }
113510
+ function recordSearchDegradation(code, component, projectId) {
113511
+ const degradation = {
113512
+ code,
113513
+ component,
113514
+ message: DEGRADATION_MESSAGES[code]
113515
+ };
113516
+ diagnostics.push({
113517
+ kind: "degradation",
113518
+ ...degradation,
113519
+ projectId,
113520
+ timestamp: new Date().toISOString()
113521
+ });
113522
+ if (diagnostics.length > MAX_DIAGNOSTICS) {
113523
+ diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
113524
+ }
113525
+ return degradation;
113526
+ }
113527
+ function recordSearchFailure(error51, projectId) {
113528
+ if (recordedFailures.has(error51))
113529
+ return;
113530
+ recordedFailures.add(error51);
113531
+ diagnostics.push({
113532
+ kind: "failure",
113533
+ code: error51.code,
113534
+ component: error51.component,
113535
+ message: error51.message,
113536
+ projectId,
113537
+ timestamp: new Date().toISOString()
113538
+ });
113539
+ if (diagnostics.length > MAX_DIAGNOSTICS) {
113540
+ diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
113541
+ }
113542
+ }
113543
+ function getSearchDiagnostics() {
113544
+ return diagnostics.map((diagnostic) => ({ ...diagnostic }));
113545
+ }
113546
+ function resetSearchDiagnosticsForTests() {
113547
+ diagnostics.length = 0;
113548
+ }
113549
+ var MAX_DIAGNOSTICS = 100, diagnostics, recordedFailures, DEGRADATION_MESSAGES, SearchServiceError;
113550
+ var init_search_diagnostics = __esm(() => {
113551
+ diagnostics = [];
113552
+ recordedFailures = new WeakSet;
113553
+ DEGRADATION_MESSAGES = {
113554
+ QUERY_UNDERSTANDING_UNAVAILABLE: "Query understanding was unavailable; original query used",
113555
+ TRIGRAM_UNAVAILABLE: "Trigram enrichment was unavailable",
113556
+ FUZZY_SEARCH_UNAVAILABLE: "Fuzzy enrichment was unavailable",
113557
+ PROXIMITY_RERANK_UNAVAILABLE: "Proximity reranking was unavailable; fused order preserved",
113558
+ GRAPH_AUGMENTATION_UNAVAILABLE: "Graph augmentation was unavailable",
113559
+ SYNAPSE_UNAVAILABLE: "Synapse enrichment was unavailable; stateless results used",
113560
+ SEARCH_AUDIT_UNAVAILABLE: "Search event auditing was unavailable",
113561
+ SEARCH_ANALYTICS_UNAVAILABLE: "Search analytics were unavailable"
113562
+ };
113563
+ SearchServiceError = class SearchServiceError extends Error {
113564
+ code;
113565
+ component;
113566
+ statusCode;
113567
+ constructor(code, component, options) {
113568
+ super(options?.message ?? (code === "STORE_CORRUPTION" ? "Stored data is invalid" : "A required search backend is unavailable"), options?.cause === undefined ? undefined : { cause: options.cause });
113569
+ this.code = code;
113570
+ this.component = component;
113571
+ this.name = "SearchServiceError";
113572
+ this.statusCode = options?.statusCode ?? 503;
113573
+ }
113574
+ };
113575
+ });
113576
+
113394
113577
  // ../../packages/core/dist/kernel/enum-validation.js
113395
113578
  function validateEnum(paramName, value, validValues) {
113396
113579
  if (typeof value !== "string" || !validValues.includes(value)) {
@@ -113499,7 +113682,7 @@ class SearchController {
113499
113682
  });
113500
113683
  const admission = await this.contextualSearch.checkSearchAdmission(projectId, projectPath);
113501
113684
  if (!admission.admitted) {
113502
- throw new Error(admission.error ?? `Project '${projectId}' is not indexed`);
113685
+ throw projectNotIndexed(projectId, admission.error ?? `Project '${projectId}' is not indexed`);
113503
113686
  }
113504
113687
  const staleWarning = admission.stale ?? null;
113505
113688
  let reindexInfo = null;
@@ -113723,6 +113906,7 @@ var init_search_controller = __esm(() => {
113723
113906
  init_contextual_search_rlm();
113724
113907
  init_event_bus();
113725
113908
  init_reranker();
113909
+ init_search_diagnostics();
113726
113910
  init_esm();
113727
113911
  init_filter_validation();
113728
113912
  });
@@ -114208,83 +114392,6 @@ var init_session_bias = __esm(() => {
114208
114392
  init_synapse();
114209
114393
  });
114210
114394
 
114211
- // ../../packages/core/dist/kernel/search-diagnostics.js
114212
- function searchBackendUnavailable(component, cause) {
114213
- return cause instanceof SearchServiceError ? cause : new SearchServiceError("SEARCH_BACKEND_UNAVAILABLE", component, { cause });
114214
- }
114215
- function storeCorruption(component, cause) {
114216
- return cause instanceof SearchServiceError ? cause : new SearchServiceError("STORE_CORRUPTION", component, {
114217
- cause,
114218
- statusCode: 500
114219
- });
114220
- }
114221
- function recordSearchDegradation(code, component, projectId) {
114222
- const degradation = {
114223
- code,
114224
- component,
114225
- message: DEGRADATION_MESSAGES[code]
114226
- };
114227
- diagnostics.push({
114228
- kind: "degradation",
114229
- ...degradation,
114230
- projectId,
114231
- timestamp: new Date().toISOString()
114232
- });
114233
- if (diagnostics.length > MAX_DIAGNOSTICS) {
114234
- diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
114235
- }
114236
- return degradation;
114237
- }
114238
- function recordSearchFailure(error51, projectId) {
114239
- if (recordedFailures.has(error51))
114240
- return;
114241
- recordedFailures.add(error51);
114242
- diagnostics.push({
114243
- kind: "failure",
114244
- code: error51.code,
114245
- component: error51.component,
114246
- message: error51.message,
114247
- projectId,
114248
- timestamp: new Date().toISOString()
114249
- });
114250
- if (diagnostics.length > MAX_DIAGNOSTICS) {
114251
- diagnostics.splice(0, diagnostics.length - MAX_DIAGNOSTICS);
114252
- }
114253
- }
114254
- function getSearchDiagnostics() {
114255
- return diagnostics.map((diagnostic) => ({ ...diagnostic }));
114256
- }
114257
- function resetSearchDiagnosticsForTests() {
114258
- diagnostics.length = 0;
114259
- }
114260
- var MAX_DIAGNOSTICS = 100, diagnostics, recordedFailures, DEGRADATION_MESSAGES, SearchServiceError;
114261
- var init_search_diagnostics = __esm(() => {
114262
- diagnostics = [];
114263
- recordedFailures = new WeakSet;
114264
- DEGRADATION_MESSAGES = {
114265
- QUERY_UNDERSTANDING_UNAVAILABLE: "Query understanding was unavailable; original query used",
114266
- TRIGRAM_UNAVAILABLE: "Trigram enrichment was unavailable",
114267
- FUZZY_SEARCH_UNAVAILABLE: "Fuzzy enrichment was unavailable",
114268
- PROXIMITY_RERANK_UNAVAILABLE: "Proximity reranking was unavailable; fused order preserved",
114269
- GRAPH_AUGMENTATION_UNAVAILABLE: "Graph augmentation was unavailable",
114270
- SYNAPSE_UNAVAILABLE: "Synapse enrichment was unavailable; stateless results used",
114271
- SEARCH_AUDIT_UNAVAILABLE: "Search event auditing was unavailable",
114272
- SEARCH_ANALYTICS_UNAVAILABLE: "Search analytics were unavailable"
114273
- };
114274
- SearchServiceError = class SearchServiceError extends Error {
114275
- code;
114276
- component;
114277
- statusCode;
114278
- constructor(code, component, options) {
114279
- super(code === "STORE_CORRUPTION" ? "Stored data is invalid" : "A required search backend is unavailable", options?.cause === undefined ? undefined : { cause: options.cause });
114280
- this.code = code;
114281
- this.component = component;
114282
- this.name = "SearchServiceError";
114283
- this.statusCode = options?.statusCode ?? 503;
114284
- }
114285
- };
114286
- });
114287
-
114288
114395
  // ../../packages/core/dist/services/search/hybrid-search.js
114289
114396
  async function search(deps, query, projectId, options = {}) {
114290
114397
  const maxResults = options.maxResults ?? 10;
@@ -115641,7 +115748,7 @@ var init_managed_run_repository_pg = __esm(() => {
115641
115748
  });
115642
115749
 
115643
115750
  // ../../packages/core/dist/services/search/project-indexer.js
115644
- import fs8 from "fs/promises";
115751
+ import fs9 from "fs/promises";
115645
115752
  import path14 from "path";
115646
115753
  import { randomUUID as randomUUID3 } from "crypto";
115647
115754
  async function runWithIndexLock(lockMap, projectId, work) {
@@ -115901,7 +116008,7 @@ async function checkSearchAdmission(deps, projectId, projectPath) {
115901
116008
  }
115902
116009
  async function indexFile(deps, filePath, projectId, projectRoot, centralityMap) {
115903
116010
  projectId = await getProjectIdentityAliasResolver().resolve(projectId);
115904
- const content = await fs8.readFile(filePath, "utf-8");
116011
+ const content = await fs9.readFile(filePath, "utf-8");
115905
116012
  const relativePath = path14.relative(projectRoot, filePath);
115906
116013
  const maxFileSize = config.get("security").maxFileSize || 1024 * 1024;
115907
116014
  if (content.length > maxFileSize) {
@@ -116767,7 +116874,7 @@ function stripNul(content) {
116767
116874
  }
116768
116875
 
116769
116876
  // ../../packages/core/dist/services/etl/stages/discover.js
116770
- import fs9 from "fs/promises";
116877
+ import fs10 from "fs/promises";
116771
116878
  import path15 from "path";
116772
116879
  import { createHash as createHash5 } from "crypto";
116773
116880
 
@@ -116855,8 +116962,8 @@ class DiscoverStage {
116855
116962
  async processFile(ctx, relativePath, forceReindex) {
116856
116963
  const absolutePath = path15.join(ctx.projectPath, relativePath);
116857
116964
  try {
116858
- const stat2 = await fs9.stat(absolutePath);
116859
- const content = stripNul(await fs9.readFile(absolutePath, "utf-8"));
116965
+ const stat2 = await fs10.stat(absolutePath);
116966
+ const content = stripNul(await fs10.readFile(absolutePath, "utf-8"));
116860
116967
  const contentHash = createHash5("sha256").update(content).digest("hex");
116861
116968
  let needsReparse = forceReindex;
116862
116969
  if (!forceReindex) {
@@ -116900,7 +117007,7 @@ class DiscoverStage {
116900
117007
  }
116901
117008
  try {
116902
117009
  const gitignorePath = path15.join(projectPath, ".gitignore");
116903
- const gitignoreContent = await fs9.readFile(gitignorePath, "utf8");
117010
+ const gitignoreContent = await fs10.readFile(gitignorePath, "utf8");
116904
117011
  const rules = gitignoreContent.split(`
116905
117012
  `).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
116906
117013
  ig.add(rules);
@@ -119229,7 +119336,7 @@ var init_structural_runtime = __esm(() => {
119229
119336
 
119230
119337
  // ../../packages/core/dist/services/etl/stages/parse.js
119231
119338
  import path16 from "path";
119232
- import fs10 from "fs/promises";
119339
+ import fs11 from "fs/promises";
119233
119340
  function resolveChunkerMaxChars() {
119234
119341
  const global2 = Number(process.env.EMBEDDING_MAX_CHARS);
119235
119342
  if (Number.isFinite(global2) && global2 > 0)
@@ -119321,7 +119428,7 @@ class ParseStage {
119321
119428
  if (!file3.needsReparse) {
119322
119429
  const extension = path16.extname(file3.relativePath).toLowerCase();
119323
119430
  if ([".c", ".cpp", ".hpp"].includes(extension)) {
119324
- const content = file3.snapshotContent ?? await fs10.readFile(file3.absolutePath, "utf8");
119431
+ const content = file3.snapshotContent ?? await fs11.readFile(file3.absolutePath, "utf8");
119325
119432
  const outcome = await this.runtime.parse({ extension, source: Buffer.from(content) });
119326
119433
  if (outcome.status === "failed")
119327
119434
  throw new StructuralEtlParseError(file3.relativePath, outcome.failureKind, `Structural evidence parse failed (${outcome.failureKind})`, outcome.diagnosticCount, outcome.diagnostics.slice(0, 10));
@@ -119333,7 +119440,7 @@ class ParseStage {
119333
119440
  return { file: file3, chunks: [], symbols: [], rawImports: [], rawEdges: [] };
119334
119441
  }
119335
119442
  try {
119336
- const content = file3.snapshotContent ?? await fs10.readFile(file3.absolutePath, "utf-8");
119443
+ const content = file3.snapshotContent ?? await fs11.readFile(file3.absolutePath, "utf-8");
119337
119444
  const ext2 = path16.extname(file3.relativePath).toLowerCase();
119338
119445
  const chunkerMaxChars = resolveChunkerMaxChars();
119339
119446
  const chunks = smartChunk(content, file3.relativePath, chunkerMaxChars ? { maxChunkChars: chunkerMaxChars } : {});
@@ -120374,7 +120481,7 @@ var init_data_document2 = __esm(() => {
120374
120481
 
120375
120482
  // ../../packages/core/dist/services/etl/stages/resolve.js
120376
120483
  import path19 from "path";
120377
- import fs11 from "fs";
120484
+ import fs12 from "fs";
120378
120485
 
120379
120486
  class ResolveStage {
120380
120487
  symbolRepository;
@@ -120691,7 +120798,7 @@ class ResolveStage {
120691
120798
  const aliases = [];
120692
120799
  const tsconfigPath = path19.join(projectPath, "tsconfig.json");
120693
120800
  try {
120694
- const raw2 = fs11.readFileSync(tsconfigPath, "utf-8");
120801
+ const raw2 = fs12.readFileSync(tsconfigPath, "utf-8");
120695
120802
  const stripped = raw2.replace(/\/\/[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
120696
120803
  const tsconfig = JSON.parse(stripped);
120697
120804
  const paths = tsconfig?.compilerOptions?.paths ?? {};
@@ -122987,7 +123094,7 @@ __export(exports_symbol_graph_service, {
122987
123094
  SymbolGraphService: () => SymbolGraphService
122988
123095
  });
122989
123096
  import path23 from "path";
122990
- import fs12 from "fs/promises";
123097
+ import fs13 from "fs/promises";
122991
123098
 
122992
123099
  class SymbolGraphService {
122993
123100
  identityLookup;
@@ -123315,7 +123422,7 @@ class SymbolGraphService {
123315
123422
  async readSnippet(relativePath, lineStart, lineEnd, projectId) {
123316
123423
  try {
123317
123424
  const absolutePath = await this.resolveToAbsolute(relativePath, projectId);
123318
- const content = await fs12.readFile(absolutePath, "utf-8");
123425
+ const content = await fs13.readFile(absolutePath, "utf-8");
123319
123426
  const lines = content.split(`
123320
123427
  `);
123321
123428
  return lines.slice(Math.max(0, lineStart - 1), Math.min(lines.length, lineEnd)).join(`
@@ -123327,7 +123434,7 @@ class SymbolGraphService {
123327
123434
  async readContext(relativePath, lineNumber, contextLines, projectId) {
123328
123435
  try {
123329
123436
  const absolutePath = await this.resolveToAbsolute(relativePath, projectId);
123330
- const content = await fs12.readFile(absolutePath, "utf-8");
123437
+ const content = await fs13.readFile(absolutePath, "utf-8");
123331
123438
  const lines = content.split(`
123332
123439
  `);
123333
123440
  const start = Math.max(0, lineNumber - contextLines - 1);
@@ -126372,6 +126479,10 @@ var init_checkpoint_store_pg = __esm(() => {
126372
126479
  });
126373
126480
 
126374
126481
  // ../../packages/core/dist/services/checkpoint/checkpoint-manager.js
126482
+ var exports_checkpoint_manager = {};
126483
+ __export(exports_checkpoint_manager, {
126484
+ CheckpointManager: () => CheckpointManager
126485
+ });
126375
126486
  var CheckpointManager;
126376
126487
  var init_checkpoint_manager = __esm(() => {
126377
126488
  init_config();
@@ -130496,7 +130607,7 @@ var init_l1_memory_cache = __esm(() => {
130496
130607
  });
130497
130608
 
130498
130609
  // ../../packages/core/dist/services/health/local-health-checker.js
130499
- import fs15 from "fs/promises";
130610
+ import fs16 from "fs/promises";
130500
130611
  import { existsSync as existsSync3 } from "fs";
130501
130612
  import path28 from "path";
130502
130613
 
@@ -130532,10 +130643,10 @@ class LocalHealthChecker {
130532
130643
  const start = Date.now();
130533
130644
  try {
130534
130645
  if (!existsSync3(this.dataDir))
130535
- await fs15.mkdir(this.dataDir, { recursive: true });
130646
+ await fs16.mkdir(this.dataDir, { recursive: true });
130536
130647
  const probe2 = path28.join(this.dataDir, ".health-check-test");
130537
- await fs15.writeFile(probe2, "ok");
130538
- await fs15.unlink(probe2);
130648
+ await fs16.writeFile(probe2, "ok");
130649
+ await fs16.unlink(probe2);
130539
130650
  return { available: true, latency: Date.now() - start, details: { path: this.dataDir, writable: true } };
130540
130651
  } catch (error51) {
130541
130652
  return { available: false, latency: Date.now() - start, error: `Data directory error: ${error51.message}` };
@@ -132370,6 +132481,11 @@ function registerDefaultJobs(scheduler) {
132370
132481
  const projectId = job.payload?.projectId ?? "default";
132371
132482
  await observationConsolidationJob2.runOnce(projectId);
132372
132483
  });
132484
+ scheduler.registerHandler("checkpoint-purge", async () => {
132485
+ const { CheckpointManager: CheckpointManager2 } = await Promise.resolve().then(() => (init_checkpoint_manager(), exports_checkpoint_manager));
132486
+ const count = CheckpointManager2.getInstance().purgeExpired();
132487
+ logger.info("Scheduled checkpoint purge completed", { count });
132488
+ });
132373
132489
  for (const rawDef of DEFAULT_SCHEDULED_JOBS) {
132374
132490
  const def = applySafeDefaults(rawDef);
132375
132491
  const enabled2 = envBool2(def.enableEnvVar, def.defaultEnabled);
@@ -132431,6 +132547,15 @@ var init_scheduler_defaults = __esm(() => {
132431
132547
  defaultEnabled: false,
132432
132548
  enableEnvVar: "MASSA_AI_SCHEDULER_OBSERVATION_BRIDGE_ENABLED",
132433
132549
  intervalEnvVar: "MASSA_AI_SCHEDULER_OBSERVATION_BRIDGE_INTERVAL_MS"
132550
+ },
132551
+ {
132552
+ id: "scheduled-checkpoint-purge",
132553
+ name: "Checkpoint Purge (clock)",
132554
+ jobKind: "checkpoint-purge",
132555
+ schedule: { type: "interval", intervalMs: ONE_HOUR },
132556
+ defaultEnabled: false,
132557
+ enableEnvVar: "MASSA_AI_SCHEDULER_CHECKPOINT_PURGE_ENABLED",
132558
+ intervalEnvVar: "MASSA_AI_SCHEDULER_CHECKPOINT_PURGE_INTERVAL_MS"
132434
132559
  }
132435
132560
  ];
132436
132561
  });
@@ -132445,7 +132570,7 @@ var init_scheduler2 = __esm(() => {
132445
132570
  });
132446
132571
 
132447
132572
  // ../../packages/core/dist/services/pricing/models-dev-client.js
132448
- import fs16 from "fs/promises";
132573
+ import fs17 from "fs/promises";
132449
132574
  import { existsSync as existsSync4 } from "fs";
132450
132575
  import path29 from "path";
132451
132576
  function getModelsDevClient() {
@@ -132475,7 +132600,7 @@ var init_models_dev_client = __esm(() => {
132475
132600
  if (!existsSync4(cachePath)) {
132476
132601
  return null;
132477
132602
  }
132478
- const content = await fs16.readFile(cachePath, "utf-8");
132603
+ const content = await fs17.readFile(cachePath, "utf-8");
132479
132604
  const data = JSON.parse(content);
132480
132605
  const age = Date.now() - data.timestamp;
132481
132606
  if (age > ModelsDevClient.LOCAL_CACHE_TTL) {
@@ -132503,13 +132628,13 @@ var init_models_dev_client = __esm(() => {
132503
132628
  const cachePath = this.getLocalCachePath();
132504
132629
  try {
132505
132630
  const dir = path29.dirname(cachePath);
132506
- await fs16.mkdir(dir, { recursive: true });
132631
+ await fs17.mkdir(dir, { recursive: true });
132507
132632
  const data = {
132508
132633
  timestamp: Date.now(),
132509
132634
  version: "1.0.0",
132510
132635
  models: Object.fromEntries(models)
132511
132636
  };
132512
- await fs16.writeFile(cachePath, JSON.stringify(data), "utf-8");
132637
+ await fs17.writeFile(cachePath, JSON.stringify(data), "utf-8");
132513
132638
  logger.debug("Saved pricing to local cache", {
132514
132639
  models: models.size,
132515
132640
  path: cachePath
@@ -132838,7 +132963,7 @@ var init_models_dev_client = __esm(() => {
132838
132963
  const cachePath = this.getLocalCachePath();
132839
132964
  try {
132840
132965
  if (existsSync4(cachePath)) {
132841
- await fs16.unlink(cachePath);
132966
+ await fs17.unlink(cachePath);
132842
132967
  logger.debug("Local pricing cache file deleted");
132843
132968
  }
132844
132969
  } catch (error51) {
@@ -150856,6 +150981,7 @@ __export(exports_services, {
150856
150981
  selectCompressionCandidates: () => selectCompressionCandidates,
150857
150982
  searchSessionHook: () => searchSessionHook,
150858
150983
  searchBackendUnavailable: () => searchBackendUnavailable,
150984
+ safeErrorSummary: () => safeErrorSummary,
150859
150985
  runPool: () => runPool,
150860
150986
  resolveStructuralParseLanguage: () => resolveStructuralParseLanguage,
150861
150987
  resetSynapseManager: () => resetSynapseManager,
@@ -150870,6 +150996,7 @@ __export(exports_services, {
150870
150996
  recordSearchFailure: () => recordSearchFailure,
150871
150997
  recordSearchDegradation: () => recordSearchDegradation,
150872
150998
  quoteDiscoveredIdentifier: () => quoteDiscoveredIdentifier,
150999
+ projectNotIndexed: () => projectNotIndexed,
150873
151000
  payloadStorePolicies: () => payloadStorePolicies,
150874
151001
  parseStructuralFqn: () => parseStructuralFqn,
150875
151002
  parseProjectIdentityPreviewRequest: () => parseProjectIdentityPreviewRequest,
@@ -151087,6 +151214,7 @@ var init_services = __esm(() => {
151087
151214
  init_search_analytics_pg();
151088
151215
  init_index_manager();
151089
151216
  init_search_diagnostics();
151217
+ init_safe_error_summary();
151090
151218
  init_memory_controller();
151091
151219
  init_llm_client();
151092
151220
  init_search_controller();
@@ -175534,7 +175662,8 @@ init_compaction_snapshot_service();
175534
175662
  init_dist();
175535
175663
  init_db_connection();
175536
175664
  init_alias_resolver();
175537
- import fs13 from "fs";
175665
+ init_safe_error_summary();
175666
+ import fs14 from "fs";
175538
175667
  import os6 from "os";
175539
175668
  import path25 from "path";
175540
175669
 
@@ -175611,9 +175740,7 @@ class PgWorkspaceRootProvider {
175611
175740
  this.cache = { roots, expiresAt: this.now() + PROVIDER_TTL_MS };
175612
175741
  return roots;
175613
175742
  } catch (error51) {
175614
- logger.warn("[hook-attribution] workspace roots lookup failed; containment disabled (sanitized)", {
175615
- name: error51 instanceof Error ? error51.name : "unknown"
175616
- });
175743
+ logger.warn("[hook-attribution] workspace roots lookup failed; containment disabled", safeErrorSummary(error51));
175617
175744
  return [];
175618
175745
  } finally {
175619
175746
  if (timer)
@@ -175722,7 +175849,7 @@ class AttributionResolver {
175722
175849
  }
175723
175850
  function defaultCanonicalize(cwd) {
175724
175851
  try {
175725
- return fs13.realpathSync(cwd);
175852
+ return fs14.realpathSync(cwd);
175726
175853
  } catch {
175727
175854
  try {
175728
175855
  return path25.resolve(cwd);
@@ -175738,70 +175865,9 @@ function getAttributionResolver() {
175738
175865
  return sharedResolver2;
175739
175866
  }
175740
175867
 
175741
- // ../../packages/core/dist/kernel/sanitize/credential-scrub.js
175742
- function markerFor(id) {
175743
- return `[REDACTED:${id}]`;
175744
- }
175745
- function fullMatchRule(id, pattern) {
175746
- const marker26 = markerFor(id);
175747
- return {
175748
- id,
175749
- replace(text3) {
175750
- let count = 0;
175751
- const replaced = text3.replace(pattern, () => {
175752
- count++;
175753
- return marker26;
175754
- });
175755
- return { text: replaced, count };
175756
- }
175757
- };
175758
- }
175759
- var PEM_PATTERN = /-----BEGIN [A-Z ]{0,32}PRIVATE KEY-----[\s\S]{0,8192}?-----END [A-Z ]{0,32}PRIVATE KEY-----/g;
175760
- var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g;
175761
- var AWS_KEY_PATTERN = /\b(?:AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}\b/g;
175762
- var SK_KEY_PATTERN = /\bsk-[A-Za-z0-9_-]{20,}\b/g;
175763
- var GITHUB_TOKEN_PATTERN = /\bgh[pousr]_[A-Za-z0-9]{36,}\b|\bgithub_pat_[A-Za-z0-9_]{22,}\b/g;
175764
- var SLACK_TOKEN_PATTERN = /\bxox[baprs]-[A-Za-z0-9-]{18,}\b/g;
175765
- var BEARER_PATTERN = /(Bearer\s+)([A-Za-z0-9._~+/=-]{20,})/g;
175766
- var RULES = [
175767
- fullMatchRule("pem", PEM_PATTERN),
175768
- fullMatchRule("jwt", JWT_PATTERN),
175769
- fullMatchRule("aws-key", AWS_KEY_PATTERN),
175770
- fullMatchRule("sk-key", SK_KEY_PATTERN),
175771
- fullMatchRule("github-token", GITHUB_TOKEN_PATTERN),
175772
- fullMatchRule("slack-token", SLACK_TOKEN_PATTERN),
175773
- {
175774
- id: "bearer",
175775
- replace(text3) {
175776
- let count = 0;
175777
- const replaced = text3.replace(BEARER_PATTERN, (_m, prefix) => {
175778
- count++;
175779
- return `${prefix}${markerFor("bearer")}`;
175780
- });
175781
- return { text: replaced, count };
175782
- }
175783
- }
175784
- ];
175785
- var RULE_IDS = RULES.map((r2) => r2.id);
175786
- function scrubCredentials(payloadJson) {
175787
- const redactions = {};
175788
- for (const id of RULE_IDS)
175789
- redactions[id] = 0;
175790
- let text3 = payloadJson;
175791
- for (const rule of RULES) {
175792
- const { text: next, count } = rule.replace(text3);
175793
- text3 = next;
175794
- redactions[rule.id] += count;
175795
- }
175796
- const total = Object.values(redactions).reduce((sum, n2) => sum + n2, 0);
175797
- return {
175798
- sanitized: text3,
175799
- redactions,
175800
- total
175801
- };
175802
- }
175803
-
175804
175868
  // ../../packages/core/dist/tools/compact_snapshot.js
175869
+ init_credential_scrub();
175870
+
175805
175871
  class CompactSnapshotTool {
175806
175872
  name = "compact_snapshot";
175807
175873
  storeOverride;
@@ -176323,7 +176389,7 @@ init_code_compressor();
176323
176389
 
176324
176390
  // ../../packages/core/dist/services/file-read/file-content-cache.js
176325
176391
  init_dist();
176326
- import fs14 from "fs/promises";
176392
+ import fs15 from "fs/promises";
176327
176393
 
176328
176394
  class FileContentCache {
176329
176395
  extractMetadata;
@@ -176356,7 +176422,7 @@ class FileContentCache {
176356
176422
  metadata: cached2.metadata
176357
176423
  };
176358
176424
  }
176359
- const content = await fs14.readFile(filePath, "utf-8");
176425
+ const content = await fs15.readFile(filePath, "utf-8");
176360
176426
  const metadata = await this.extractMetadata(content, filePath, options);
176361
176427
  evictOldest(this.fileCache, this.FILE_CACHE_MAX_ENTRIES - 1);
176362
176428
  this.fileCache.set(cacheKey, {
@@ -177191,6 +177257,8 @@ class WriterQueue {
177191
177257
  // ../../packages/core/dist/services/hooks/hook-service.js
177192
177258
  init_observation_extractor();
177193
177259
  init_observation_consolidation_job();
177260
+ init_credential_scrub();
177261
+
177194
177262
  class NoopBridge {
177195
177263
  maybeRun() {}
177196
177264
  }
@@ -177395,7 +177463,7 @@ init_event_bus();
177395
177463
  init_llm_client();
177396
177464
  init_symbol_graph_service();
177397
177465
  import { randomUUID as randomUUID9 } from "crypto";
177398
- import fs17 from "fs";
177466
+ import fs18 from "fs";
177399
177467
  import path30 from "path";
177400
177468
  import { spawn as spawn2 } from "child_process";
177401
177469
  var FALLBACK_BOOTSTRAP = {
@@ -177581,8 +177649,8 @@ async function scanSignals(_projectId, projectRoot, caps, symbolGraph, gitRunner
177581
177649
  try {
177582
177650
  for (const name26 of README_CANDIDATES) {
177583
177651
  const p = path30.join(projectRoot, name26);
177584
- if (fs17.existsSync(p) && fs17.statSync(p).isFile()) {
177585
- const buf = fs17.readFileSync(p);
177652
+ if (fs18.existsSync(p) && fs18.statSync(p).isFile()) {
177653
+ const buf = fs18.readFileSync(p);
177586
177654
  signals.readme = buf.slice(0, MAX_README_BYTES).toString("utf8");
177587
177655
  break;
177588
177656
  }
@@ -177592,11 +177660,11 @@ async function scanSignals(_projectId, projectRoot, caps, symbolGraph, gitRunner
177592
177660
  }
177593
177661
  try {
177594
177662
  const docsDir = path30.join(projectRoot, "docs");
177595
- if (fs17.existsSync(docsDir) && fs17.statSync(docsDir).isDirectory()) {
177663
+ if (fs18.existsSync(docsDir) && fs18.statSync(docsDir).isDirectory()) {
177596
177664
  const entries = walkMarkdown(docsDir).slice(0, MAX_DOCS);
177597
177665
  for (const rel of entries) {
177598
177666
  try {
177599
- const buf = fs17.readFileSync(rel);
177667
+ const buf = fs18.readFileSync(rel);
177600
177668
  signals.docs.push({
177601
177669
  path: path30.relative(projectRoot, rel),
177602
177670
  snippet: buf.slice(0, MAX_DOC_BYTES).toString("utf8")
@@ -177610,9 +177678,9 @@ async function scanSignals(_projectId, projectRoot, caps, symbolGraph, gitRunner
177610
177678
  try {
177611
177679
  for (const name26 of MANIFEST_FILES) {
177612
177680
  const p = path30.join(projectRoot, name26);
177613
- if (!fs17.existsSync(p) || !fs17.statSync(p).isFile())
177681
+ if (!fs18.existsSync(p) || !fs18.statSync(p).isFile())
177614
177682
  continue;
177615
- const raw2 = fs17.readFileSync(p).slice(0, MAX_MANIFEST_BYTES).toString("utf8");
177683
+ const raw2 = fs18.readFileSync(p).slice(0, MAX_MANIFEST_BYTES).toString("utf8");
177616
177684
  const kind = name26;
177617
177685
  if (name26 === "package.json") {
177618
177686
  try {
@@ -177652,7 +177720,7 @@ function walkMarkdown(dir) {
177652
177720
  const cur = stack.pop();
177653
177721
  let entries;
177654
177722
  try {
177655
- entries = fs17.readdirSync(cur, { withFileTypes: true });
177723
+ entries = fs18.readdirSync(cur, { withFileTypes: true });
177656
177724
  } catch {
177657
177725
  continue;
177658
177726
  }
@@ -178690,7 +178758,7 @@ var checkpointRoutes = new Elysia({ prefix: "/api/v1/checkpoints" }).post("/list
178690
178758
 
178691
178759
  // src/routes/project.ts
178692
178760
  init_dist();
178693
- import fs18 from "fs/promises";
178761
+ import fs19 from "fs/promises";
178694
178762
  import path31 from "path";
178695
178763
  var indexProjectTool = null;
178696
178764
  var indexStatusTool = null;
@@ -178902,8 +178970,8 @@ var projectRoutes = new Elysia({ prefix: "/api/v1/project" }).get("/list", async
178902
178970
  const finalProjectId = rawBase.replace(/[^a-zA-Z0-9_.-]/g, "_").slice(0, 128);
178903
178971
  const uploadRoot = process.env.MASSA_AI_UPLOAD_DIR || path31.join(getGlobalDataDir(), "uploads");
178904
178972
  const stagingDir = path31.resolve(uploadRoot, finalProjectId);
178905
- await fs18.rm(stagingDir, { recursive: true, force: true });
178906
- await fs18.mkdir(stagingDir, { recursive: true });
178973
+ await fs19.rm(stagingDir, { recursive: true, force: true });
178974
+ await fs19.mkdir(stagingDir, { recursive: true });
178907
178975
  const WRITE_BATCH = 20;
178908
178976
  for (let i = 0;i < body.files.length; i += WRITE_BATCH) {
178909
178977
  await Promise.all(body.files.slice(i, i + WRITE_BATCH).map(async (file3) => {
@@ -178914,8 +178982,8 @@ var projectRoutes = new Elysia({ prefix: "/api/v1/project" }).get("/list", async
178914
178982
  if (!dest.startsWith(stagingDir + path31.sep)) {
178915
178983
  throw new Error(`Path escapes staging directory: ${file3.relativePath}`);
178916
178984
  }
178917
- await fs18.mkdir(path31.dirname(dest), { recursive: true });
178918
- await fs18.writeFile(dest, file3.content, "utf-8");
178985
+ await fs19.mkdir(path31.dirname(dest), { recursive: true });
178986
+ await fs19.writeFile(dest, file3.content, "utf-8");
178919
178987
  }));
178920
178988
  }
178921
178989
  return await getIndexProjectTool().handle({
@@ -179070,7 +179138,7 @@ var analyticsRoutes = new Elysia({ prefix: "/api/v1/analytics" }).post("/", asyn
179070
179138
  // src/routes/system.ts
179071
179139
  init_dist();
179072
179140
  import path32 from "path";
179073
- import fs19 from "fs";
179141
+ import fs20 from "fs";
179074
179142
  import os7 from "os";
179075
179143
  function databaseUrlParts() {
179076
179144
  const url2 = new URL(process.env.DATABASE_URL);
@@ -179146,9 +179214,9 @@ var systemRoutes = new Elysia({ prefix: "/api/v1/system" }).get("/info", async (
179146
179214
  }).get("/metrics", async () => {
179147
179215
  const metricsPath = path32.join(process.cwd(), "data", "metrics.json");
179148
179216
  let metrics2 = {};
179149
- if (fs19.existsSync(metricsPath)) {
179217
+ if (fs20.existsSync(metricsPath)) {
179150
179218
  try {
179151
- metrics2 = JSON.parse(fs19.readFileSync(metricsPath, "utf-8"));
179219
+ metrics2 = JSON.parse(fs20.readFileSync(metricsPath, "utf-8"));
179152
179220
  } catch {}
179153
179221
  }
179154
179222
  const database = await getDatabaseInfo();
@@ -179298,7 +179366,7 @@ var eventsRoutes = new Elysia({ prefix: "/api/v1" }).get("/events", async ({ que
179298
179366
  });
179299
179367
 
179300
179368
  // src/routes/workspace.ts
179301
- import fs20 from "fs/promises";
179369
+ import fs21 from "fs/promises";
179302
179370
  import path33 from "path";
179303
179371
  import { realpathSync as realpathSync4 } from "fs";
179304
179372
  var indexProjectTool2 = null;
@@ -179824,7 +179892,7 @@ var workspaceRoutes = new Elysia({ prefix: "/api/v1" }).get("/workspace/list", a
179824
179892
  end = start + 20;
179825
179893
  }
179826
179894
  const absolutePath = path33.join(workspace.project_path, file3);
179827
- const content = await fs20.readFile(absolutePath, "utf-8");
179895
+ const content = await fs21.readFile(absolutePath, "utf-8");
179828
179896
  const lines = content.split(/\r?\n/);
179829
179897
  const slice = lines.slice(start - 1, Math.min(lines.length, end));
179830
179898
  const formatted = slice.map((text3, idx) => ({
@@ -179862,8 +179930,18 @@ function getReadFileTool() {
179862
179930
  }
179863
179931
  return readFileTool;
179864
179932
  }
179865
- var fileRoutes = new Elysia({ prefix: "/api/v1/file" }).post("/read", async ({ body }) => {
179866
- return await getReadFileTool().handle(body);
179933
+ function classifyReadFileFailureStatus(message) {
179934
+ if (message && /ENOENT|no such file/i.test(message)) {
179935
+ return 404;
179936
+ }
179937
+ return 400;
179938
+ }
179939
+ var fileRoutes = new Elysia({ prefix: "/api/v1/file" }).post("/read", async ({ body, set: set3 }) => {
179940
+ const result = await getReadFileTool().handle(body);
179941
+ if (result.success === false) {
179942
+ set3.status = classifyReadFileFailureStatus(result.error);
179943
+ }
179944
+ return result;
179867
179945
  }, {
179868
179946
  body: t.Object({
179869
179947
  filePath: t.String({
@@ -180739,7 +180817,7 @@ var webRoutes = new Elysia({ prefix: "/api/v1/web" }).post("/fetch_and_index", a
180739
180817
  });
180740
180818
 
180741
180819
  // src/routes/web-ui.ts
180742
- import fs21 from "fs/promises";
180820
+ import fs22 from "fs/promises";
180743
180821
  import path34 from "path";
180744
180822
  import { fileURLToPath as fileURLToPath3 } from "url";
180745
180823
 
@@ -180798,7 +180876,7 @@ var STATIC_DIR_CANDIDATES = buildStaticDirCandidates(path34.dirname(fileURLToPat
180798
180876
  async function resolveStaticDir() {
180799
180877
  for (const dir of STATIC_DIR_CANDIDATES) {
180800
180878
  try {
180801
- const st = await fs21.stat(dir);
180879
+ const st = await fs22.stat(dir);
180802
180880
  if (st.isDirectory())
180803
180881
  return dir;
180804
180882
  } catch {}
@@ -180836,7 +180914,7 @@ async function resolveSafePath(staticDir, sub) {
180836
180914
  return null;
180837
180915
  }
180838
180916
  try {
180839
- await fs21.stat(abs);
180917
+ await fs22.stat(abs);
180840
180918
  return { abs, exists: true };
180841
180919
  } catch {
180842
180920
  return { abs, exists: false };
@@ -180859,7 +180937,7 @@ function injectAccessMarkup(html, apiKey, trusted) {
180859
180937
  return out;
180860
180938
  }
180861
180939
  async function readShell(indexPath, remoteAddress) {
180862
- const raw2 = await fs21.readFile(indexPath, "utf-8");
180940
+ const raw2 = await fs22.readFile(indexPath, "utf-8");
180863
180941
  const trusted = isTrustedWebUiCaller(remoteAddress);
180864
180942
  return Buffer.from(injectAccessMarkup(raw2, getConfiguredApiKey(), trusted), "utf-8");
180865
180943
  }
@@ -180909,7 +180987,7 @@ var webUiRoutes = new Elysia().get("/ui", async ({ set: set3, request }) => {
180909
180987
  }
180910
180988
  if (resolved.exists) {
180911
180989
  try {
180912
- const body = await fs21.readFile(resolved.abs);
180990
+ const body = await fs22.readFile(resolved.abs);
180913
180991
  set3.headers["content-type"] = contentTypeFor(resolved.abs);
180914
180992
  return body;
180915
180993
  } catch {
@@ -181145,10 +181223,13 @@ var profileRoutes = new Elysia({ prefix: "/api/v1/profiles" }).get("/", ({ query
181145
181223
  });
181146
181224
 
181147
181225
  // src/middleware/error.ts
181148
- var errorHandler = new Elysia({ name: "error-handler" }).onError(({ code, error: error51, set: set3 }) => {
181149
- console.error("[massa-ai-api] Request failed", {
181150
- name: error51 instanceof Error ? error51.name : "UnknownError",
181151
- code
181226
+ init_dist();
181227
+ var errorHandler = new Elysia({ name: "error-handler" }).onError(({ code, error: error51, set: set3, path: path35, request }) => {
181228
+ logger.error("[massa-ai-api] Request failed", undefined, {
181229
+ ...safeErrorSummary(error51),
181230
+ code,
181231
+ path: path35,
181232
+ method: request.method
181152
181233
  });
181153
181234
  if (error51 instanceof SearchServiceError) {
181154
181235
  set3.status = error51.statusCode;
@@ -181171,6 +181252,16 @@ var errorHandler = new Elysia({ name: "error-handler" }).onError(({ code, error:
181171
181252
  }
181172
181253
  };
181173
181254
  }
181255
+ if (code === "NOT_FOUND") {
181256
+ set3.status = 404;
181257
+ return {
181258
+ success: false,
181259
+ error: {
181260
+ code: "NOT_FOUND",
181261
+ message: "Route not found"
181262
+ }
181263
+ };
181264
+ }
181174
181265
  if (!set3.status || set3.status === 200) {
181175
181266
  set3.status = 500;
181176
181267
  }