viben 1.2.6 → 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 +203 -166
  2. package/dist/index.js +225 -188
  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
  }
@@ -23286,10 +23320,10 @@ var require_coerce = __commonJS2({
23286
23320
  var require_truncate = __commonJS2({
23287
23321
  "../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/truncate.js"(exports2, module2) {
23288
23322
  var parse7 = require_parse();
23289
- var constants3 = require_constants2();
23323
+ var constants4 = require_constants2();
23290
23324
  var SemVer = require_semver();
23291
23325
  var truncate2 = (version2, truncation, options) => {
23292
- if (!constants3.RELEASE_TYPES.includes(truncation)) {
23326
+ if (!constants4.RELEASE_TYPES.includes(truncation)) {
23293
23327
  return null;
23294
23328
  }
23295
23329
  const clonedVersion = cloneInputVersion(version2, options);
@@ -24282,7 +24316,7 @@ var require_subset = __commonJS2({
24282
24316
  var require_semver2 = __commonJS2({
24283
24317
  "../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/index.js"(exports2, module2) {
24284
24318
  var internalRe = require_re();
24285
- var constants3 = require_constants2();
24319
+ var constants4 = require_constants2();
24286
24320
  var SemVer = require_semver();
24287
24321
  var identifiers = require_identifiers();
24288
24322
  var parse7 = require_parse();
@@ -24366,8 +24400,8 @@ var require_semver2 = __commonJS2({
24366
24400
  re: internalRe.re,
24367
24401
  src: internalRe.src,
24368
24402
  tokens: internalRe.t,
24369
- SEMVER_SPEC_VERSION: constants3.SEMVER_SPEC_VERSION,
24370
- RELEASE_TYPES: constants3.RELEASE_TYPES,
24403
+ SEMVER_SPEC_VERSION: constants4.SEMVER_SPEC_VERSION,
24404
+ RELEASE_TYPES: constants4.RELEASE_TYPES,
24371
24405
  compareIdentifiers: identifiers.compareIdentifiers,
24372
24406
  rcompareIdentifiers: identifiers.rcompareIdentifiers
24373
24407
  };
@@ -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
  }
@@ -132466,14 +132500,14 @@ var init_session_store = __esm({
132466
132500
  return [];
132467
132501
  }
132468
132502
  const entries = await (0, import_promises.readdir)(sessionsDir, { withFileTypes: true });
132503
+ const dirEntries = entries.filter((entry) => entry.isDirectory());
132504
+ const results = await Promise.allSettled(
132505
+ dirEntries.map((entry) => this.getSession(agentId, entry.name, agentDir))
132506
+ );
132469
132507
  const sessions2 = [];
132470
- for (const entry of entries) {
132471
- if (entry.isDirectory()) {
132472
- try {
132473
- const config = await this.getSession(agentId, entry.name, agentDir);
132474
- sessions2.push(config);
132475
- } catch {
132476
- }
132508
+ for (const result of results) {
132509
+ if (result.status === "fulfilled") {
132510
+ sessions2.push(result.value);
132477
132511
  }
132478
132512
  }
132479
132513
  sessions2.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
@@ -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
  });
@@ -138694,13 +138728,14 @@ var init_service3 = __esm({
138694
138728
  return [];
138695
138729
  }
138696
138730
  const entries = await (0, import_promises.readdir)(this.baseDir, { withFileTypes: true });
138731
+ const dirEntries = entries.filter((entry) => entry.isDirectory());
138732
+ const results = await Promise.allSettled(
138733
+ dirEntries.map((entry) => this.getGroupChat(entry.name))
138734
+ );
138697
138735
  const configs = [];
138698
- for (const entry of entries) {
138699
- if (entry.isDirectory()) {
138700
- const config = await this.getGroupChat(entry.name);
138701
- if (config) {
138702
- configs.push(config);
138703
- }
138736
+ for (const result of results) {
138737
+ if (result.status === "fulfilled" && result.value !== null) {
138738
+ configs.push(result.value);
138704
138739
  }
138705
138740
  }
138706
138741
  return configs.sort(
@@ -138831,7 +138866,7 @@ var init_service3 = __esm({
138831
138866
  return this.readYaml(configPath);
138832
138867
  }
138833
138868
  /**
138834
- * List sessions for a group chat
138869
+ * List all sessions for a group chat
138835
138870
  */
138836
138871
  async listSessions(groupChatId) {
138837
138872
  const sessionsDir = this.sessionsDir(groupChatId);
@@ -138839,13 +138874,14 @@ var init_service3 = __esm({
138839
138874
  return [];
138840
138875
  }
138841
138876
  const entries = await (0, import_promises.readdir)(sessionsDir, { withFileTypes: true });
138877
+ const dirEntries = entries.filter((entry) => entry.isDirectory());
138878
+ const results = await Promise.allSettled(
138879
+ dirEntries.map((entry) => this.getSession(groupChatId, entry.name))
138880
+ );
138842
138881
  const sessions2 = [];
138843
- for (const entry of entries) {
138844
- if (entry.isDirectory()) {
138845
- const session = await this.getSession(groupChatId, entry.name);
138846
- if (session) {
138847
- sessions2.push(session);
138848
- }
138882
+ for (const result of results) {
138883
+ if (result.status === "fulfilled" && result.value !== null) {
138884
+ sessions2.push(result.value);
138849
138885
  }
138850
138886
  }
138851
138887
  return sessions2.sort(
@@ -149029,7 +149065,7 @@ var startupConfig;
149029
149065
  var gatewayStartTime;
149030
149066
  var init_health = __esm({
149031
149067
  "src/gateway/routes/health.ts"() {
149032
- VERSION3 = "1.2.6";
149068
+ VERSION3 = "1.2.8";
149033
149069
  startupConfig = null;
149034
149070
  gatewayStartTime = Date.now();
149035
149071
  }
@@ -149047,15 +149083,19 @@ async function discoverClaudeCodeSessions(workspacePath) {
149047
149083
  if (!fs20.existsSync(sessionDir)) {
149048
149084
  return [];
149049
149085
  }
149050
- const sessions2 = [];
149051
149086
  const entries = await fs20.promises.readdir(sessionDir, { withFileTypes: true });
149052
- for (const entry of entries) {
149053
- if (entry.isFile() && entry.name.endsWith(".jsonl")) {
149054
- const sessionId = entry.name.replace(".jsonl", "");
149055
- const filePath = path21.join(sessionDir, entry.name);
149056
- const stats = await fs20.promises.stat(filePath);
149057
- const name = await readFirstUserMessage(filePath);
149058
- sessions2.push({
149087
+ const jsonlEntries = entries.filter(
149088
+ (entry) => entry.isFile() && entry.name.endsWith(".jsonl")
149089
+ );
149090
+ const sessionPromises = jsonlEntries.map(async (entry) => {
149091
+ const sessionId = entry.name.replace(".jsonl", "");
149092
+ const filePath = path21.join(sessionDir, entry.name);
149093
+ try {
149094
+ const [stats, name] = await Promise.all([
149095
+ fs20.promises.stat(filePath),
149096
+ readFirstUserMessage(filePath)
149097
+ ]);
149098
+ return {
149059
149099
  id: sessionId,
149060
149100
  executor_type: "CLAUDE_CODE",
149061
149101
  workspace_path: workspacePath,
@@ -149063,10 +149103,14 @@ async function discoverClaudeCodeSessions(workspacePath) {
149063
149103
  updated_at: stats.mtime.toISOString(),
149064
149104
  name,
149065
149105
  message_count: Math.floor(stats.size / 1024)
149066
- // Rough estimate
149067
- });
149106
+ };
149107
+ } catch {
149108
+ return null;
149068
149109
  }
149069
- }
149110
+ });
149111
+ const sessions2 = (await Promise.all(sessionPromises)).filter(
149112
+ (s) => s !== null
149113
+ );
149070
149114
  sessions2.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime());
149071
149115
  return sessions2;
149072
149116
  }
@@ -149716,8 +149760,8 @@ function registerExecutorRoutes(fastify2) {
149716
149760
  const entries = fs20.readdirSync(folderPath);
149717
149761
  for (const entry of entries) {
149718
149762
  const entryPath = path21.join(folderPath, entry);
149719
- const stat12 = fs20.statSync(entryPath);
149720
- if (stat12.isDirectory()) {
149763
+ const stat13 = fs20.statSync(entryPath);
149764
+ if (stat13.isDirectory()) {
149721
149765
  const skillMdPath = path21.join(entryPath, "skill.md");
149722
149766
  if (fs20.existsSync(skillMdPath)) {
149723
149767
  const skill = parseSkillMd2(skillMdPath);
@@ -149801,8 +149845,8 @@ function registerExecutorRoutes(fastify2) {
149801
149845
  const entries = fs20.readdirSync(folderPath);
149802
149846
  for (const entry of entries) {
149803
149847
  const fullPath = path21.join(folderPath, entry);
149804
- const stat12 = fs20.statSync(fullPath);
149805
- if (stat12.isFile() && entry.endsWith(".md")) {
149848
+ const stat13 = fs20.statSync(fullPath);
149849
+ if (stat13.isFile() && entry.endsWith(".md")) {
149806
149850
  try {
149807
149851
  const content = fs20.readFileSync(fullPath, "utf-8");
149808
149852
  subagents.push(parseSubagentMd(fullPath, content));
@@ -149868,8 +149912,8 @@ function registerExecutorRoutes(fastify2) {
149868
149912
  const namespaces = fs20.readdirSync(folderPath);
149869
149913
  for (const namespace of namespaces) {
149870
149914
  const namespacePath = path21.join(folderPath, namespace);
149871
- const stat12 = fs20.statSync(namespacePath);
149872
- if (stat12.isDirectory()) {
149915
+ const stat13 = fs20.statSync(namespacePath);
149916
+ if (stat13.isDirectory()) {
149873
149917
  try {
149874
149918
  const files = fs20.readdirSync(namespacePath);
149875
149919
  for (const file of files) {
@@ -149891,7 +149935,7 @@ function registerExecutorRoutes(fastify2) {
149891
149935
  }
149892
149936
  } catch {
149893
149937
  }
149894
- } else if (stat12.isFile() && namespace.endsWith(".md")) {
149938
+ } else if (stat13.isFile() && namespace.endsWith(".md")) {
149895
149939
  const name = namespace.replace(/\.md$/, "");
149896
149940
  try {
149897
149941
  const content = fs20.readFileSync(namespacePath, "utf-8");
@@ -149991,8 +150035,8 @@ function registerExecutorRoutes(fastify2) {
149991
150035
  const entries = fs20.readdirSync(folderPath);
149992
150036
  for (const entry of entries) {
149993
150037
  const fullPath = path21.join(folderPath, entry);
149994
- const stat12 = fs20.statSync(fullPath);
149995
- if (stat12.isFile() && entry.endsWith(".md")) {
150038
+ const stat13 = fs20.statSync(fullPath);
150039
+ if (stat13.isFile() && entry.endsWith(".md")) {
149996
150040
  try {
149997
150041
  const content = fs20.readFileSync(fullPath, "utf-8");
149998
150042
  prompts.push(parsePromptMd(fullPath, content));
@@ -150861,10 +150905,10 @@ function registerAgentRoutes(fastify2, state) {
150861
150905
  const authFile = (0, import_path.join)(claudeDir, "config.json");
150862
150906
  if ((0, import_fs.existsSync)(authFile)) {
150863
150907
  try {
150864
- const stat12 = (0, import_fs.statSync)(authFile);
150908
+ const stat13 = (0, import_fs.statSync)(authFile);
150865
150909
  availability = {
150866
150910
  type: "LOGIN_DETECTED",
150867
- last_auth_timestamp: Math.floor(stat12.mtimeMs)
150911
+ last_auth_timestamp: Math.floor(stat13.mtimeMs)
150868
150912
  };
150869
150913
  } catch {
150870
150914
  availability = { type: "INSTALLATION_FOUND" };
@@ -150913,10 +150957,10 @@ function registerAgentRoutes(fastify2, state) {
150913
150957
  const openClawConfig = (0, import_path.join)(openClawDir, "openclaw.json");
150914
150958
  if ((0, import_fs.existsSync)(openClawConfig)) {
150915
150959
  try {
150916
- const stat12 = (0, import_fs.statSync)(openClawConfig);
150960
+ const stat13 = (0, import_fs.statSync)(openClawConfig);
150917
150961
  availability = {
150918
150962
  type: "LOGIN_DETECTED",
150919
- last_auth_timestamp: Math.floor(stat12.mtimeMs)
150963
+ last_auth_timestamp: Math.floor(stat13.mtimeMs)
150920
150964
  };
150921
150965
  } catch {
150922
150966
  availability = { type: "INSTALLATION_FOUND" };
@@ -159576,22 +159620,27 @@ var init_workspaces = __esm({
159576
159620
  function getDefaultWorkspacePath() {
159577
159621
  return (0, import_os.homedir)();
159578
159622
  }
159579
- function hasExecutorConfig(workspacePath, folders) {
159623
+ async function pathExists(path24) {
159624
+ try {
159625
+ await (0, import_promises.access)(path24, import_promises.constants.F_OK);
159626
+ return true;
159627
+ } catch {
159628
+ return false;
159629
+ }
159630
+ }
159631
+ async function hasExecutorConfig(workspacePath, folders) {
159580
159632
  for (const folder of folders) {
159581
- if ((0, import_fs.existsSync)((0, import_path.join)(workspacePath, folder))) {
159633
+ if (await pathExists((0, import_path.join)(workspacePath, folder))) {
159582
159634
  return true;
159583
159635
  }
159584
159636
  }
159585
159637
  return false;
159586
159638
  }
159587
- function countClaudeCodeSessions(workspacePath) {
159639
+ async function countClaudeCodeSessions(workspacePath) {
159588
159640
  const encodedPath = workspacePath.replace(/\//g, "-");
159589
159641
  const sessionsDir = (0, import_path.join)((0, import_os.homedir)(), ".claude", "projects", encodedPath);
159590
- if (!(0, import_fs.existsSync)(sessionsDir)) {
159591
- return 0;
159592
- }
159593
159642
  try {
159594
- const entries = (0, import_fs.readdirSync)(sessionsDir);
159643
+ const entries = await (0, import_promises.readdir)(sessionsDir);
159595
159644
  return entries.filter((e) => e.endsWith(".jsonl")).length;
159596
159645
  } catch {
159597
159646
  return 0;
@@ -159607,7 +159656,7 @@ function registerChatListRoutes(fastify2) {
159607
159656
  const items = [];
159608
159657
  if (includeGlobal) {
159609
159658
  const globalVibenPath = (0, import_path.join)(globalPath, ".viben", "group-chats");
159610
- if ((0, import_fs.existsSync)(globalVibenPath)) {
159659
+ if (await pathExists(globalVibenPath)) {
159611
159660
  try {
159612
159661
  const globalService = new GroupChatService(globalVibenPath);
159613
159662
  const globalChats = await globalService.listGroupChats();
@@ -159635,7 +159684,7 @@ function registerChatListRoutes(fastify2) {
159635
159684
  }
159636
159685
  if (workspacePath !== globalPath) {
159637
159686
  const workspaceVibenPath = (0, import_path.join)(workspacePath, ".viben", "group-chats");
159638
- if ((0, import_fs.existsSync)(workspaceVibenPath)) {
159687
+ if (await pathExists(workspaceVibenPath)) {
159639
159688
  try {
159640
159689
  const workspaceService = new GroupChatService(workspaceVibenPath);
159641
159690
  const workspaceChats = await workspaceService.listGroupChats();
@@ -159664,10 +159713,10 @@ function registerChatListRoutes(fastify2) {
159664
159713
  }
159665
159714
  }
159666
159715
  for (const executor of EXECUTOR_CONFIGS) {
159667
- const hasWorkspaceConfig = hasExecutorConfig(workspacePath, executor.folders);
159668
- const hasGlobalConfig = includeGlobal && hasExecutorConfig(globalPath, executor.folders);
159716
+ const hasWorkspaceConfig = await hasExecutorConfig(workspacePath, executor.folders);
159717
+ const hasGlobalConfig = includeGlobal && await hasExecutorConfig(globalPath, executor.folders);
159669
159718
  if (hasWorkspaceConfig || hasGlobalConfig) {
159670
- const sessionCount = executor.id === "CLAUDE_CODE" ? countClaudeCodeSessions(workspacePath) : 0;
159719
+ const sessionCount = executor.id === "CLAUDE_CODE" ? await countClaudeCodeSessions(workspacePath) : 0;
159671
159720
  items.push({
159672
159721
  id: executor.id,
159673
159722
  item_type: "executor",
@@ -159713,30 +159762,28 @@ function registerChatListRoutes(fastify2) {
159713
159762
  } catch {
159714
159763
  }
159715
159764
  const vibenAgentsDir = (0, import_path.join)(workspacePath, ".viben", "agents");
159716
- if ((0, import_fs.existsSync)(vibenAgentsDir)) {
159717
- try {
159718
- const entries = (0, import_fs.readdirSync)(vibenAgentsDir, { withFileTypes: true });
159719
- for (const entry of entries) {
159720
- if (entry.isDirectory()) {
159721
- const agentId = entry.name;
159722
- if (!items.some((i) => i.id === agentId)) {
159723
- items.push({
159724
- id: agentId,
159725
- item_type: "agent",
159726
- name: entry.name,
159727
- source: "workspace",
159728
- workspace_path: workspacePath,
159729
- icon_type: "viben",
159730
- is_global: false,
159731
- metadata: {
159732
- agent_type: "viben"
159733
- }
159734
- });
159735
- }
159765
+ try {
159766
+ const entries = await (0, import_promises.readdir)(vibenAgentsDir, { withFileTypes: true });
159767
+ for (const entry of entries) {
159768
+ if (entry.isDirectory()) {
159769
+ const agentId = entry.name;
159770
+ if (!items.some((i) => i.id === agentId)) {
159771
+ items.push({
159772
+ id: agentId,
159773
+ item_type: "agent",
159774
+ name: entry.name,
159775
+ source: "workspace",
159776
+ workspace_path: workspacePath,
159777
+ icon_type: "viben",
159778
+ is_global: false,
159779
+ metadata: {
159780
+ agent_type: "viben"
159781
+ }
159782
+ });
159736
159783
  }
159737
159784
  }
159738
- } catch {
159739
159785
  }
159786
+ } catch {
159740
159787
  }
159741
159788
  items.sort((a, b) => {
159742
159789
  if (!a.last_active && !b.last_active) return 0;
@@ -163017,16 +163064,7 @@ function registerTelemetryRoutes(fastify2) {
163017
163064
  fastify2.get("/api/telemetry/dates", async (_request, reply) => {
163018
163065
  try {
163019
163066
  const dates = listTraceDates(baseDir);
163020
- const result = await Promise.all(
163021
- dates.map(async (date) => {
163022
- const traces = await listTraces(baseDir, date);
163023
- return {
163024
- date,
163025
- count: traces.length,
163026
- totalSize: traces.reduce((sum, t) => sum + t.size, 0)
163027
- };
163028
- })
163029
- );
163067
+ const result = dates.map((date) => ({ date }));
163030
163068
  return reply.send(result);
163031
163069
  } catch (error) {
163032
163070
  return reply.status(500).send({
@@ -163039,27 +163077,26 @@ function registerTelemetryRoutes(fastify2) {
163039
163077
  "/api/telemetry/traces",
163040
163078
  async (request, reply) => {
163041
163079
  try {
163042
- const { date = (/* @__PURE__ */ new Date()).toISOString().split("T")[0], route } = request.query;
163043
- const traces = await listTraces(baseDir, date);
163044
- 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;
163045
163084
  if (route) {
163085
+ const traces = await listTraces(baseDir, date);
163046
163086
  filteredTraces = [];
163047
163087
  for (const t of traces) {
163048
- const filePath = path21.join(baseDir, "traces", date, `${t.traceId}.jsonl`);
163049
- try {
163050
- const spans = await loadTrace(filePath);
163051
- const matches = spans.some((span) => {
163052
- const httpTarget = span.attributes["http.target"];
163053
- const httpRoute = span.attributes["http.route"];
163054
- const httpUrl = span.attributes["http.url"];
163055
- return httpTarget?.includes(route) || httpRoute?.includes(route) || httpUrl?.includes(route);
163056
- });
163057
- if (matches) {
163058
- filteredTraces.push(t);
163059
- }
163060
- } 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);
163061
163096
  }
163062
163097
  }
163098
+ } else {
163099
+ filteredTraces = await listTraces(baseDir, date, { limit });
163063
163100
  }
163064
163101
  const result = filteredTraces.map((t) => ({
163065
163102
  traceId: t.traceId,
@@ -164853,7 +164890,7 @@ async function getSessionFromFile(filePath) {
164853
164890
  }
164854
164891
  try {
164855
164892
  const entries = await parseLogFile(filePath);
164856
- const stat12 = (0, import_fs.statSync)(filePath);
164893
+ const stat13 = (0, import_fs.statSync)(filePath);
164857
164894
  const runId = (0, import_path.basename)(filePath, ".log");
164858
164895
  let serverId = "unknown";
164859
164896
  let serverName = "Unknown Server";
@@ -164874,13 +164911,13 @@ async function getSessionFromFile(filePath) {
164874
164911
  server_id: serverId,
164875
164912
  server_name: serverName,
164876
164913
  pid,
164877
- created_at: stat12.birthtime.toISOString(),
164878
- updated_at: stat12.mtime.toISOString(),
164914
+ created_at: stat13.birthtime.toISOString(),
164915
+ updated_at: stat13.mtime.toISOString(),
164879
164916
  ended_at: null,
164880
164917
  log_file: filePath,
164881
164918
  log_count: entries.length,
164882
164919
  error_count: errorCount,
164883
- started_at: stat12.birthtime.toISOString()
164920
+ started_at: stat13.birthtime.toISOString()
164884
164921
  };
164885
164922
  } catch {
164886
164923
  return null;
@@ -164895,8 +164932,8 @@ async function getLogSessions(serverId) {
164895
164932
  for (const file of files) {
164896
164933
  if (!file.endsWith(".log")) continue;
164897
164934
  const filePath = (0, import_path.join)(logsDir, file);
164898
- const stat12 = (0, import_fs.statSync)(filePath);
164899
- if (!stat12.isFile()) continue;
164935
+ const stat13 = (0, import_fs.statSync)(filePath);
164936
+ if (!stat13.isFile()) continue;
164900
164937
  const session = await getSessionFromFile(filePath);
164901
164938
  if (session) {
164902
164939
  if (!serverId || session.server_id === serverId) {
@@ -165033,8 +165070,8 @@ function registerLogsRoutes(fastify2) {
165033
165070
  for (const file of files) {
165034
165071
  if (!file.endsWith(".jsonl")) continue;
165035
165072
  const filePath = (0, import_path.join)(apiLogsDir, file);
165036
- const stat12 = (0, import_fs.statSync)(filePath);
165037
- if (!stat12.isFile()) continue;
165073
+ const stat13 = (0, import_fs.statSync)(filePath);
165074
+ if (!stat13.isFile()) continue;
165038
165075
  const runId = (0, import_path.basename)(file, ".jsonl");
165039
165076
  const content = await (0, import_promises.readFile)(filePath, "utf-8");
165040
165077
  const lines = content.split("\n").filter((l) => l.trim());
@@ -165181,8 +165218,8 @@ function isCacheValid() {
165181
165218
  return false;
165182
165219
  }
165183
165220
  try {
165184
- const stat12 = (0, import_fs.statSync)(cachePath);
165185
- const age = Date.now() - stat12.mtimeMs;
165221
+ const stat13 = (0, import_fs.statSync)(cachePath);
165222
+ const age = Date.now() - stat13.mtimeMs;
165186
165223
  return age < CACHE_TTL_MS2;
165187
165224
  } catch {
165188
165225
  return false;
@@ -165425,8 +165462,8 @@ function isCacheValid2() {
165425
165462
  return false;
165426
165463
  }
165427
165464
  try {
165428
- const stat12 = (0, import_fs.statSync)(cachePath);
165429
- const age = Date.now() - stat12.mtimeMs;
165465
+ const stat13 = (0, import_fs.statSync)(cachePath);
165466
+ const age = Date.now() - stat13.mtimeMs;
165430
165467
  return age < CACHE_TTL_MS3;
165431
165468
  } catch {
165432
165469
  return false;
@@ -175255,8 +175292,8 @@ function serveStaticFile(page, requestedPath) {
175255
175292
  error: `File not found: ${relativePath}`
175256
175293
  };
175257
175294
  }
175258
- const stat12 = (0, import_fs.statSync)(resolvedPath);
175259
- if (!stat12.isFile()) {
175295
+ const stat13 = (0, import_fs.statSync)(resolvedPath);
175296
+ if (!stat13.isFile()) {
175260
175297
  return {
175261
175298
  success: false,
175262
175299
  error: `Not a file: ${relativePath}`
@@ -184280,7 +184317,7 @@ ${import_chalk.default.bold("Telemetry \u7EDF\u8BA1")}:
184280
184317
  init_lib();
184281
184318
  init_update();
184282
184319
  var execAsync11 = (0, import_util.promisify)(import_child_process.exec);
184283
- var CURRENT_VERSION = "1.2.6";
184320
+ var CURRENT_VERSION = "1.2.8";
184284
184321
  var GITHUB_REPO2 = "LinXueyuanStdio/viben";
184285
184322
  var NPM_PACKAGE = "viben";
184286
184323
  function compareSemver(a, b) {
@@ -192908,7 +192945,7 @@ function registerCommands(program) {
192908
192945
  registerAccountCommand(program);
192909
192946
  registerAppCommand(program);
192910
192947
  }
192911
- var VERSION4 = "1.2.6";
192948
+ var VERSION4 = "1.2.8";
192912
192949
  function createProgram() {
192913
192950
  const program = new import_commander.Command();
192914
192951
  program.name("viben").description("Viben - Agent Swarm \xD7 Code Evolution").version(VERSION4, "-v, --version", "Output the version number");