viben 1.2.7 → 1.2.8

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 (3) hide show
  1. package/dist/index.cjs +121 -97
  2. package/dist/index.js +143 -119
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -11959,27 +11959,38 @@ function getTraceStats(tree) {
11959
11959
  traverse(tree.root, 1);
11960
11960
  return { totalSpans, successSpans, errorSpans, maxDepth, operations };
11961
11961
  }
11962
- async function listTraces(baseDir, date) {
11962
+ async function listTraces(baseDir, date, options) {
11963
11963
  const tracesDir = path21.join(baseDir, "traces");
11964
11964
  const targetDate = date || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
11965
11965
  const dateDir = path21.join(tracesDir, targetDate);
11966
- if (!fs20.existsSync(dateDir)) {
11966
+ try {
11967
+ await fs15.access(dateDir);
11968
+ } catch {
11967
11969
  return [];
11968
11970
  }
11969
- const files = fs20.readdirSync(dateDir);
11970
- const traces = [];
11971
- for (const file of files) {
11972
- if (!file.endsWith(".jsonl")) continue;
11973
- const filePath = path21.join(dateDir, file);
11974
- const stat12 = fs20.statSync(filePath);
11975
- traces.push({
11976
- traceId: file.replace(".jsonl", ""),
11977
- filePath,
11978
- size: stat12.size,
11979
- mtime: stat12.mtime
11980
- });
11981
- }
11971
+ const files = await fs15.readdir(dateDir);
11972
+ const jsonlFiles = files.filter((f) => f.endsWith(".jsonl"));
11973
+ const statResults = await Promise.all(
11974
+ jsonlFiles.map(async (file) => {
11975
+ const filePath = path21.join(dateDir, file);
11976
+ try {
11977
+ const stat13 = await fs15.stat(filePath);
11978
+ return {
11979
+ traceId: file.replace(".jsonl", ""),
11980
+ filePath,
11981
+ size: stat13.size,
11982
+ mtime: stat13.mtime
11983
+ };
11984
+ } catch {
11985
+ return null;
11986
+ }
11987
+ })
11988
+ );
11989
+ const traces = statResults.filter((t) => t !== null);
11982
11990
  traces.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
11991
+ if (options?.limit && options.limit > 0) {
11992
+ return traces.slice(0, options.limit);
11993
+ }
11983
11994
  return traces;
11984
11995
  }
11985
11996
  function listTraceDates(baseDir) {
@@ -11990,6 +12001,29 @@ function listTraceDates(baseDir) {
11990
12001
  const dirs = fs20.readdirSync(tracesDir);
11991
12002
  return dirs.filter((d) => /^\d{4}-\d{2}-\d{2}$/.test(d)).sort().reverse();
11992
12003
  }
12004
+ async function readFirstSpan(filePath) {
12005
+ const fileStream = fs20.createReadStream(filePath, { encoding: "utf-8" });
12006
+ try {
12007
+ const rl = readline.createInterface({
12008
+ input: fileStream,
12009
+ crlfDelay: Infinity
12010
+ });
12011
+ for await (const line of rl) {
12012
+ if (line.trim()) {
12013
+ try {
12014
+ return JSON.parse(line);
12015
+ } catch {
12016
+ return null;
12017
+ }
12018
+ }
12019
+ }
12020
+ return null;
12021
+ } catch {
12022
+ return null;
12023
+ } finally {
12024
+ fileStream.destroy();
12025
+ }
12026
+ }
11993
12027
  var init_trace_viewer = __esm({
11994
12028
  "src/telemetry/trace-viewer.ts"() {
11995
12029
  }
@@ -12228,13 +12262,13 @@ function cleanOldTelemetryFiles(baseDir, retentionDays = 7) {
12228
12262
  for (const entry of entries) {
12229
12263
  const entryPath = path21.join(dir, entry.name);
12230
12264
  if (entry.isDirectory()) {
12231
- const stat12 = fs20.statSync(entryPath);
12232
- if (stat12.mtimeMs < cutoff) {
12265
+ const stat13 = fs20.statSync(entryPath);
12266
+ if (stat13.mtimeMs < cutoff) {
12233
12267
  fs20.rmSync(entryPath, { recursive: true });
12234
12268
  }
12235
12269
  } else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
12236
- const stat12 = fs20.statSync(entryPath);
12237
- if (stat12.mtimeMs < cutoff) {
12270
+ const stat13 = fs20.statSync(entryPath);
12271
+ if (stat13.mtimeMs < cutoff) {
12238
12272
  fs20.unlinkSync(entryPath);
12239
12273
  }
12240
12274
  }
@@ -24527,14 +24561,14 @@ var require_utils2 = __commonJS2({
24527
24561
  });
24528
24562
  };
24529
24563
  function notifierExists(notifier, cb) {
24530
- return fs23.stat(notifier, function(err, stat12) {
24531
- if (!err) return cb(err, stat12.isFile());
24564
+ return fs23.stat(notifier, function(err, stat13) {
24565
+ if (!err) return cb(err, stat13.isFile());
24532
24566
  if (path24.extname(notifier)) {
24533
24567
  return cb(err, false);
24534
24568
  }
24535
- return fs23.stat(notifier + ".exe", function(err2, stat13) {
24569
+ return fs23.stat(notifier + ".exe", function(err2, stat14) {
24536
24570
  if (err2) return cb(err2, false);
24537
- cb(err2, stat13.isFile());
24571
+ cb(err2, stat14.isFile());
24538
24572
  });
24539
24573
  });
24540
24574
  }
@@ -24890,15 +24924,15 @@ var require_windows = __commonJS2({
24890
24924
  }
24891
24925
  return false;
24892
24926
  }
24893
- function checkStat(stat12, path24, options) {
24894
- if (!stat12.isSymbolicLink() && !stat12.isFile()) {
24927
+ function checkStat(stat13, path24, options) {
24928
+ if (!stat13.isSymbolicLink() && !stat13.isFile()) {
24895
24929
  return false;
24896
24930
  }
24897
24931
  return checkPathExt(path24, options);
24898
24932
  }
24899
24933
  function isexe(path24, options, cb) {
24900
- fs23.stat(path24, function(er, stat12) {
24901
- cb(er, er ? false : checkStat(stat12, path24, options));
24934
+ fs23.stat(path24, function(er, stat13) {
24935
+ cb(er, er ? false : checkStat(stat13, path24, options));
24902
24936
  });
24903
24937
  }
24904
24938
  function sync(path24, options) {
@@ -24912,20 +24946,20 @@ var require_mode = __commonJS2({
24912
24946
  isexe.sync = sync;
24913
24947
  var fs23 = __require("fs");
24914
24948
  function isexe(path24, options, cb) {
24915
- fs23.stat(path24, function(er, stat12) {
24916
- cb(er, er ? false : checkStat(stat12, options));
24949
+ fs23.stat(path24, function(er, stat13) {
24950
+ cb(er, er ? false : checkStat(stat13, options));
24917
24951
  });
24918
24952
  }
24919
24953
  function sync(path24, options) {
24920
24954
  return checkStat(fs23.statSync(path24), options);
24921
24955
  }
24922
- function checkStat(stat12, options) {
24923
- return stat12.isFile() && checkMode(stat12, options);
24956
+ function checkStat(stat13, options) {
24957
+ return stat13.isFile() && checkMode(stat13, options);
24924
24958
  }
24925
- function checkMode(stat12, options) {
24926
- var mod2 = stat12.mode;
24927
- var uid = stat12.uid;
24928
- var gid = stat12.gid;
24959
+ function checkMode(stat13, options) {
24960
+ var mod2 = stat13.mode;
24961
+ var uid = stat13.uid;
24962
+ var gid = stat13.gid;
24929
24963
  var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
24930
24964
  var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
24931
24965
  var u = parseInt("100", 8);
@@ -37560,12 +37594,12 @@ var require_form_data = __commonJS2({
37560
37594
  if (value.end != void 0 && value.end != Infinity && value.start != void 0) {
37561
37595
  callback(null, value.end + 1 - (value.start ? value.start : 0));
37562
37596
  } else {
37563
- fs23.stat(value.path, function(err, stat12) {
37597
+ fs23.stat(value.path, function(err, stat13) {
37564
37598
  if (err) {
37565
37599
  callback(err);
37566
37600
  return;
37567
37601
  }
37568
- var fileSize = stat12.size - (value.start ? value.start : 0);
37602
+ var fileSize = stat13.size - (value.start ? value.start : 0);
37569
37603
  callback(null, fileSize);
37570
37604
  });
37571
37605
  }
@@ -134871,10 +134905,10 @@ var init_service_manager = __esm({
134871
134905
  let position = (0, import_fs.statSync)(logPath).size;
134872
134906
  const watcher = (0, import_fs.watch)(logPath, (eventType) => {
134873
134907
  if (eventType === "change") {
134874
- const stat12 = (0, import_fs.statSync)(logPath);
134875
- if (stat12.size > position) {
134908
+ const stat13 = (0, import_fs.statSync)(logPath);
134909
+ if (stat13.size > position) {
134876
134910
  const fd = (0, import_fs.openSync)(logPath, "r");
134877
- const buffer = Buffer.alloc(stat12.size - position);
134911
+ const buffer = Buffer.alloc(stat13.size - position);
134878
134912
  (0, import_fs.readSync)(fd, buffer, 0, buffer.length, position);
134879
134913
  (0, import_fs.closeSync)(fd);
134880
134914
  const newContent = buffer.toString("utf-8");
@@ -134882,7 +134916,7 @@ var init_service_manager = __esm({
134882
134916
  for (const line of lines) {
134883
134917
  onLine(line);
134884
134918
  }
134885
- position = stat12.size;
134919
+ position = stat13.size;
134886
134920
  }
134887
134921
  }
134888
134922
  });
@@ -149031,7 +149065,7 @@ var startupConfig;
149031
149065
  var gatewayStartTime;
149032
149066
  var init_health = __esm({
149033
149067
  "src/gateway/routes/health.ts"() {
149034
- VERSION3 = "1.2.7";
149068
+ VERSION3 = "1.2.8";
149035
149069
  startupConfig = null;
149036
149070
  gatewayStartTime = Date.now();
149037
149071
  }
@@ -149726,8 +149760,8 @@ function registerExecutorRoutes(fastify2) {
149726
149760
  const entries = fs20.readdirSync(folderPath);
149727
149761
  for (const entry of entries) {
149728
149762
  const entryPath = path21.join(folderPath, entry);
149729
- const stat12 = fs20.statSync(entryPath);
149730
- if (stat12.isDirectory()) {
149763
+ const stat13 = fs20.statSync(entryPath);
149764
+ if (stat13.isDirectory()) {
149731
149765
  const skillMdPath = path21.join(entryPath, "skill.md");
149732
149766
  if (fs20.existsSync(skillMdPath)) {
149733
149767
  const skill = parseSkillMd2(skillMdPath);
@@ -149811,8 +149845,8 @@ function registerExecutorRoutes(fastify2) {
149811
149845
  const entries = fs20.readdirSync(folderPath);
149812
149846
  for (const entry of entries) {
149813
149847
  const fullPath = path21.join(folderPath, entry);
149814
- const stat12 = fs20.statSync(fullPath);
149815
- if (stat12.isFile() && entry.endsWith(".md")) {
149848
+ const stat13 = fs20.statSync(fullPath);
149849
+ if (stat13.isFile() && entry.endsWith(".md")) {
149816
149850
  try {
149817
149851
  const content = fs20.readFileSync(fullPath, "utf-8");
149818
149852
  subagents.push(parseSubagentMd(fullPath, content));
@@ -149878,8 +149912,8 @@ function registerExecutorRoutes(fastify2) {
149878
149912
  const namespaces = fs20.readdirSync(folderPath);
149879
149913
  for (const namespace of namespaces) {
149880
149914
  const namespacePath = path21.join(folderPath, namespace);
149881
- const stat12 = fs20.statSync(namespacePath);
149882
- if (stat12.isDirectory()) {
149915
+ const stat13 = fs20.statSync(namespacePath);
149916
+ if (stat13.isDirectory()) {
149883
149917
  try {
149884
149918
  const files = fs20.readdirSync(namespacePath);
149885
149919
  for (const file of files) {
@@ -149901,7 +149935,7 @@ function registerExecutorRoutes(fastify2) {
149901
149935
  }
149902
149936
  } catch {
149903
149937
  }
149904
- } else if (stat12.isFile() && namespace.endsWith(".md")) {
149938
+ } else if (stat13.isFile() && namespace.endsWith(".md")) {
149905
149939
  const name = namespace.replace(/\.md$/, "");
149906
149940
  try {
149907
149941
  const content = fs20.readFileSync(namespacePath, "utf-8");
@@ -150001,8 +150035,8 @@ function registerExecutorRoutes(fastify2) {
150001
150035
  const entries = fs20.readdirSync(folderPath);
150002
150036
  for (const entry of entries) {
150003
150037
  const fullPath = path21.join(folderPath, entry);
150004
- const stat12 = fs20.statSync(fullPath);
150005
- if (stat12.isFile() && entry.endsWith(".md")) {
150038
+ const stat13 = fs20.statSync(fullPath);
150039
+ if (stat13.isFile() && entry.endsWith(".md")) {
150006
150040
  try {
150007
150041
  const content = fs20.readFileSync(fullPath, "utf-8");
150008
150042
  prompts.push(parsePromptMd(fullPath, content));
@@ -150871,10 +150905,10 @@ function registerAgentRoutes(fastify2, state) {
150871
150905
  const authFile = (0, import_path.join)(claudeDir, "config.json");
150872
150906
  if ((0, import_fs.existsSync)(authFile)) {
150873
150907
  try {
150874
- const stat12 = (0, import_fs.statSync)(authFile);
150908
+ const stat13 = (0, import_fs.statSync)(authFile);
150875
150909
  availability = {
150876
150910
  type: "LOGIN_DETECTED",
150877
- last_auth_timestamp: Math.floor(stat12.mtimeMs)
150911
+ last_auth_timestamp: Math.floor(stat13.mtimeMs)
150878
150912
  };
150879
150913
  } catch {
150880
150914
  availability = { type: "INSTALLATION_FOUND" };
@@ -150923,10 +150957,10 @@ function registerAgentRoutes(fastify2, state) {
150923
150957
  const openClawConfig = (0, import_path.join)(openClawDir, "openclaw.json");
150924
150958
  if ((0, import_fs.existsSync)(openClawConfig)) {
150925
150959
  try {
150926
- const stat12 = (0, import_fs.statSync)(openClawConfig);
150960
+ const stat13 = (0, import_fs.statSync)(openClawConfig);
150927
150961
  availability = {
150928
150962
  type: "LOGIN_DETECTED",
150929
- last_auth_timestamp: Math.floor(stat12.mtimeMs)
150963
+ last_auth_timestamp: Math.floor(stat13.mtimeMs)
150930
150964
  };
150931
150965
  } catch {
150932
150966
  availability = { type: "INSTALLATION_FOUND" };
@@ -163030,16 +163064,7 @@ function registerTelemetryRoutes(fastify2) {
163030
163064
  fastify2.get("/api/telemetry/dates", async (_request, reply) => {
163031
163065
  try {
163032
163066
  const dates = listTraceDates(baseDir);
163033
- const result = await Promise.all(
163034
- dates.map(async (date) => {
163035
- const traces = await listTraces(baseDir, date);
163036
- return {
163037
- date,
163038
- count: traces.length,
163039
- totalSize: traces.reduce((sum, t) => sum + t.size, 0)
163040
- };
163041
- })
163042
- );
163067
+ const result = dates.map((date) => ({ date }));
163043
163068
  return reply.send(result);
163044
163069
  } catch (error) {
163045
163070
  return reply.status(500).send({
@@ -163052,27 +163077,26 @@ function registerTelemetryRoutes(fastify2) {
163052
163077
  "/api/telemetry/traces",
163053
163078
  async (request, reply) => {
163054
163079
  try {
163055
- const { date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0], route } = request.query;
163056
- const traces = await listTraces(baseDir, date);
163057
- let filteredTraces = traces;
163080
+ const { date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0], route, limit: limitStr } = request.query;
163081
+ const parsedLimit = limitStr ? parseInt(limitStr, 10) : 100;
163082
+ const limit = isNaN(parsedLimit) || parsedLimit <= 0 ? 100 : parsedLimit;
163083
+ let filteredTraces;
163058
163084
  if (route) {
163085
+ const traces = await listTraces(baseDir, date);
163059
163086
  filteredTraces = [];
163060
163087
  for (const t of traces) {
163061
- const filePath = path21.join(baseDir, "traces", date, `${t.traceId}.jsonl`);
163062
- try {
163063
- const spans = await loadTrace(filePath);
163064
- const matches = spans.some((span) => {
163065
- const httpTarget = span.attributes["http.target"];
163066
- const httpRoute = span.attributes["http.route"];
163067
- const httpUrl = span.attributes["http.url"];
163068
- return httpTarget?.includes(route) || httpRoute?.includes(route) || httpUrl?.includes(route);
163069
- });
163070
- if (matches) {
163071
- filteredTraces.push(t);
163072
- }
163073
- } catch {
163088
+ if (filteredTraces.length >= limit) break;
163089
+ const firstSpan = await readFirstSpan(t.filePath);
163090
+ if (!firstSpan) continue;
163091
+ const httpTarget = firstSpan.attributes["http.target"];
163092
+ const httpRoute = firstSpan.attributes["http.route"];
163093
+ const httpUrl = firstSpan.attributes["http.url"];
163094
+ if (httpTarget?.includes(route) || httpRoute?.includes(route) || httpUrl?.includes(route)) {
163095
+ filteredTraces.push(t);
163074
163096
  }
163075
163097
  }
163098
+ } else {
163099
+ filteredTraces = await listTraces(baseDir, date, { limit });
163076
163100
  }
163077
163101
  const result = filteredTraces.map((t) => ({
163078
163102
  traceId: t.traceId,
@@ -164866,7 +164890,7 @@ async function getSessionFromFile(filePath) {
164866
164890
  }
164867
164891
  try {
164868
164892
  const entries = await parseLogFile(filePath);
164869
- const stat12 = (0, import_fs.statSync)(filePath);
164893
+ const stat13 = (0, import_fs.statSync)(filePath);
164870
164894
  const runId = (0, import_path.basename)(filePath, ".log");
164871
164895
  let serverId = "unknown";
164872
164896
  let serverName = "Unknown Server";
@@ -164887,13 +164911,13 @@ async function getSessionFromFile(filePath) {
164887
164911
  server_id: serverId,
164888
164912
  server_name: serverName,
164889
164913
  pid,
164890
- created_at: stat12.birthtime.toISOString(),
164891
- updated_at: stat12.mtime.toISOString(),
164914
+ created_at: stat13.birthtime.toISOString(),
164915
+ updated_at: stat13.mtime.toISOString(),
164892
164916
  ended_at: null,
164893
164917
  log_file: filePath,
164894
164918
  log_count: entries.length,
164895
164919
  error_count: errorCount,
164896
- started_at: stat12.birthtime.toISOString()
164920
+ started_at: stat13.birthtime.toISOString()
164897
164921
  };
164898
164922
  } catch {
164899
164923
  return null;
@@ -164908,8 +164932,8 @@ async function getLogSessions(serverId) {
164908
164932
  for (const file of files) {
164909
164933
  if (!file.endsWith(".log")) continue;
164910
164934
  const filePath = (0, import_path.join)(logsDir, file);
164911
- const stat12 = (0, import_fs.statSync)(filePath);
164912
- if (!stat12.isFile()) continue;
164935
+ const stat13 = (0, import_fs.statSync)(filePath);
164936
+ if (!stat13.isFile()) continue;
164913
164937
  const session = await getSessionFromFile(filePath);
164914
164938
  if (session) {
164915
164939
  if (!serverId || session.server_id === serverId) {
@@ -165046,8 +165070,8 @@ function registerLogsRoutes(fastify2) {
165046
165070
  for (const file of files) {
165047
165071
  if (!file.endsWith(".jsonl")) continue;
165048
165072
  const filePath = (0, import_path.join)(apiLogsDir, file);
165049
- const stat12 = (0, import_fs.statSync)(filePath);
165050
- if (!stat12.isFile()) continue;
165073
+ const stat13 = (0, import_fs.statSync)(filePath);
165074
+ if (!stat13.isFile()) continue;
165051
165075
  const runId = (0, import_path.basename)(file, ".jsonl");
165052
165076
  const content = await (0, import_promises.readFile)(filePath, "utf-8");
165053
165077
  const lines = content.split("\n").filter((l) => l.trim());
@@ -165194,8 +165218,8 @@ function isCacheValid() {
165194
165218
  return false;
165195
165219
  }
165196
165220
  try {
165197
- const stat12 = (0, import_fs.statSync)(cachePath);
165198
- const age = Date.now() - stat12.mtimeMs;
165221
+ const stat13 = (0, import_fs.statSync)(cachePath);
165222
+ const age = Date.now() - stat13.mtimeMs;
165199
165223
  return age < CACHE_TTL_MS2;
165200
165224
  } catch {
165201
165225
  return false;
@@ -165438,8 +165462,8 @@ function isCacheValid2() {
165438
165462
  return false;
165439
165463
  }
165440
165464
  try {
165441
- const stat12 = (0, import_fs.statSync)(cachePath);
165442
- const age = Date.now() - stat12.mtimeMs;
165465
+ const stat13 = (0, import_fs.statSync)(cachePath);
165466
+ const age = Date.now() - stat13.mtimeMs;
165443
165467
  return age < CACHE_TTL_MS3;
165444
165468
  } catch {
165445
165469
  return false;
@@ -175268,8 +175292,8 @@ function serveStaticFile(page, requestedPath) {
175268
175292
  error: `File not found: ${relativePath}`
175269
175293
  };
175270
175294
  }
175271
- const stat12 = (0, import_fs.statSync)(resolvedPath);
175272
- if (!stat12.isFile()) {
175295
+ const stat13 = (0, import_fs.statSync)(resolvedPath);
175296
+ if (!stat13.isFile()) {
175273
175297
  return {
175274
175298
  success: false,
175275
175299
  error: `Not a file: ${relativePath}`
@@ -184293,7 +184317,7 @@ ${import_chalk.default.bold("Telemetry \u7EDF\u8BA1")}:
184293
184317
  init_lib();
184294
184318
  init_update();
184295
184319
  var execAsync11 = (0, import_util.promisify)(import_child_process.exec);
184296
- var CURRENT_VERSION = "1.2.7";
184320
+ var CURRENT_VERSION = "1.2.8";
184297
184321
  var GITHUB_REPO2 = "LinXueyuanStdio/viben";
184298
184322
  var NPM_PACKAGE = "viben";
184299
184323
  function compareSemver(a, b) {
@@ -192921,7 +192945,7 @@ function registerCommands(program) {
192921
192945
  registerAccountCommand(program);
192922
192946
  registerAppCommand(program);
192923
192947
  }
192924
- var VERSION4 = "1.2.7";
192948
+ var VERSION4 = "1.2.8";
192925
192949
  function createProgram() {
192926
192950
  const program = new import_commander.Command();
192927
192951
  program.name("viben").description("Viben - Agent Swarm \xD7 Code Evolution").version(VERSION4, "-v, --version", "Output the version number");
package/dist/index.js CHANGED
@@ -2165,7 +2165,7 @@ import os3__default, { homedir as homedir2, platform as platform2, type, release
2165
2165
  import * as path21 from "path";
2166
2166
  import path21__default, { join as join2, dirname as dirname2, basename as basename2, isAbsolute, resolve as resolve2, parse as parse$1, sep as sep2, delimiter, extname as extname2, relative as relative2 } from "path";
2167
2167
  import * as fs15 from "fs/promises";
2168
- import { readFile, mkdir as mkdir2, writeFile as writeFile2, readdir as readdir2, rm, appendFile, cp, stat, access as access2, constants, rename, unlink as unlink2, chmod, realpath } from "fs/promises";
2168
+ import { readFile, mkdir as mkdir2, writeFile as writeFile2, readdir as readdir2, rm, appendFile, cp, stat as stat2, access as access2, constants, rename, unlink as unlink2, chmod, realpath } from "fs/promises";
2169
2169
  import * as fs20 from "fs";
2170
2170
  import fs20__default, { existsSync as existsSync2, mkdirSync as mkdirSync2, statSync as statSync2, openSync as openSync2, readSync, closeSync as closeSync2, readFileSync as readFileSync2, readdirSync as readdirSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2, watch as watch2, rmSync as rmSync2, copyFileSync, renameSync, cpSync, appendFileSync as appendFileSync2, createWriteStream, writeSync } from "fs";
2171
2171
  import { parse, stringify } from "yaml";
@@ -3635,7 +3635,7 @@ var init_memory = __esm({
3635
3635
  };
3636
3636
  }
3637
3637
  const content = await readFile(memoryPath, "utf-8");
3638
- const stats = await stat(memoryPath);
3638
+ const stats = await stat2(memoryPath);
3639
3639
  return {
3640
3640
  agent_id,
3641
3641
  content,
@@ -3693,7 +3693,7 @@ var init_memory = __esm({
3693
3693
  return null;
3694
3694
  }
3695
3695
  const content = await readFile(logPath, "utf-8");
3696
- const stats = await stat(logPath);
3696
+ const stats = await stat2(logPath);
3697
3697
  const entries = this.parseDailyLog(content);
3698
3698
  return {
3699
3699
  date: dateStr,
@@ -3827,7 +3827,7 @@ var init_memory = __esm({
3827
3827
  for (const date of dates) {
3828
3828
  const logPath = join2(memoryDir, `${date}.md`);
3829
3829
  if (fileExists(logPath)) {
3830
- const stats = await stat(logPath);
3830
+ const stats = await stat2(logPath);
3831
3831
  totalSize += stats.size;
3832
3832
  }
3833
3833
  }
@@ -8680,7 +8680,7 @@ var init_service = __esm({
8680
8680
  const exactPath = join2(tasksDir, name);
8681
8681
  if (existsSync2(exactPath)) {
8682
8682
  try {
8683
- const stats = await stat(exactPath);
8683
+ const stats = await stat2(exactPath);
8684
8684
  if (stats.isDirectory()) {
8685
8685
  return exactPath;
8686
8686
  }
@@ -11950,27 +11950,38 @@ function getTraceStats(tree) {
11950
11950
  traverse(tree.root, 1);
11951
11951
  return { totalSpans, successSpans, errorSpans, maxDepth, operations };
11952
11952
  }
11953
- async function listTraces(baseDir, date) {
11953
+ async function listTraces(baseDir, date, options) {
11954
11954
  const tracesDir = path21.join(baseDir, "traces");
11955
11955
  const targetDate = date || (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
11956
11956
  const dateDir = path21.join(tracesDir, targetDate);
11957
- if (!fs20.existsSync(dateDir)) {
11957
+ try {
11958
+ await fs15.access(dateDir);
11959
+ } catch {
11958
11960
  return [];
11959
11961
  }
11960
- const files = fs20.readdirSync(dateDir);
11961
- const traces = [];
11962
- for (const file of files) {
11963
- if (!file.endsWith(".jsonl")) continue;
11964
- const filePath = path21.join(dateDir, file);
11965
- const stat12 = fs20.statSync(filePath);
11966
- traces.push({
11967
- traceId: file.replace(".jsonl", ""),
11968
- filePath,
11969
- size: stat12.size,
11970
- mtime: stat12.mtime
11971
- });
11972
- }
11962
+ const files = await fs15.readdir(dateDir);
11963
+ const jsonlFiles = files.filter((f) => f.endsWith(".jsonl"));
11964
+ const statResults = await Promise.all(
11965
+ jsonlFiles.map(async (file) => {
11966
+ const filePath = path21.join(dateDir, file);
11967
+ try {
11968
+ const stat13 = await fs15.stat(filePath);
11969
+ return {
11970
+ traceId: file.replace(".jsonl", ""),
11971
+ filePath,
11972
+ size: stat13.size,
11973
+ mtime: stat13.mtime
11974
+ };
11975
+ } catch {
11976
+ return null;
11977
+ }
11978
+ })
11979
+ );
11980
+ const traces = statResults.filter((t) => t !== null);
11973
11981
  traces.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());
11982
+ if (options?.limit && options.limit > 0) {
11983
+ return traces.slice(0, options.limit);
11984
+ }
11974
11985
  return traces;
11975
11986
  }
11976
11987
  function listTraceDates(baseDir) {
@@ -11981,6 +11992,29 @@ function listTraceDates(baseDir) {
11981
11992
  const dirs = fs20.readdirSync(tracesDir);
11982
11993
  return dirs.filter((d) => /^\d{4}-\d{2}-\d{2}$/.test(d)).sort().reverse();
11983
11994
  }
11995
+ async function readFirstSpan(filePath) {
11996
+ const fileStream = fs20.createReadStream(filePath, { encoding: "utf-8" });
11997
+ try {
11998
+ const rl = readline.createInterface({
11999
+ input: fileStream,
12000
+ crlfDelay: Infinity
12001
+ });
12002
+ for await (const line of rl) {
12003
+ if (line.trim()) {
12004
+ try {
12005
+ return JSON.parse(line);
12006
+ } catch {
12007
+ return null;
12008
+ }
12009
+ }
12010
+ }
12011
+ return null;
12012
+ } catch {
12013
+ return null;
12014
+ } finally {
12015
+ fileStream.destroy();
12016
+ }
12017
+ }
11984
12018
  var init_trace_viewer = __esm({
11985
12019
  "src/telemetry/trace-viewer.ts"() {
11986
12020
  }
@@ -12219,13 +12253,13 @@ function cleanOldTelemetryFiles(baseDir, retentionDays = 7) {
12219
12253
  for (const entry of entries) {
12220
12254
  const entryPath = path21.join(dir, entry.name);
12221
12255
  if (entry.isDirectory()) {
12222
- const stat12 = fs20.statSync(entryPath);
12223
- if (stat12.mtimeMs < cutoff) {
12256
+ const stat13 = fs20.statSync(entryPath);
12257
+ if (stat13.mtimeMs < cutoff) {
12224
12258
  fs20.rmSync(entryPath, { recursive: true });
12225
12259
  }
12226
12260
  } else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
12227
- const stat12 = fs20.statSync(entryPath);
12228
- if (stat12.mtimeMs < cutoff) {
12261
+ const stat13 = fs20.statSync(entryPath);
12262
+ if (stat13.mtimeMs < cutoff) {
12229
12263
  fs20.unlinkSync(entryPath);
12230
12264
  }
12231
12265
  }
@@ -15795,7 +15829,7 @@ async function copyTemplateDir(srcRelativePath, destPath, options, createdFiles,
15795
15829
  for (const entry of entries) {
15796
15830
  const srcEntryPath = join2(srcPath, entry);
15797
15831
  const destEntryPath = join2(destPath, entry);
15798
- const entryStat = await stat(srcEntryPath);
15832
+ const entryStat = await stat2(srcEntryPath);
15799
15833
  if (entryStat.isDirectory()) {
15800
15834
  await copyTemplateDir(
15801
15835
  join2(srcRelativePath, entry),
@@ -16508,7 +16542,7 @@ var init_workspace = __esm({
16508
16542
  if (!config) {
16509
16543
  return null;
16510
16544
  }
16511
- const fileStat = await stat(configPath);
16545
+ const fileStat = await stat2(configPath);
16512
16546
  return {
16513
16547
  path: workspace_path,
16514
16548
  name: config.name || basename2(workspace_path),
@@ -24518,14 +24552,14 @@ var require_utils2 = __commonJS2({
24518
24552
  });
24519
24553
  };
24520
24554
  function notifierExists(notifier, cb) {
24521
- return fs23.stat(notifier, function(err, stat12) {
24522
- if (!err) return cb(err, stat12.isFile());
24555
+ return fs23.stat(notifier, function(err, stat13) {
24556
+ if (!err) return cb(err, stat13.isFile());
24523
24557
  if (path24.extname(notifier)) {
24524
24558
  return cb(err, false);
24525
24559
  }
24526
- return fs23.stat(notifier + ".exe", function(err2, stat13) {
24560
+ return fs23.stat(notifier + ".exe", function(err2, stat14) {
24527
24561
  if (err2) return cb(err2, false);
24528
- cb(err2, stat13.isFile());
24562
+ cb(err2, stat14.isFile());
24529
24563
  });
24530
24564
  });
24531
24565
  }
@@ -24881,15 +24915,15 @@ var require_windows = __commonJS2({
24881
24915
  }
24882
24916
  return false;
24883
24917
  }
24884
- function checkStat(stat12, path24, options) {
24885
- if (!stat12.isSymbolicLink() && !stat12.isFile()) {
24918
+ function checkStat(stat13, path24, options) {
24919
+ if (!stat13.isSymbolicLink() && !stat13.isFile()) {
24886
24920
  return false;
24887
24921
  }
24888
24922
  return checkPathExt(path24, options);
24889
24923
  }
24890
24924
  function isexe(path24, options, cb) {
24891
- fs23.stat(path24, function(er, stat12) {
24892
- cb(er, er ? false : checkStat(stat12, path24, options));
24925
+ fs23.stat(path24, function(er, stat13) {
24926
+ cb(er, er ? false : checkStat(stat13, path24, options));
24893
24927
  });
24894
24928
  }
24895
24929
  function sync(path24, options) {
@@ -24903,20 +24937,20 @@ var require_mode = __commonJS2({
24903
24937
  isexe.sync = sync;
24904
24938
  var fs23 = __require2("fs");
24905
24939
  function isexe(path24, options, cb) {
24906
- fs23.stat(path24, function(er, stat12) {
24907
- cb(er, er ? false : checkStat(stat12, options));
24940
+ fs23.stat(path24, function(er, stat13) {
24941
+ cb(er, er ? false : checkStat(stat13, options));
24908
24942
  });
24909
24943
  }
24910
24944
  function sync(path24, options) {
24911
24945
  return checkStat(fs23.statSync(path24), options);
24912
24946
  }
24913
- function checkStat(stat12, options) {
24914
- return stat12.isFile() && checkMode(stat12, options);
24947
+ function checkStat(stat13, options) {
24948
+ return stat13.isFile() && checkMode(stat13, options);
24915
24949
  }
24916
- function checkMode(stat12, options) {
24917
- var mod2 = stat12.mode;
24918
- var uid = stat12.uid;
24919
- var gid = stat12.gid;
24950
+ function checkMode(stat13, options) {
24951
+ var mod2 = stat13.mode;
24952
+ var uid = stat13.uid;
24953
+ var gid = stat13.gid;
24920
24954
  var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
24921
24955
  var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
24922
24956
  var u = parseInt("100", 8);
@@ -37551,12 +37585,12 @@ var require_form_data = __commonJS2({
37551
37585
  if (value.end != void 0 && value.end != Infinity && value.start != void 0) {
37552
37586
  callback(null, value.end + 1 - (value.start ? value.start : 0));
37553
37587
  } else {
37554
- fs23.stat(value.path, function(err, stat12) {
37588
+ fs23.stat(value.path, function(err, stat13) {
37555
37589
  if (err) {
37556
37590
  callback(err);
37557
37591
  return;
37558
37592
  }
37559
- var fileSize = stat12.size - (value.start ? value.start : 0);
37593
+ var fileSize = stat13.size - (value.start ? value.start : 0);
37560
37594
  callback(null, fileSize);
37561
37595
  });
37562
37596
  }
@@ -134862,10 +134896,10 @@ var init_service_manager = __esm({
134862
134896
  let position = statSync2(logPath).size;
134863
134897
  const watcher = watch2(logPath, (eventType) => {
134864
134898
  if (eventType === "change") {
134865
- const stat12 = statSync2(logPath);
134866
- if (stat12.size > position) {
134899
+ const stat13 = statSync2(logPath);
134900
+ if (stat13.size > position) {
134867
134901
  const fd = openSync2(logPath, "r");
134868
- const buffer = Buffer.alloc(stat12.size - position);
134902
+ const buffer = Buffer.alloc(stat13.size - position);
134869
134903
  readSync(fd, buffer, 0, buffer.length, position);
134870
134904
  closeSync2(fd);
134871
134905
  const newContent = buffer.toString("utf-8");
@@ -134873,7 +134907,7 @@ var init_service_manager = __esm({
134873
134907
  for (const line of lines) {
134874
134908
  onLine(line);
134875
134909
  }
134876
- position = stat12.size;
134910
+ position = stat13.size;
134877
134911
  }
134878
134912
  }
134879
134913
  });
@@ -139142,7 +139176,7 @@ var init_service3 = __esm({
139142
139176
  const finalFilename = await this.generateUniqueFilename(filesDir, filename);
139143
139177
  const filePath = join2(filesDir, finalFilename);
139144
139178
  await writeFile2(filePath, data);
139145
- const stats = await stat(filePath);
139179
+ const stats = await stat2(filePath);
139146
139180
  const guessedMime = mimeType || this.guessMimeType(finalFilename) || "application/octet-stream";
139147
139181
  const fileInfo = {
139148
139182
  id: randomUUID(),
@@ -139172,7 +139206,7 @@ var init_service3 = __esm({
139172
139206
  for (const entry of entries) {
139173
139207
  if (entry.isFile()) {
139174
139208
  const filePath = join2(filesDir, entry.name);
139175
- const stats = await stat(filePath);
139209
+ const stats = await stat2(filePath);
139176
139210
  const mimeType = this.guessMimeType(entry.name) || "application/octet-stream";
139177
139211
  files.push({
139178
139212
  id: entry.name,
@@ -139219,7 +139253,7 @@ var init_service3 = __esm({
139219
139253
  if (!existsSync2(filePath)) {
139220
139254
  return null;
139221
139255
  }
139222
- const stats = await stat(filePath);
139256
+ const stats = await stat2(filePath);
139223
139257
  const mimeType = this.guessMimeType(safeFilename) || "application/octet-stream";
139224
139258
  return {
139225
139259
  id: safeFilename,
@@ -139269,7 +139303,7 @@ var init_service3 = __esm({
139269
139303
  const finalFilename = await this.generateUniqueFilename(picturesDir, filename);
139270
139304
  const filePath = join2(picturesDir, finalFilename);
139271
139305
  await writeFile2(filePath, data);
139272
- const stats = await stat(filePath);
139306
+ const stats = await stat2(filePath);
139273
139307
  const guessedMime = mimeType || this.guessMimeType(finalFilename) || "image/jpeg";
139274
139308
  const fileInfo = {
139275
139309
  id: randomUUID(),
@@ -139299,7 +139333,7 @@ var init_service3 = __esm({
139299
139333
  for (const entry of entries) {
139300
139334
  if (entry.isFile()) {
139301
139335
  const filePath = join2(picturesDir, entry.name);
139302
- const stats = await stat(filePath);
139336
+ const stats = await stat2(filePath);
139303
139337
  const mimeType = this.guessMimeType(entry.name) || "image/jpeg";
139304
139338
  pictures.push({
139305
139339
  id: entry.name,
@@ -139346,7 +139380,7 @@ var init_service3 = __esm({
139346
139380
  if (!existsSync2(filePath)) {
139347
139381
  return null;
139348
139382
  }
139349
- const stats = await stat(filePath);
139383
+ const stats = await stat2(filePath);
139350
139384
  const mimeType = this.guessMimeType(safeFilename) || "image/jpeg";
139351
139385
  return {
139352
139386
  id: safeFilename,
@@ -149022,7 +149056,7 @@ var startupConfig;
149022
149056
  var gatewayStartTime;
149023
149057
  var init_health = __esm({
149024
149058
  "src/gateway/routes/health.ts"() {
149025
- VERSION3 = "1.2.7";
149059
+ VERSION3 = "1.2.8";
149026
149060
  startupConfig = null;
149027
149061
  gatewayStartTime = Date.now();
149028
149062
  }
@@ -149717,8 +149751,8 @@ function registerExecutorRoutes(fastify2) {
149717
149751
  const entries = fs20.readdirSync(folderPath);
149718
149752
  for (const entry of entries) {
149719
149753
  const entryPath = path21.join(folderPath, entry);
149720
- const stat12 = fs20.statSync(entryPath);
149721
- if (stat12.isDirectory()) {
149754
+ const stat13 = fs20.statSync(entryPath);
149755
+ if (stat13.isDirectory()) {
149722
149756
  const skillMdPath = path21.join(entryPath, "skill.md");
149723
149757
  if (fs20.existsSync(skillMdPath)) {
149724
149758
  const skill = parseSkillMd2(skillMdPath);
@@ -149802,8 +149836,8 @@ function registerExecutorRoutes(fastify2) {
149802
149836
  const entries = fs20.readdirSync(folderPath);
149803
149837
  for (const entry of entries) {
149804
149838
  const fullPath = path21.join(folderPath, entry);
149805
- const stat12 = fs20.statSync(fullPath);
149806
- if (stat12.isFile() && entry.endsWith(".md")) {
149839
+ const stat13 = fs20.statSync(fullPath);
149840
+ if (stat13.isFile() && entry.endsWith(".md")) {
149807
149841
  try {
149808
149842
  const content = fs20.readFileSync(fullPath, "utf-8");
149809
149843
  subagents.push(parseSubagentMd(fullPath, content));
@@ -149869,8 +149903,8 @@ function registerExecutorRoutes(fastify2) {
149869
149903
  const namespaces = fs20.readdirSync(folderPath);
149870
149904
  for (const namespace of namespaces) {
149871
149905
  const namespacePath = path21.join(folderPath, namespace);
149872
- const stat12 = fs20.statSync(namespacePath);
149873
- if (stat12.isDirectory()) {
149906
+ const stat13 = fs20.statSync(namespacePath);
149907
+ if (stat13.isDirectory()) {
149874
149908
  try {
149875
149909
  const files = fs20.readdirSync(namespacePath);
149876
149910
  for (const file of files) {
@@ -149892,7 +149926,7 @@ function registerExecutorRoutes(fastify2) {
149892
149926
  }
149893
149927
  } catch {
149894
149928
  }
149895
- } else if (stat12.isFile() && namespace.endsWith(".md")) {
149929
+ } else if (stat13.isFile() && namespace.endsWith(".md")) {
149896
149930
  const name = namespace.replace(/\.md$/, "");
149897
149931
  try {
149898
149932
  const content = fs20.readFileSync(namespacePath, "utf-8");
@@ -149992,8 +150026,8 @@ function registerExecutorRoutes(fastify2) {
149992
150026
  const entries = fs20.readdirSync(folderPath);
149993
150027
  for (const entry of entries) {
149994
150028
  const fullPath = path21.join(folderPath, entry);
149995
- const stat12 = fs20.statSync(fullPath);
149996
- if (stat12.isFile() && entry.endsWith(".md")) {
150029
+ const stat13 = fs20.statSync(fullPath);
150030
+ if (stat13.isFile() && entry.endsWith(".md")) {
149997
150031
  try {
149998
150032
  const content = fs20.readFileSync(fullPath, "utf-8");
149999
150033
  prompts.push(parsePromptMd(fullPath, content));
@@ -150862,10 +150896,10 @@ function registerAgentRoutes(fastify2, state) {
150862
150896
  const authFile = join2(claudeDir, "config.json");
150863
150897
  if (existsSync2(authFile)) {
150864
150898
  try {
150865
- const stat12 = statSync2(authFile);
150899
+ const stat13 = statSync2(authFile);
150866
150900
  availability = {
150867
150901
  type: "LOGIN_DETECTED",
150868
- last_auth_timestamp: Math.floor(stat12.mtimeMs)
150902
+ last_auth_timestamp: Math.floor(stat13.mtimeMs)
150869
150903
  };
150870
150904
  } catch {
150871
150905
  availability = { type: "INSTALLATION_FOUND" };
@@ -150914,10 +150948,10 @@ function registerAgentRoutes(fastify2, state) {
150914
150948
  const openClawConfig = join2(openClawDir, "openclaw.json");
150915
150949
  if (existsSync2(openClawConfig)) {
150916
150950
  try {
150917
- const stat12 = statSync2(openClawConfig);
150951
+ const stat13 = statSync2(openClawConfig);
150918
150952
  availability = {
150919
150953
  type: "LOGIN_DETECTED",
150920
- last_auth_timestamp: Math.floor(stat12.mtimeMs)
150954
+ last_auth_timestamp: Math.floor(stat13.mtimeMs)
150921
150955
  };
150922
150956
  } catch {
150923
150957
  availability = { type: "INSTALLATION_FOUND" };
@@ -162429,7 +162463,7 @@ function resolvePath(path24) {
162429
162463
  return resolve2(path24);
162430
162464
  }
162431
162465
  async function getFileEntry(filePath, name) {
162432
- const stats = await stat(filePath);
162466
+ const stats = await stat2(filePath);
162433
162467
  return {
162434
162468
  name,
162435
162469
  path: filePath,
@@ -162473,7 +162507,7 @@ function registerFileRoutes(fastify2) {
162473
162507
  return { error: `Path does not exist: ${dirPath}` };
162474
162508
  }
162475
162509
  try {
162476
- const stats = await stat(dirPath);
162510
+ const stats = await stat2(dirPath);
162477
162511
  if (!stats.isDirectory()) {
162478
162512
  reply.code(400);
162479
162513
  return { error: `Path is not a directory: ${dirPath}` };
@@ -162529,7 +162563,7 @@ function registerFileRoutes(fastify2) {
162529
162563
  return { error: `File does not exist: ${filePath}` };
162530
162564
  }
162531
162565
  try {
162532
- const stats = await stat(filePath);
162566
+ const stats = await stat2(filePath);
162533
162567
  if (!stats.isFile()) {
162534
162568
  reply.code(400);
162535
162569
  return { error: `Path is not a file: ${filePath}` };
@@ -162602,7 +162636,7 @@ function registerFileRoutes(fastify2) {
162602
162636
  }
162603
162637
  try {
162604
162638
  if (existsSync2(dirPath)) {
162605
- const stats = await stat(dirPath);
162639
+ const stats = await stat2(dirPath);
162606
162640
  if (stats.isDirectory()) {
162607
162641
  reply.code(409);
162608
162642
  return { error: `Directory already exists: ${dirPath}` };
@@ -162980,7 +163014,7 @@ function registerFileRoutes(fastify2) {
162980
163014
  }
162981
163015
  try {
162982
163016
  const currentPlatform = platform2();
162983
- const stats = await stat(filePath);
163017
+ const stats = await stat2(filePath);
162984
163018
  const targetPath = stats.isDirectory() ? filePath : dirname2(filePath);
162985
163019
  if (currentPlatform === "darwin") {
162986
163020
  const revealProcess = spawn("open", [targetPath], {
@@ -163021,16 +163055,7 @@ function registerTelemetryRoutes(fastify2) {
163021
163055
  fastify2.get("/api/telemetry/dates", async (_request, reply) => {
163022
163056
  try {
163023
163057
  const dates = listTraceDates(baseDir);
163024
- const result = await Promise.all(
163025
- dates.map(async (date) => {
163026
- const traces = await listTraces(baseDir, date);
163027
- return {
163028
- date,
163029
- count: traces.length,
163030
- totalSize: traces.reduce((sum, t) => sum + t.size, 0)
163031
- };
163032
- })
163033
- );
163058
+ const result = dates.map((date) => ({ date }));
163034
163059
  return reply.send(result);
163035
163060
  } catch (error) {
163036
163061
  return reply.status(500).send({
@@ -163043,27 +163068,26 @@ function registerTelemetryRoutes(fastify2) {
163043
163068
  "/api/telemetry/traces",
163044
163069
  async (request, reply) => {
163045
163070
  try {
163046
- const { date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0], route } = request.query;
163047
- const traces = await listTraces(baseDir, date);
163048
- let filteredTraces = traces;
163071
+ const { date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0], route, limit: limitStr } = request.query;
163072
+ const parsedLimit = limitStr ? parseInt(limitStr, 10) : 100;
163073
+ const limit = isNaN(parsedLimit) || parsedLimit <= 0 ? 100 : parsedLimit;
163074
+ let filteredTraces;
163049
163075
  if (route) {
163076
+ const traces = await listTraces(baseDir, date);
163050
163077
  filteredTraces = [];
163051
163078
  for (const t of traces) {
163052
- const filePath = path21.join(baseDir, "traces", date, `${t.traceId}.jsonl`);
163053
- try {
163054
- const spans = await loadTrace(filePath);
163055
- const matches = spans.some((span) => {
163056
- const httpTarget = span.attributes["http.target"];
163057
- const httpRoute = span.attributes["http.route"];
163058
- const httpUrl = span.attributes["http.url"];
163059
- return httpTarget?.includes(route) || httpRoute?.includes(route) || httpUrl?.includes(route);
163060
- });
163061
- if (matches) {
163062
- filteredTraces.push(t);
163063
- }
163064
- } catch {
163079
+ if (filteredTraces.length >= limit) break;
163080
+ const firstSpan = await readFirstSpan(t.filePath);
163081
+ if (!firstSpan) continue;
163082
+ const httpTarget = firstSpan.attributes["http.target"];
163083
+ const httpRoute = firstSpan.attributes["http.route"];
163084
+ const httpUrl = firstSpan.attributes["http.url"];
163085
+ if (httpTarget?.includes(route) || httpRoute?.includes(route) || httpUrl?.includes(route)) {
163086
+ filteredTraces.push(t);
163065
163087
  }
163066
163088
  }
163089
+ } else {
163090
+ filteredTraces = await listTraces(baseDir, date, { limit });
163067
163091
  }
163068
163092
  const result = filteredTraces.map((t) => ({
163069
163093
  traceId: t.traceId,
@@ -163401,7 +163425,7 @@ async function findSkillFiles(dirs) {
163401
163425
  if (entry.isDirectory()) {
163402
163426
  const skillPath = join2(dir, entry.name, "SKILL.md");
163403
163427
  try {
163404
- await stat(skillPath);
163428
+ await stat2(skillPath);
163405
163429
  files.push(skillPath);
163406
163430
  } catch {
163407
163431
  }
@@ -164857,7 +164881,7 @@ async function getSessionFromFile(filePath) {
164857
164881
  }
164858
164882
  try {
164859
164883
  const entries = await parseLogFile(filePath);
164860
- const stat12 = statSync2(filePath);
164884
+ const stat13 = statSync2(filePath);
164861
164885
  const runId = basename2(filePath, ".log");
164862
164886
  let serverId = "unknown";
164863
164887
  let serverName = "Unknown Server";
@@ -164878,13 +164902,13 @@ async function getSessionFromFile(filePath) {
164878
164902
  server_id: serverId,
164879
164903
  server_name: serverName,
164880
164904
  pid,
164881
- created_at: stat12.birthtime.toISOString(),
164882
- updated_at: stat12.mtime.toISOString(),
164905
+ created_at: stat13.birthtime.toISOString(),
164906
+ updated_at: stat13.mtime.toISOString(),
164883
164907
  ended_at: null,
164884
164908
  log_file: filePath,
164885
164909
  log_count: entries.length,
164886
164910
  error_count: errorCount,
164887
- started_at: stat12.birthtime.toISOString()
164911
+ started_at: stat13.birthtime.toISOString()
164888
164912
  };
164889
164913
  } catch {
164890
164914
  return null;
@@ -164899,8 +164923,8 @@ async function getLogSessions(serverId) {
164899
164923
  for (const file of files) {
164900
164924
  if (!file.endsWith(".log")) continue;
164901
164925
  const filePath = join2(logsDir, file);
164902
- const stat12 = statSync2(filePath);
164903
- if (!stat12.isFile()) continue;
164926
+ const stat13 = statSync2(filePath);
164927
+ if (!stat13.isFile()) continue;
164904
164928
  const session = await getSessionFromFile(filePath);
164905
164929
  if (session) {
164906
164930
  if (!serverId || session.server_id === serverId) {
@@ -165037,8 +165061,8 @@ function registerLogsRoutes(fastify2) {
165037
165061
  for (const file of files) {
165038
165062
  if (!file.endsWith(".jsonl")) continue;
165039
165063
  const filePath = join2(apiLogsDir, file);
165040
- const stat12 = statSync2(filePath);
165041
- if (!stat12.isFile()) continue;
165064
+ const stat13 = statSync2(filePath);
165065
+ if (!stat13.isFile()) continue;
165042
165066
  const runId = basename2(file, ".jsonl");
165043
165067
  const content = await readFile(filePath, "utf-8");
165044
165068
  const lines = content.split("\n").filter((l) => l.trim());
@@ -165185,8 +165209,8 @@ function isCacheValid() {
165185
165209
  return false;
165186
165210
  }
165187
165211
  try {
165188
- const stat12 = statSync2(cachePath);
165189
- const age = Date.now() - stat12.mtimeMs;
165212
+ const stat13 = statSync2(cachePath);
165213
+ const age = Date.now() - stat13.mtimeMs;
165190
165214
  return age < CACHE_TTL_MS2;
165191
165215
  } catch {
165192
165216
  return false;
@@ -165429,8 +165453,8 @@ function isCacheValid2() {
165429
165453
  return false;
165430
165454
  }
165431
165455
  try {
165432
- const stat12 = statSync2(cachePath);
165433
- const age = Date.now() - stat12.mtimeMs;
165456
+ const stat13 = statSync2(cachePath);
165457
+ const age = Date.now() - stat13.mtimeMs;
165434
165458
  return age < CACHE_TTL_MS3;
165435
165459
  } catch {
165436
165460
  return false;
@@ -165706,7 +165730,7 @@ async function getDirSize(dir) {
165706
165730
  for (const entry of entries) {
165707
165731
  const entryPath = join2(dir, entry.name);
165708
165732
  if (entry.isFile()) {
165709
- const stats = await stat(entryPath);
165733
+ const stats = await stat2(entryPath);
165710
165734
  size += stats.size;
165711
165735
  } else if (entry.isDirectory()) {
165712
165736
  size += await getDirSize(entryPath);
@@ -165736,7 +165760,7 @@ async function getLatestModTime(dir) {
165736
165760
  const entries = await readdir2(dir, { withFileTypes: true });
165737
165761
  for (const entry of entries) {
165738
165762
  const entryPath = join2(dir, entry.name);
165739
- const stats = await stat(entryPath);
165763
+ const stats = await stat2(entryPath);
165740
165764
  if (!latestTime || stats.mtime > latestTime) {
165741
165765
  latestTime = stats.mtime;
165742
165766
  }
@@ -165872,7 +165896,7 @@ async function readDirectory(dirPath) {
165872
165896
  }
165873
165897
  const entryPath = join2(dirPath, entry.name);
165874
165898
  try {
165875
- const stats = await stat(entryPath);
165899
+ const stats = await stat2(entryPath);
165876
165900
  files.push({
165877
165901
  name: entry.name,
165878
165902
  path: entryPath,
@@ -175259,8 +175283,8 @@ function serveStaticFile(page, requestedPath) {
175259
175283
  error: `File not found: ${relativePath}`
175260
175284
  };
175261
175285
  }
175262
- const stat12 = statSync2(resolvedPath);
175263
- if (!stat12.isFile()) {
175286
+ const stat13 = statSync2(resolvedPath);
175287
+ if (!stat13.isFile()) {
175264
175288
  return {
175265
175289
  success: false,
175266
175290
  error: `Not a file: ${relativePath}`
@@ -184284,7 +184308,7 @@ ${chalk22.bold("Telemetry \u7EDF\u8BA1")}:
184284
184308
  init_lib();
184285
184309
  init_update();
184286
184310
  var execAsync11 = promisify(exec);
184287
- var CURRENT_VERSION = "1.2.7";
184311
+ var CURRENT_VERSION = "1.2.8";
184288
184312
  var GITHUB_REPO2 = "LinXueyuanStdio/viben";
184289
184313
  var NPM_PACKAGE = "viben";
184290
184314
  function compareSemver(a, b) {
@@ -192912,7 +192936,7 @@ function registerCommands(program) {
192912
192936
  registerAccountCommand(program);
192913
192937
  registerAppCommand(program);
192914
192938
  }
192915
- var VERSION4 = "1.2.7";
192939
+ var VERSION4 = "1.2.8";
192916
192940
  function createProgram() {
192917
192941
  const program = new Command();
192918
192942
  program.name("viben").description("Viben - Agent Swarm \xD7 Code Evolution").version(VERSION4, "-v, --version", "Output the version number");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viben",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "CLI for Viben - Agent Swarm × Code Evolution platform",
5
5
  "keywords": [
6
6
  "viben",