agentflow-dashboard 0.7.1 → 0.8.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.
package/dist/cli.cjs CHANGED
@@ -37,10 +37,84 @@ var os = __toESM(require("os"), 1);
37
37
  var path3 = __toESM(require("path"), 1);
38
38
 
39
39
  // src/server.ts
40
+ var import_node_child_process = require("child_process");
40
41
  var fs2 = __toESM(require("fs"), 1);
41
42
  var import_node_http = require("http");
42
43
  var path2 = __toESM(require("path"), 1);
43
44
  var import_node_url = require("url");
45
+
46
+ // src/config.ts
47
+ var import_node_fs = require("fs");
48
+ var import_node_os = require("os");
49
+ var import_node_path = require("path");
50
+ var EMPTY_CONFIG = {};
51
+ function expandTilde(p) {
52
+ if (p.startsWith("~/") || p === "~") {
53
+ return (0, import_node_path.join)((0, import_node_os.homedir)(), p.slice(1));
54
+ }
55
+ return p;
56
+ }
57
+ function loadConfig(explicitPath) {
58
+ const candidates = [];
59
+ if (explicitPath) {
60
+ candidates.push((0, import_node_path.resolve)(explicitPath));
61
+ }
62
+ if (process.env.AGENTFLOW_CONFIG) {
63
+ candidates.push((0, import_node_path.resolve)(process.env.AGENTFLOW_CONFIG));
64
+ }
65
+ candidates.push((0, import_node_path.resolve)("agentflow.config.json"));
66
+ candidates.push((0, import_node_path.join)((0, import_node_os.homedir)(), ".config", "agentflow", "config.json"));
67
+ for (const candidate of candidates) {
68
+ if (!(0, import_node_fs.existsSync)(candidate)) continue;
69
+ try {
70
+ const raw = (0, import_node_fs.readFileSync)(candidate, "utf-8");
71
+ const parsed = JSON.parse(raw);
72
+ const cleaned = stripCommentKeys(parsed);
73
+ console.log(`Loaded config: ${candidate}`);
74
+ return { config: cleaned, configPath: candidate };
75
+ } catch (err) {
76
+ console.warn(`Warning: Failed to load config from ${candidate}: ${err.message}`);
77
+ console.warn("Continuing with empty defaults.");
78
+ return { config: EMPTY_CONFIG, configPath: null };
79
+ }
80
+ }
81
+ return { config: EMPTY_CONFIG, configPath: null };
82
+ }
83
+ function stripCommentKeys(obj) {
84
+ if (Array.isArray(obj)) return obj.map(stripCommentKeys);
85
+ if (obj && typeof obj === "object") {
86
+ const result = {};
87
+ for (const [key, value] of Object.entries(obj)) {
88
+ if (key.startsWith("//")) continue;
89
+ result[key] = stripCommentKeys(value);
90
+ }
91
+ return result;
92
+ }
93
+ return obj;
94
+ }
95
+ function getAliases(config) {
96
+ return config.aliases ?? {};
97
+ }
98
+ function getSkipFiles(config) {
99
+ return config.skipFiles ?? [];
100
+ }
101
+ function getSkipDirectories(config) {
102
+ return config.skipDirectories ?? [];
103
+ }
104
+ function getDiscoveryPaths(config) {
105
+ return (config.discoveryPaths ?? []).map(expandTilde);
106
+ }
107
+ function getSystemdServices(config) {
108
+ return config.systemdServices ?? [];
109
+ }
110
+ function getAgentDetection(config) {
111
+ return config.agentDetection ?? {};
112
+ }
113
+ function getProcessPreference(config) {
114
+ return config.processPreference ?? null;
115
+ }
116
+
117
+ // src/server.ts
44
118
  var import_agentflow_core3 = require("agentflow-core");
45
119
  var import_express = __toESM(require("express"), 1);
46
120
  var import_ws = require("ws");
@@ -74,17 +148,17 @@ var AgentFlowAdapter = class {
74
148
  };
75
149
 
76
150
  // src/adapters/openclaw.ts
77
- var import_node_fs = require("fs");
78
- var import_node_path = require("path");
151
+ var import_node_fs2 = require("fs");
152
+ var import_node_path2 = require("path");
79
153
  var jobCache = /* @__PURE__ */ new Map();
80
154
  function loadJobs(openclawDir) {
81
155
  const cached = jobCache.get(openclawDir);
82
156
  if (cached) return cached;
83
- const jobsPath = (0, import_node_path.join)(openclawDir, "cron", "jobs.json");
157
+ const jobsPath = (0, import_node_path2.join)(openclawDir, "cron", "jobs.json");
84
158
  const map = /* @__PURE__ */ new Map();
85
159
  try {
86
- if ((0, import_node_fs.existsSync)(jobsPath)) {
87
- const data = JSON.parse((0, import_node_fs.readFileSync)(jobsPath, "utf-8"));
160
+ if ((0, import_node_fs2.existsSync)(jobsPath)) {
161
+ const data = JSON.parse((0, import_node_fs2.readFileSync)(jobsPath, "utf-8"));
88
162
  const jobs = Array.isArray(data) ? data : data.jobs ?? [];
89
163
  for (const job of jobs) {
90
164
  if (job.id) map.set(job.id, job);
@@ -96,19 +170,19 @@ function loadJobs(openclawDir) {
96
170
  return map;
97
171
  }
98
172
  function findOpenClawRoot(filePath) {
99
- let dir = (0, import_node_path.dirname)(filePath);
173
+ let dir = (0, import_node_path2.dirname)(filePath);
100
174
  for (let i = 0; i < 5; i++) {
101
- if ((0, import_node_fs.existsSync)((0, import_node_path.join)(dir, "cron", "jobs.json")) || (0, import_node_path.basename)(dir) === ".openclaw") {
175
+ if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(dir, "cron", "jobs.json")) || (0, import_node_path2.basename)(dir) === ".openclaw") {
102
176
  return dir;
103
177
  }
104
- dir = (0, import_node_path.dirname)(dir);
178
+ dir = (0, import_node_path2.dirname)(dir);
105
179
  }
106
180
  return null;
107
181
  }
108
182
  var OpenClawAdapter = class {
109
183
  name = "openclaw";
110
184
  detect(dirPath) {
111
- return (0, import_node_fs.existsSync)((0, import_node_path.join)(dirPath, "cron", "jobs.json")) || dirPath.includes(".openclaw") || (0, import_node_fs.existsSync)((0, import_node_path.join)(dirPath, "cron", "runs"));
185
+ return (0, import_node_fs2.existsSync)((0, import_node_path2.join)(dirPath, "cron", "jobs.json")) || dirPath.includes(".openclaw") || (0, import_node_fs2.existsSync)((0, import_node_path2.join)(dirPath, "cron", "runs"));
112
186
  }
113
187
  canHandle(filePath) {
114
188
  if (!filePath.endsWith(".jsonl")) return false;
@@ -117,7 +191,7 @@ var OpenClawAdapter = class {
117
191
  parse(filePath) {
118
192
  const traces = [];
119
193
  try {
120
- const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
194
+ const content = (0, import_node_fs2.readFileSync)(filePath, "utf-8");
121
195
  const root = findOpenClawRoot(filePath);
122
196
  const jobs = root ? loadJobs(root) : /* @__PURE__ */ new Map();
123
197
  for (const line of content.split("\n")) {
@@ -129,7 +203,7 @@ var OpenClawAdapter = class {
129
203
  continue;
130
204
  }
131
205
  if (entry.action !== "finished") continue;
132
- const jobId = entry.jobId ?? (0, import_node_path.basename)(filePath, ".jsonl");
206
+ const jobId = entry.jobId ?? (0, import_node_path2.basename)(filePath, ".jsonl");
133
207
  const job = jobs.get(jobId);
134
208
  const jobName = (job == null ? void 0 : job.name) ?? jobId;
135
209
  const startTime = entry.runAtMs ?? entry.ts;
@@ -181,8 +255,8 @@ var OpenClawAdapter = class {
181
255
  };
182
256
 
183
257
  // src/adapters/otel.ts
184
- var import_node_fs2 = require("fs");
185
- var import_node_path2 = require("path");
258
+ var import_node_fs3 = require("fs");
259
+ var import_node_path3 = require("path");
186
260
  var SPAN_TYPE_MAP = {
187
261
  "gen_ai.chat": "llm",
188
262
  "gen_ai.completion": "llm",
@@ -289,8 +363,8 @@ var OTelAdapter = class {
289
363
  name = "otel";
290
364
  detect(dirPath) {
291
365
  try {
292
- if ((0, import_node_fs2.existsSync)((0, import_node_path2.join)(dirPath, "otel-traces"))) return true;
293
- const files = (0, import_node_fs2.readdirSync)(dirPath);
366
+ if ((0, import_node_fs3.existsSync)((0, import_node_path3.join)(dirPath, "otel-traces"))) return true;
367
+ const files = (0, import_node_fs3.readdirSync)(dirPath);
294
368
  return files.some((f) => f.endsWith(".otlp.json"));
295
369
  } catch {
296
370
  return false;
@@ -301,7 +375,7 @@ var OTelAdapter = class {
301
375
  }
302
376
  parse(filePath) {
303
377
  try {
304
- const content = (0, import_node_fs2.readFileSync)(filePath, "utf-8");
378
+ const content = (0, import_node_fs3.readFileSync)(filePath, "utf-8");
305
379
  const payload = JSON.parse(content);
306
380
  const traces = parseOtlpPayload(payload);
307
381
  for (const t of traces) t.filePath = filePath;
@@ -343,9 +417,7 @@ function extractSource(agentId) {
343
417
  const colonIdx = agentId.indexOf(":");
344
418
  if (colonIdx > 0 && colonIdx < 20) {
345
419
  const prefix = agentId.slice(0, colonIdx);
346
- if (["openclaw", "otel", "langchain", "crewai", "mastra"].includes(prefix)) {
347
- return { source: prefix, localId: agentId.slice(colonIdx + 1) };
348
- }
420
+ return { source: prefix, localId: agentId.slice(colonIdx + 1) };
349
421
  }
350
422
  return { source: "agentflow", localId: agentId };
351
423
  }
@@ -376,16 +448,20 @@ function deduplicateAgents(agents) {
376
448
  for (const a of tagged) {
377
449
  const suffix = extractSuffix(a.localId);
378
450
  if (!suffix) continue;
379
- const group = suffixGroups.get(suffix) ?? [];
451
+ const key = `${a.source}:${suffix}`;
452
+ const group = suffixGroups.get(key) ?? [];
380
453
  group.push(a);
381
- suffixGroups.set(suffix, group);
454
+ suffixGroups.set(key, group);
382
455
  }
383
456
  const mergedIds = /* @__PURE__ */ new Set();
384
457
  const mergedAgents = [];
385
- for (const [suffix, group] of suffixGroups) {
458
+ for (const [_key, group] of suffixGroups) {
459
+ const suffix = extractSuffix(group[0].localId);
386
460
  if (group.length < 2) continue;
387
461
  const prefixes = new Set(group.map((a) => a.localId.split("-")[0]));
388
462
  if (prefixes.size < 2) continue;
463
+ const longPrefixes = [...prefixes].filter((p) => p !== suffix && p.length > 2);
464
+ if (longPrefixes.length >= 2) continue;
389
465
  const merged = {
390
466
  agentId: group[0].source === "agentflow" ? suffix : `${group[0].source}:${suffix}`,
391
467
  displayName: suffix,
@@ -433,10 +509,7 @@ function groupAgents(agents) {
433
509
  }
434
510
  const SOURCE_DISPLAY = {
435
511
  agentflow: "AgentFlow",
436
- openclaw: "OpenClaw",
437
- otel: "OpenTelemetry",
438
- langchain: "LangChain",
439
- crewai: "CrewAI"
512
+ otel: "OpenTelemetry"
440
513
  };
441
514
  const groups = [];
442
515
  for (const [source, sourceAgents] of sourceMap) {
@@ -782,10 +855,6 @@ function getUniversalNodeStatus(activity) {
782
855
  return "completed";
783
856
  }
784
857
  function openClawSessionIdToAgent(sessionId) {
785
- if (sessionId.startsWith("janitor-")) return "vault-janitor";
786
- if (sessionId.startsWith("curator-")) return "vault-curator";
787
- if (sessionId.startsWith("distiller-")) return "vault-distiller";
788
- if (sessionId.startsWith("main-")) return "alfred-main";
789
858
  const firstSegment = sessionId.split("-")[0];
790
859
  if (firstSegment) return firstSegment;
791
860
  return "openclaw";
@@ -798,19 +867,81 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
798
867
  tracesDir;
799
868
  dataDirs;
800
869
  allWatchDirs;
870
+ maxAgeMs;
871
+ userConfig;
801
872
  constructor(tracesDirOrOptions) {
802
873
  super();
874
+ const defaultMaxAgeMs = 48 * 60 * 60 * 1e3;
875
+ const envHours = process.env.AGENTFLOW_TRACE_WINDOW_HOURS;
876
+ const envMaxAgeMs = envHours ? parseFloat(envHours) * 60 * 60 * 1e3 : void 0;
803
877
  if (typeof tracesDirOrOptions === "string") {
804
878
  this.tracesDir = path.resolve(tracesDirOrOptions);
805
879
  this.dataDirs = [];
880
+ this.maxAgeMs = envMaxAgeMs ?? defaultMaxAgeMs;
881
+ this.userConfig = {};
806
882
  } else {
807
883
  this.tracesDir = path.resolve(tracesDirOrOptions.tracesDir);
808
884
  this.dataDirs = (tracesDirOrOptions.dataDirs || []).map((d) => path.resolve(d));
809
- }
885
+ this.maxAgeMs = envMaxAgeMs ?? tracesDirOrOptions.maxAgeMs ?? defaultMaxAgeMs;
886
+ this.userConfig = tracesDirOrOptions.userConfig ?? {};
887
+ }
888
+ this.skipFiles = /* @__PURE__ */ new Set([
889
+ ..._TraceWatcher.STRUCTURAL_SKIP_FILES,
890
+ ...getSkipFiles(this.userConfig)
891
+ ]);
892
+ this.userSkipDirs = new Set(getSkipDirectories(this.userConfig));
810
893
  this.allWatchDirs = [this.tracesDir, ...this.dataDirs];
811
894
  this.ensureTracesDir();
812
895
  this.loadExistingFiles();
896
+ this.archiveOldTraces();
813
897
  this.startWatching();
898
+ setInterval(() => this.archiveOldTraces(), 6 * 60 * 60 * 1e3);
899
+ }
900
+ /** Move trace files older than maxAgeMs into archive/YYYY-MM/ subdirectories. */
901
+ archiveOldTraces() {
902
+ const cutoff = Date.now() - this.maxAgeMs;
903
+ let archived = 0;
904
+ for (const dir of this.allWatchDirs) {
905
+ if (!fs.existsSync(dir)) continue;
906
+ try {
907
+ this.archiveDirectory(dir, cutoff, 0);
908
+ } catch (error) {
909
+ console.warn(`Archival error in ${dir}:`, error.message);
910
+ }
911
+ }
912
+ }
913
+ archiveDirectory(dir, cutoff, depth) {
914
+ if (depth > 10) return 0;
915
+ if (path.basename(dir) === "archive") return 0;
916
+ let archived = 0;
917
+ try {
918
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
919
+ for (const entry of entries) {
920
+ if (entry.name.startsWith(".") || entry.name === "archive" || this.userSkipDirs.has(entry.name)) continue;
921
+ const fullPath = path.join(dir, entry.name);
922
+ if (entry.isDirectory()) {
923
+ archived += this.archiveDirectory(fullPath, cutoff, depth + 1);
924
+ continue;
925
+ }
926
+ if (!entry.isFile() || !this.isSupportedFile(entry.name)) continue;
927
+ try {
928
+ const stats = fs.statSync(fullPath);
929
+ if (stats.mtimeMs >= cutoff) continue;
930
+ const mtime = new Date(stats.mtimeMs);
931
+ const yearMonth = `${mtime.getFullYear()}-${String(mtime.getMonth() + 1).padStart(2, "0")}`;
932
+ const archiveDir = path.join(this.tracesDir, "archive", yearMonth);
933
+ fs.mkdirSync(archiveDir, { recursive: true });
934
+ const dest = path.join(archiveDir, entry.name);
935
+ fs.renameSync(fullPath, dest);
936
+ const key = this.traceKey(fullPath);
937
+ this.traces.delete(key);
938
+ archived++;
939
+ } catch {
940
+ }
941
+ }
942
+ } catch {
943
+ }
944
+ return archived;
814
945
  }
815
946
  ensureTracesDir() {
816
947
  if (!fs.existsSync(this.tracesDir)) {
@@ -843,9 +974,17 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
843
974
  const entries = fs.readdirSync(dir, { withFileTypes: true });
844
975
  for (const entry of entries) {
845
976
  if (entry.name.startsWith(".")) continue;
977
+ if (entry.name === "archive") continue;
978
+ if (this.userSkipDirs.has(entry.name)) continue;
846
979
  const fullPath = path.join(dir, entry.name);
847
980
  if (entry.isFile()) {
848
981
  if (this.isSupportedFile(entry.name)) {
982
+ try {
983
+ const mtime = fs.statSync(fullPath).mtimeMs;
984
+ if (Date.now() - mtime > this.maxAgeMs) continue;
985
+ } catch {
986
+ continue;
987
+ }
849
988
  if (this.loadFile(fullPath)) {
850
989
  fileCount++;
851
990
  }
@@ -863,8 +1002,8 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
863
1002
  isSupportedFile(filename) {
864
1003
  return filename.endsWith(".json") || filename.endsWith(".jsonl") || filename.endsWith(".log") || filename.endsWith(".trace");
865
1004
  }
866
- /** File names that are config/state, not tracesskip them. */
867
- static SKIP_FILES = /* @__PURE__ */ new Set([
1005
+ /** Structural file names that are never trace dataalways skipped. */
1006
+ static STRUCTURAL_SKIP_FILES = /* @__PURE__ */ new Set([
868
1007
  "workers.json",
869
1008
  "package.json",
870
1009
  "package-lock.json",
@@ -879,6 +1018,10 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
879
1018
  "update-check.json",
880
1019
  "exec-approvals.json"
881
1020
  ]);
1021
+ /** Skip files = structural + user config */
1022
+ skipFiles;
1023
+ /** Skip directories from user config */
1024
+ userSkipDirs;
882
1025
  static SKIP_SUFFIXES = [
883
1026
  "-state.json",
884
1027
  "-config.json",
@@ -890,7 +1033,7 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
890
1033
  /** Load a file using the adapter registry, falling back to built-in parsing. */
891
1034
  loadFile(filePath) {
892
1035
  const filename = path.basename(filePath);
893
- if (_TraceWatcher.SKIP_FILES.has(filename)) return false;
1036
+ if (this.skipFiles.has(filename)) return false;
894
1037
  if (_TraceWatcher.SKIP_SUFFIXES.some((s) => filename.endsWith(s))) return false;
895
1038
  const adapter = findAdapter(filePath);
896
1039
  if (adapter && adapter.name !== "agentflow") {
@@ -1067,43 +1210,26 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
1067
1210
  }
1068
1211
  return traces;
1069
1212
  }
1070
- /**
1071
- * Normalise agent identifiers so that the same worker is never shown
1072
- * under two different names (e.g. "vault-curator" vs "openclaw-vault-curator").
1073
- *
1074
- * Canonical names: alfred-main, vault-curator, vault-janitor,
1075
- * vault-distiller, vault-surveyor
1076
- */
1077
- static AGENT_ALIASES = {
1078
- "openclaw-main": "alfred-main",
1079
- "openclaw-vault-curator": "vault-curator",
1080
- "openclaw-vault-janitor": "vault-janitor",
1081
- "openclaw-vault-distiller": "vault-distiller",
1082
- "openclaw-vault-surveyor": "vault-surveyor",
1083
- "alfred-curator": "vault-curator",
1084
- "alfred-janitor": "vault-janitor",
1085
- "alfred-distiller": "vault-distiller",
1086
- "alfred-surveyor": "vault-surveyor",
1087
- curator: "vault-curator",
1088
- janitor: "vault-janitor",
1089
- distiller: "vault-distiller",
1090
- surveyor: "vault-surveyor"
1091
- };
1213
+ /** Normalise agent identifiers using config-driven alias map. */
1092
1214
  normaliseAgentId(raw) {
1093
- return _TraceWatcher.AGENT_ALIASES[raw] ?? raw;
1215
+ const aliases = getAliases(this.userConfig);
1216
+ return aliases[raw] ?? raw;
1094
1217
  }
1095
1218
  detectAgentIdentifier(activity, _filename, filePath) {
1096
1219
  if (activity.agent_id) {
1097
- const agentId = activity.agent_id;
1098
- if (agentId === "main" && filePath.includes(".alfred/")) return this.normaliseAgentId("alfred-main");
1099
- return this.normaliseAgentId(agentId);
1220
+ return this.normaliseAgentId(activity.agent_id);
1100
1221
  }
1101
1222
  const pathAgent = this.extractAgentFromPath(filePath);
1102
- if (filePath.includes(".alfred/") && !pathAgent.startsWith("alfred-")) {
1223
+ const detection = getAgentDetection(this.userConfig);
1224
+ if (detection.filePatterns) {
1103
1225
  const basename3 = path.basename(filePath, path.extname(filePath));
1104
- if (basename3.match(/^(janitor|curator|distiller|surveyor|alfred)$/)) {
1105
- const raw = basename3 === "alfred" ? "alfred" : `alfred-${basename3}`;
1106
- return this.normaliseAgentId(raw);
1226
+ for (const [pattern, template] of Object.entries(detection.filePatterns)) {
1227
+ const re = new RegExp(`^(${pattern})$`);
1228
+ const match = basename3.match(re);
1229
+ if (match) {
1230
+ const resolved = template.replace("${match}", match[1]);
1231
+ return this.normaliseAgentId(resolved);
1232
+ }
1107
1233
  }
1108
1234
  }
1109
1235
  return this.normaliseAgentId(pathAgent);
@@ -1111,20 +1237,23 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
1111
1237
  extractAgentFromPath(filePath) {
1112
1238
  const filename = path.basename(filePath, path.extname(filePath));
1113
1239
  const pathParts = filePath.split(path.sep);
1114
- if (filePath.includes(".openclaw/")) {
1115
- const agentsIndex = pathParts.lastIndexOf("agents");
1116
- if (agentsIndex !== -1 && agentsIndex + 1 < pathParts.length) {
1117
- return `openclaw-${pathParts[agentsIndex + 1]}`;
1118
- }
1119
- if (filename.startsWith("openclaw-")) {
1120
- return "openclaw-gateway";
1240
+ const detection = getAgentDetection(this.userConfig);
1241
+ let pathPrefix = "";
1242
+ if (detection.pathPatterns) {
1243
+ for (const [pathSubstring, agentId] of Object.entries(detection.pathPatterns)) {
1244
+ if (filePath.includes(pathSubstring)) {
1245
+ pathPrefix = agentId;
1246
+ break;
1247
+ }
1121
1248
  }
1122
- return "openclaw";
1123
1249
  }
1124
- if (filePath.includes(".alfred/") || filename.includes("alfred")) {
1125
- return "alfred";
1250
+ const agentsIndex = pathParts.lastIndexOf("agents");
1251
+ if (agentsIndex !== -1 && agentsIndex + 1 < pathParts.length) {
1252
+ const agentName = pathParts[agentsIndex + 1];
1253
+ return pathPrefix ? `${pathPrefix}-${agentName}` : agentName;
1126
1254
  }
1127
- for (const part of pathParts.reverse()) {
1255
+ if (pathPrefix) return pathPrefix;
1256
+ for (const part of [...pathParts].reverse()) {
1128
1257
  if (part.match(/agent|worker|service|daemon|bot|ai|llm/i)) {
1129
1258
  return part;
1130
1259
  }
@@ -1459,19 +1588,22 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
1459
1588
  const parentDir = path.basename(path.dirname(filePath));
1460
1589
  const grandParentDir = path.basename(path.dirname(path.dirname(filePath)));
1461
1590
  const greatGrandParentDir = path.basename(path.dirname(path.dirname(path.dirname(filePath))));
1462
- let agentId;
1591
+ let agentName;
1463
1592
  if (parentDir === "sessions" && greatGrandParentDir === "agents") {
1464
- agentId = grandParentDir;
1593
+ agentName = grandParentDir;
1465
1594
  } else if (grandParentDir === "agents") {
1466
- agentId = parentDir;
1467
- } else if (parentDir === "runs" && grandParentDir === "cron") {
1468
- agentId = "openclaw-cron";
1595
+ agentName = parentDir;
1469
1596
  } else {
1470
- agentId = parentDir;
1471
- }
1472
- if (filePath.includes(".alfred/") || filePath.includes("alfred")) {
1473
- if (!agentId.startsWith("alfred-")) {
1474
- agentId = `alfred-${agentId}`;
1597
+ agentName = parentDir;
1598
+ }
1599
+ let agentId = agentName;
1600
+ const detection = getAgentDetection(this.userConfig);
1601
+ if (detection.pathPatterns) {
1602
+ for (const [pathSubstring, prefix] of Object.entries(detection.pathPatterns)) {
1603
+ if (filePath.includes(pathSubstring)) {
1604
+ agentId = `${prefix}-${agentName}`;
1605
+ break;
1606
+ }
1475
1607
  }
1476
1608
  }
1477
1609
  const modelEvent = rawEvents.find((e) => e.type === "model_change");
@@ -1760,6 +1892,7 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
1760
1892
  edges: [],
1761
1893
  events: [],
1762
1894
  startTime,
1895
+ status,
1763
1896
  agentId,
1764
1897
  trigger,
1765
1898
  name: rootName,
@@ -1880,8 +2013,12 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
1880
2013
  // Ignore git directories
1881
2014
  /\.vscode/,
1882
2015
  // Ignore vscode
1883
- /\.idea/
2016
+ /\.idea/,
1884
2017
  // Ignore idea
2018
+ /\/archive\//,
2019
+ // Ignore archived trace files
2020
+ // Ignore user-configured skip directories
2021
+ ...getSkipDirectories(this.userConfig).map((d) => new RegExp(`/${d}/`))
1885
2022
  ],
1886
2023
  persistent: true,
1887
2024
  ignoreInitial: true,
@@ -1935,29 +2072,42 @@ var TraceWatcher = class _TraceWatcher extends import_node_events.EventEmitter {
1935
2072
  });
1936
2073
  }
1937
2074
  getTrace(filename) {
2075
+ const candidates = [];
1938
2076
  const exact = this.traces.get(filename);
1939
- if (exact) return exact;
2077
+ if (exact) candidates.push(exact);
1940
2078
  if (filename.includes("::")) {
1941
2079
  const [fname, startTimeStr] = filename.split("::");
1942
2080
  const startTime = Number(startTimeStr);
1943
2081
  if (fname && !Number.isNaN(startTime)) {
1944
2082
  for (const trace of this.traces.values()) {
1945
2083
  if (trace.filename === fname && trace.startTime === startTime) {
1946
- return trace;
2084
+ candidates.push(trace);
1947
2085
  }
1948
2086
  }
1949
2087
  }
1950
2088
  }
1951
2089
  for (const prefix of ["openclaw:", "otel:", ""]) {
1952
2090
  const prefixed = this.traces.get(prefix + filename);
1953
- if (prefixed) return prefixed;
2091
+ if (prefixed) candidates.push(prefixed);
1954
2092
  }
1955
2093
  for (const [key, trace] of this.traces) {
1956
2094
  if (trace.filename === filename || trace.id === filename || key.endsWith(filename)) {
1957
- return trace;
2095
+ candidates.push(trace);
2096
+ }
2097
+ }
2098
+ if (candidates.length === 0) return void 0;
2099
+ if (candidates.length === 1) return candidates[0];
2100
+ let best = candidates[0];
2101
+ let bestNodeCount = best.nodes instanceof Map ? best.nodes.size : Object.keys(best.nodes ?? {}).length;
2102
+ for (let i = 1; i < candidates.length; i++) {
2103
+ const c = candidates[i];
2104
+ const nc = c.nodes instanceof Map ? c.nodes.size : Object.keys(c.nodes ?? {}).length;
2105
+ if (nc > bestNodeCount) {
2106
+ best = c;
2107
+ bestNodeCount = nc;
1958
2108
  }
1959
2109
  }
1960
- return void 0;
2110
+ return best;
1961
2111
  }
1962
2112
  getTracesByAgent(agentId) {
1963
2113
  return this.getAllTraces().filter((trace) => trace.agentId === agentId);
@@ -2019,12 +2169,15 @@ function serializeTrace(trace) {
2019
2169
  var DashboardServer = class {
2020
2170
  constructor(config) {
2021
2171
  this.config = config;
2022
- const home = process.env.HOME ?? "/home/trader";
2023
- const configPath = path2.join(home, ".agentflow/dashboard-config.json");
2172
+ const { config: userCfg, configPath: cfgPath } = loadConfig(config.configPath);
2173
+ this.userConfig = userCfg;
2174
+ this.configPath = cfgPath;
2175
+ const home = process.env.HOME ?? process.env.USERPROFILE ?? "/tmp";
2176
+ const dashConfigPath = path2.join(home, ".agentflow/dashboard-config.json");
2024
2177
  if (!config.dataDirs) config.dataDirs = [];
2025
2178
  try {
2026
- if (fs2.existsSync(configPath)) {
2027
- const saved = JSON.parse(fs2.readFileSync(configPath, "utf-8"));
2179
+ if (fs2.existsSync(dashConfigPath)) {
2180
+ const saved = JSON.parse(fs2.readFileSync(dashConfigPath, "utf-8"));
2028
2181
  const extraDirs = saved.extraDirs ?? [];
2029
2182
  for (const d of extraDirs) {
2030
2183
  if (!config.dataDirs.includes(d)) config.dataDirs.push(d);
@@ -2032,21 +2185,15 @@ var DashboardServer = class {
2032
2185
  }
2033
2186
  } catch {
2034
2187
  }
2035
- const autoDiscoverPaths = [
2036
- path2.join(home, ".openclaw/cron/runs"),
2037
- path2.join(home, ".openclaw/workspace/traces"),
2038
- path2.join(home, ".openclaw/subagents"),
2039
- path2.join(home, ".openclaw/agents/main/sessions"),
2040
- path2.join(home, ".agentflow/traces")
2041
- ];
2042
- for (const p of autoDiscoverPaths) {
2188
+ for (const p of getDiscoveryPaths(this.userConfig)) {
2043
2189
  if (fs2.existsSync(p) && !config.dataDirs.includes(p)) {
2044
2190
  config.dataDirs.push(p);
2045
2191
  }
2046
2192
  }
2047
2193
  this.watcher = new TraceWatcher({
2048
2194
  tracesDir: config.tracesDir,
2049
- dataDirs: config.dataDirs
2195
+ dataDirs: config.dataDirs,
2196
+ userConfig: this.userConfig
2050
2197
  });
2051
2198
  this.stats = new AgentStats();
2052
2199
  this.knowledgeStore = (0, import_agentflow_core3.createKnowledgeStore)({
@@ -2081,6 +2228,8 @@ var DashboardServer = class {
2081
2228
  ts: 0
2082
2229
  };
2083
2230
  knowledgeStore;
2231
+ userConfig;
2232
+ configPath;
2084
2233
  setupExpress() {
2085
2234
  if (this.config.enableCors) {
2086
2235
  this.app.use((_req, res, next) => {
@@ -2092,18 +2241,35 @@ var DashboardServer = class {
2092
2241
  next();
2093
2242
  });
2094
2243
  }
2095
- const clientDir = path2.join(__dirname, "../dist/client");
2244
+ const pkgDir = path2.join(__dirname, "..");
2245
+ const clientDir = path2.join(pkgDir, "dist/client");
2246
+ const clientIndex = path2.join(clientDir, "index.html");
2247
+ const srcDir = path2.join(pkgDir, "src/client");
2248
+ const needsBuild = !fs2.existsSync(clientIndex) || fs2.existsSync(srcDir) && this.isClientStale(srcDir, clientDir);
2249
+ if (needsBuild) {
2250
+ try {
2251
+ console.log("Building dashboard client...");
2252
+ (0, import_node_child_process.execSync)("npm run build:client", { cwd: pkgDir, stdio: "inherit", timeout: 3e4 });
2253
+ } catch (err) {
2254
+ console.warn("Client build failed \u2014 dashboard UI may be stale:", err.message);
2255
+ }
2256
+ }
2096
2257
  if (fs2.existsSync(clientDir)) {
2097
2258
  this.app.use(import_express.default.static(clientDir));
2098
2259
  }
2099
- const publicDir = path2.join(__dirname, "../public");
2100
- if (fs2.existsSync(publicDir)) {
2101
- this.app.use("/v1", import_express.default.static(publicDir));
2102
- }
2103
- this.app.get("/api/traces", (_req, res) => {
2260
+ this.app.get("/api/traces", (req, res) => {
2104
2261
  try {
2105
- const traces = this.watcher.getAllTraces().map(serializeTrace);
2106
- res.json(traces);
2262
+ const limit = Math.min(Math.max(parseInt(req.query.limit, 10) || 50, 1), 200);
2263
+ const cursor = req.query.cursor ? parseFloat(req.query.cursor) : void 0;
2264
+ let allTraces = this.watcher.getAllTraces();
2265
+ if (cursor) {
2266
+ allTraces = allTraces.filter((t) => (t.lastModified || t.startTime) < cursor);
2267
+ }
2268
+ const page = allTraces.slice(0, limit);
2269
+ const serialized = page.map(serializeTrace);
2270
+ const lastTrace = page[page.length - 1];
2271
+ const nextCursor = page.length === limit && lastTrace ? lastTrace.lastModified || lastTrace.startTime : null;
2272
+ res.json({ traces: serialized, nextCursor });
2107
2273
  } catch (_error) {
2108
2274
  res.status(500).json({ error: "Failed to load traces" });
2109
2275
  }
@@ -2394,6 +2560,102 @@ var DashboardServer = class {
2394
2560
  res.status(500).json({ error: "Failed to load agent statistics" });
2395
2561
  }
2396
2562
  });
2563
+ this.app.get("/api/soma/report", (_req, res) => {
2564
+ const somaVault = this.config.somaVault;
2565
+ if (!somaVault) {
2566
+ return res.json({ available: false, teaser: true });
2567
+ }
2568
+ try {
2569
+ const reportPath = path2.join(somaVault, "..", "soma-report.json");
2570
+ if (!fs2.existsSync(reportPath)) {
2571
+ return res.json({ available: false, teaser: false, message: "No report file yet. Run soma watch." });
2572
+ }
2573
+ const report = JSON.parse(fs2.readFileSync(reportPath, "utf-8"));
2574
+ res.json(report);
2575
+ } catch (error) {
2576
+ console.error("Soma report error:", error);
2577
+ res.json({ available: false, teaser: false, message: "Failed to read report" });
2578
+ }
2579
+ });
2580
+ this.app.get("/api/soma/governance", (_req, res) => {
2581
+ const somaVault = this.config.somaVault;
2582
+ if (!somaVault) {
2583
+ return res.json({ available: false });
2584
+ }
2585
+ try {
2586
+ const reportPath = path2.join(somaVault, "..", "soma-report.json");
2587
+ if (!fs2.existsSync(reportPath)) {
2588
+ return res.json({ available: false, message: "No report file. Run soma report." });
2589
+ }
2590
+ const report = JSON.parse(fs2.readFileSync(reportPath, "utf-8"));
2591
+ res.json({
2592
+ available: true,
2593
+ layers: report.layers ?? { archive: 0, working: 0, emerging: 0, canon: 0 },
2594
+ governance: report.governance ?? { pending: 0, promoted: 0, rejected: 0 },
2595
+ insights: (report.insights ?? []).filter((i) => i.layer === "emerging" && i.proposal_status === "pending"),
2596
+ canon: (report.insights ?? []).filter((i) => i.layer === "canon"),
2597
+ generatedAt: report.generatedAt
2598
+ });
2599
+ } catch (error) {
2600
+ console.error("Soma governance error:", error);
2601
+ res.status(500).json({ available: false, message: "Failed to read governance data" });
2602
+ }
2603
+ });
2604
+ const sanitizeArg = (s) => s.replace(/[^a-zA-Z0-9_\-.:]/g, "");
2605
+ const sanitizeReason = (s) => s.replace(/["`$\\]/g, "").slice(0, 500);
2606
+ this.app.post("/api/soma/governance/promote", (req, res) => {
2607
+ var _a;
2608
+ const somaVault = this.config.somaVault;
2609
+ if (!somaVault) return res.status(400).json({ error: "Soma vault not configured" });
2610
+ const { entryId } = req.body ?? {};
2611
+ if (!entryId) return res.status(400).json({ error: "entryId required" });
2612
+ try {
2613
+ const { execSync: execSync2 } = require("child_process");
2614
+ const safeId = sanitizeArg(String(entryId));
2615
+ const result = execSync2(`npx soma governance promote ${safeId} --vault "${somaVault}"`, {
2616
+ encoding: "utf-8",
2617
+ timeout: 1e4
2618
+ });
2619
+ res.json({ success: true, message: result.trim() });
2620
+ } catch (error) {
2621
+ res.status(400).json({ error: ((_a = error.stderr) == null ? void 0 : _a.trim()) || error.message });
2622
+ }
2623
+ });
2624
+ this.app.post("/api/soma/governance/reject", (req, res) => {
2625
+ var _a;
2626
+ const somaVault = this.config.somaVault;
2627
+ if (!somaVault) return res.status(400).json({ error: "Soma vault not configured" });
2628
+ const { entryId, reason } = req.body ?? {};
2629
+ if (!entryId || !reason) return res.status(400).json({ error: "entryId and reason required" });
2630
+ try {
2631
+ const { execSync: execSync2 } = require("child_process");
2632
+ const safeId = sanitizeArg(String(entryId));
2633
+ const safeReason = sanitizeReason(String(reason));
2634
+ const result = execSync2(`npx soma governance reject ${safeId} "${safeReason}" --vault "${somaVault}"`, {
2635
+ encoding: "utf-8",
2636
+ timeout: 1e4
2637
+ });
2638
+ res.json({ success: true, message: result.trim() });
2639
+ } catch (error) {
2640
+ res.status(400).json({ error: ((_a = error.stderr) == null ? void 0 : _a.trim()) || error.message });
2641
+ }
2642
+ });
2643
+ this.app.get("/api/soma/governance/evidence/:id", (req, res) => {
2644
+ var _a;
2645
+ const somaVault = this.config.somaVault;
2646
+ if (!somaVault) return res.status(400).json({ error: "Soma vault not configured" });
2647
+ try {
2648
+ const { execSync: execSync2 } = require("child_process");
2649
+ const safeId = sanitizeArg(String(req.params.id));
2650
+ const result = execSync2(`npx soma governance show ${safeId} --vault "${somaVault}"`, {
2651
+ encoding: "utf-8",
2652
+ timeout: 1e4
2653
+ });
2654
+ res.json({ available: true, output: result.trim() });
2655
+ } catch (error) {
2656
+ res.status(404).json({ error: ((_a = error.stderr) == null ? void 0 : _a.trim()) || error.message });
2657
+ }
2658
+ });
2397
2659
  this.app.get("/api/process-health", (_req, res) => {
2398
2660
  var _a, _b;
2399
2661
  try {
@@ -2406,7 +2668,14 @@ var DashboardServer = class {
2406
2668
  path2.dirname(this.config.tracesDir),
2407
2669
  ...this.config.dataDirs || []
2408
2670
  ];
2409
- const configs = (0, import_agentflow_core3.discoverAllProcessConfigs)(discoveryDirs);
2671
+ let configs = (0, import_agentflow_core3.discoverAllProcessConfigs)(discoveryDirs);
2672
+ const pref = getProcessPreference(this.userConfig);
2673
+ if (pref) {
2674
+ const hasPreferred = configs.some((c) => c.processName === pref.prefer);
2675
+ if (hasPreferred) {
2676
+ configs = configs.filter((c) => c.processName !== pref.over);
2677
+ }
2678
+ }
2410
2679
  if (configs.length === 0) {
2411
2680
  return res.json(null);
2412
2681
  }
@@ -2496,29 +2765,26 @@ var DashboardServer = class {
2496
2765
  ...extraDirs
2497
2766
  ];
2498
2767
  const discovered = [];
2499
- try {
2500
- const { execSync } = require("child_process");
2501
- const raw = execSync(
2502
- "systemctl --user show --property=ExecStart --no-pager alfred.service openclaw-gateway.service 2>/dev/null",
2503
- { encoding: "utf8", timeout: 5e3 }
2504
- );
2505
- for (const line of raw.split("\n")) {
2506
- const match = line.match(/path=([^\s;]+)/);
2507
- if (match == null ? void 0 : match[1]) {
2508
- const dir = path2.dirname(match[1]);
2509
- if (fs2.existsSync(dir)) discovered.push(dir);
2768
+ const svcNames = getSystemdServices(this.userConfig);
2769
+ if (svcNames.length > 0) {
2770
+ try {
2771
+ const { execSync: execSync2 } = require("child_process");
2772
+ const raw = execSync2(
2773
+ `systemctl --user show --property=ExecStart --no-pager ${svcNames.join(" ")} 2>/dev/null`,
2774
+ { encoding: "utf8", timeout: 5e3 }
2775
+ );
2776
+ for (const line of raw.split("\n")) {
2777
+ const match = line.match(/path=([^\s;]+)/);
2778
+ if (match == null ? void 0 : match[1]) {
2779
+ const dir = path2.dirname(match[1]);
2780
+ if (fs2.existsSync(dir)) discovered.push(dir);
2781
+ }
2510
2782
  }
2783
+ } catch {
2511
2784
  }
2512
- } catch {
2513
2785
  }
2514
2786
  const commonPaths = [
2515
- path2.join(home, ".alfred/traces"),
2516
- path2.join(home, ".alfred/data"),
2517
- path2.join(home, ".openclaw/workspace/traces"),
2518
- path2.join(home, ".openclaw/subagents"),
2519
- path2.join(home, ".openclaw/cron/runs"),
2520
- path2.join(home, ".openclaw/cron"),
2521
- path2.join(home, ".openclaw/agents/main/sessions"),
2787
+ ...getDiscoveryPaths(this.userConfig),
2522
2788
  path2.join(home, ".agentflow/traces")
2523
2789
  ];
2524
2790
  for (const p of commonPaths) {
@@ -2622,18 +2888,10 @@ var DashboardServer = class {
2622
2888
  this.app.get("/ready", (_req, res) => {
2623
2889
  res.json({ status: "ready" });
2624
2890
  });
2625
- this.app.get("/v1/*", (_req, res) => {
2626
- const legacyIndex = path2.join(__dirname, "../public/index.html");
2627
- if (fs2.existsSync(legacyIndex)) {
2628
- res.sendFile(legacyIndex);
2629
- } else {
2630
- res.status(404).send("Legacy dashboard not found");
2631
- }
2632
- });
2633
2891
  this.app.get("*", (_req, res) => {
2634
- const clientIndex = path2.join(__dirname, "../dist/client/index.html");
2635
- if (fs2.existsSync(clientIndex)) {
2636
- res.sendFile(clientIndex);
2892
+ const clientIndex2 = path2.join(__dirname, "../dist/client/index.html");
2893
+ if (fs2.existsSync(clientIndex2)) {
2894
+ res.sendFile(clientIndex2);
2637
2895
  } else {
2638
2896
  res.status(404).send("Dashboard not found - public files may not be built");
2639
2897
  }
@@ -2880,24 +3138,49 @@ var DashboardServer = class {
2880
3138
  });
2881
3139
  }
2882
3140
  async start() {
2883
- return new Promise((resolve4) => {
3141
+ return new Promise((resolve5) => {
2884
3142
  const host = this.config.host || "localhost";
2885
3143
  this.server.listen(this.config.port, host, () => {
2886
3144
  console.log(`AgentFlow Dashboard running at http://${host}:${this.config.port}`);
2887
3145
  console.log(`Watching traces in: ${this.config.tracesDir}`);
2888
- resolve4();
3146
+ resolve5();
2889
3147
  });
2890
3148
  });
2891
3149
  }
3150
+ /** Check if any src/client file is newer than the built bundle. */
3151
+ isClientStale(srcDir, distDir) {
3152
+ try {
3153
+ const distIndex = path2.join(distDir, "index.html");
3154
+ if (!fs2.existsSync(distIndex)) return true;
3155
+ const distMtime = fs2.statSync(distIndex).mtimeMs;
3156
+ const check = (dir) => {
3157
+ for (const entry of fs2.readdirSync(dir, { withFileTypes: true })) {
3158
+ const full = path2.join(dir, entry.name);
3159
+ if (entry.isDirectory()) {
3160
+ if (check(full)) return true;
3161
+ } else if (fs2.statSync(full).mtimeMs > distMtime) {
3162
+ return true;
3163
+ }
3164
+ }
3165
+ return false;
3166
+ };
3167
+ return check(srcDir);
3168
+ } catch {
3169
+ return false;
3170
+ }
3171
+ }
2892
3172
  async stop() {
2893
- return new Promise((resolve4) => {
3173
+ return new Promise((resolve5) => {
2894
3174
  this.watcher.stop();
2895
3175
  this.server.close(() => {
2896
3176
  console.log("Dashboard server stopped");
2897
- resolve4();
3177
+ resolve5();
2898
3178
  });
2899
3179
  });
2900
3180
  }
3181
+ getConfigPath() {
3182
+ return this.configPath;
3183
+ }
2901
3184
  getStats() {
2902
3185
  return this.stats.getGlobalStats();
2903
3186
  }
@@ -2910,7 +3193,7 @@ if (import_meta.url === `file://${process.argv[1]}`) {
2910
3193
  }
2911
3194
 
2912
3195
  // src/cli.ts
2913
- var VERSION = "0.4.0";
3196
+ var VERSION = "0.8.0";
2914
3197
  function getLanAddress() {
2915
3198
  const interfaces = os.networkInterfaces();
2916
3199
  for (const name of Object.keys(interfaces)) {
@@ -2922,7 +3205,7 @@ function getLanAddress() {
2922
3205
  }
2923
3206
  return null;
2924
3207
  }
2925
- function printBanner(config, traceCount, stats) {
3208
+ function printBanner(config, traceCount, stats, configPath) {
2926
3209
  var _a;
2927
3210
  const lan = getLanAddress();
2928
3211
  const host = config.host || "localhost";
@@ -2938,26 +3221,23 @@ function printBanner(config, traceCount, stats) {
2938
3221
 
2939
3222
  See your agents think.
2940
3223
 
2941
- \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
2942
- \u2502 \u{1F916} Agents \u2502 TRACE FILES \u2502 \u{1F4CA} AgentFlow \u2502 SHOWS YOU \u2502 \u{1F310} Your browser \u2502
2943
- \u2502 Execute tasks, \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500> \u2502 Reads traces, \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500> \u2502 Interactive \u2502
2944
- \u2502 write JSON \u2502 \u2502 builds graphs, \u2502 \u2502 graph, timeline, \u2502
2945
- \u2502 trace files. \u2502 \u2502 serves dashboard.\u2502 \u2502 metrics, health. \u2502
2946
- \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
2947
-
2948
- Runs locally. Your data never leaves your machine.
2949
-
2950
- Tabs: \u{1F3AF} Graph \xB7 \u23F1\uFE0F Timeline \xB7 \u{1F4CA} Metrics \xB7 \u{1F6E0}\uFE0F Process Health \xB7 \u26A0\uFE0F Errors
2951
-
2952
3224
  Traces: ${config.tracesDir}${((_a = config.dataDirs) == null ? void 0 : _a.length) ? `
2953
3225
  Data dirs: ${config.dataDirs.join("\n ")}` : ""}
2954
3226
  Loaded: ${traceCount} traces \xB7 ${stats.totalAgents} agents \xB7 ${stats.totalExecutions} executions
2955
3227
  Success: ${stats.globalSuccessRate.toFixed(1)}%${stats.activeAgents > 0 ? ` \xB7 ${stats.activeAgents} active now` : ""}
3228
+ Config: ${configPath ?? "none (using defaults)"}
2956
3229
  CORS: ${config.enableCors ? "enabled" : "disabled"}
2957
3230
  WebSocket: live updates enabled
3231
+ Window: ${process.env.AGENTFLOW_TRACE_WINDOW_HOURS ?? "48"}h (set AGENTFLOW_TRACE_WINDOW_HOURS to change)
2958
3232
 
2959
3233
  \u2192 http://localhost:${port}${isPublic && lan ? `
2960
3234
  \u2192 http://${lan}:${port} (LAN)` : ""}
3235
+
3236
+ Views: Agent Profile \xB7 Execution Detail \xB7 Governance
3237
+ Tabs: Flame Chart \xB7 Agent Flow \xB7 Metrics \xB7 Dependencies
3238
+ State Machine \xB7 Summary \xB7 Transcript
3239
+
3240
+ Runs locally. Your data never leaves your machine.
2961
3241
  `);
2962
3242
  }
2963
3243
  async function startDashboard() {
@@ -2995,6 +3275,12 @@ async function startDashboard() {
2995
3275
  case "--collector-token":
2996
3276
  config.collectorAuthToken = args[++i];
2997
3277
  break;
3278
+ case "--soma-vault":
3279
+ config.somaVault = args[++i];
3280
+ break;
3281
+ case "--config":
3282
+ config.configPath = args[++i];
3283
+ break;
2998
3284
  case "--help":
2999
3285
  printHelp();
3000
3286
  process.exit(0);
@@ -3006,6 +3292,9 @@ async function startDashboard() {
3006
3292
  if (process.env.AGENTFLOW_NO_COLLECTOR === "true") {
3007
3293
  config.enableCollector = false;
3008
3294
  }
3295
+ if (!config.somaVault && process.env.SOMA_VAULT) {
3296
+ config.somaVault = process.env.SOMA_VAULT;
3297
+ }
3009
3298
  const tracesPath = path3.resolve(config.tracesDir);
3010
3299
  if (!fs3.existsSync(tracesPath)) {
3011
3300
  fs3.mkdirSync(tracesPath, { recursive: true });
@@ -3027,7 +3316,7 @@ async function startDashboard() {
3027
3316
  setTimeout(() => {
3028
3317
  const stats = dashboard.getStats();
3029
3318
  const traces = dashboard.getTraces();
3030
- printBanner(config, traces.length, stats);
3319
+ printBanner(config, traces.length, stats, dashboard.getConfigPath());
3031
3320
  }, 1500);
3032
3321
  } catch (error) {
3033
3322
  console.error("\u274C Failed to start dashboard:", error);
@@ -3036,7 +3325,7 @@ async function startDashboard() {
3036
3325
  }
3037
3326
  function printHelp() {
3038
3327
  console.log(`
3039
- \u{1F4CA} AgentFlow Dashboard v${VERSION} \u2014 See your agents think.
3328
+ AgentFlow Dashboard v${VERSION} \u2014 See your agents think.
3040
3329
 
3041
3330
  Usage:
3042
3331
  agentflow-dashboard [options]
@@ -3047,22 +3336,34 @@ Options:
3047
3336
  -t, --traces <path> Traces directory (default: ./traces)
3048
3337
  -h, --host <address> Host address (default: localhost)
3049
3338
  --data-dir <path> Extra data directory for process discovery (repeatable)
3339
+ --config <path> Path to agentflow.config.json (aliases, skip files, etc.)
3340
+ --soma-vault <path> SOMA vault directory for intelligence data
3050
3341
  --cors Enable CORS headers
3051
3342
  --no-collector Disable OTLP trace collector (POST /v1/traces)
3052
3343
  --collector-token <tok> Require auth token for collector (or set AGENTFLOW_COLLECTOR_TOKEN)
3053
3344
  --help Show this help message
3054
3345
 
3055
- Examples:
3056
- agentflow-dashboard --traces ./traces --host 0.0.0.0 --cors
3057
- agentflow-dashboard -p 8080 -t /var/log/agentflow
3058
- agentflow-dashboard --traces ./traces --data-dir ./workers --data-dir ./cron
3346
+ Config file:
3347
+ The dashboard loads agentflow.config.json for agent aliases, skip files,
3348
+ discovery paths, and systemd services. Resolution order:
3349
+ 1. --config flag
3350
+ 2. AGENTFLOW_CONFIG env var
3351
+ 3. ./agentflow.config.json
3352
+ 4. ~/.config/agentflow/config.json
3353
+
3354
+ See agentflow.config.example.json for a complete reference.
3059
3355
 
3060
- Tabs:
3061
- \u{1F3AF} Graph Interactive Cytoscape.js execution graph
3062
- \u23F1\uFE0F Timeline Waterfall view of node durations
3063
- \u{1F4CA} Metrics Success rates, durations, node breakdown
3064
- \u{1F6E0}\uFE0F Process Health PID files, systemd, workers, orphans
3065
- \u26A0\uFE0F Errors Failed and hung nodes with metadata
3356
+ Environment:
3357
+ AGENTFLOW_CONFIG Path to config file
3358
+ AGENTFLOW_TRACE_WINDOW_HOURS Max age of traces to load (default: 48)
3359
+ AGENTFLOW_COLLECTOR_TOKEN Auth token for OTLP collector
3360
+ AGENTFLOW_NO_COLLECTOR=true Disable OTLP collector
3361
+ SOMA_VAULT SOMA vault directory
3362
+
3363
+ Examples:
3364
+ agentflow-dashboard --traces ./traces --host 0.0.0.0
3365
+ agentflow-dashboard --traces ./traces --config ./agentflow.config.json
3366
+ agentflow-dashboard -p 8080 -t /var/log/agentflow --cors
3066
3367
  `);
3067
3368
  }
3068
3369
  // Annotate the CommonJS export names for ESM import in node: