@swestash/agent-lens 0.17.5 → 0.17.6

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.
@@ -3628,12 +3628,7 @@ function deriveFileChanges(db, dirty) {
3628
3628
  for (const row of rows) {
3629
3629
  if (row.status === "error")
3630
3630
  continue;
3631
- let input = null;
3632
- try {
3633
- input = row.input_json ? JSON.parse(row.input_json) : null;
3634
- } catch {
3635
- input = null;
3636
- }
3631
+ const input = parseStored(row.input_json, "filechanges: tool_calls.input_json");
3637
3632
  if (!input)
3638
3633
  continue;
3639
3634
  const p = proj.get(row.session_id);
@@ -4094,15 +4089,8 @@ function linkSkillVersions(db, sessionIds) {
4094
4089
  if (!c2.skill_name)
4095
4090
  continue;
4096
4091
  const key = skillNameKey(c2.skill_name);
4097
- let args = null;
4098
- try {
4099
- args = c2.input_json ? JSON.parse(c2.input_json).args ?? null : null;
4100
- if (typeof args === "string")
4101
- args = args.trim() || null;
4102
- else if (args != null)
4103
- args = JSON.stringify(args);
4104
- } catch {
4105
- }
4092
+ const raw = parseStored(c2.input_json, "skill versions: tool_calls.input_json")?.args;
4093
+ const args = typeof raw === "string" ? raw.trim() || null : raw != null ? JSON.stringify(raw) : null;
4106
4094
  const arr = pending.get(key) ?? [];
4107
4095
  arr.push({ id: c2.id, args });
4108
4096
  pending.set(key, arr);
@@ -4407,9 +4395,6 @@ import { readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as
4407
4395
  import { join as join8 } from "node:path";
4408
4396
 
4409
4397
  // ../ingest/dist/redact.js
4410
- function parseExcludes(csv) {
4411
- return (csv ?? "").split(",").map((s) => s.trim()).filter(Boolean).map(encodeProjectPath);
4412
- }
4413
4398
  function isExcludedArchivePath(filePath, excluded) {
4414
4399
  return excluded.some((e) => filePath.includes(`/projects/${e}/`));
4415
4400
  }
@@ -4774,7 +4759,7 @@ function runIngest(argv = process.argv.slice(2)) {
4774
4759
  const sources = loadSources();
4775
4760
  const now2 = (/* @__PURE__ */ new Date()).toISOString();
4776
4761
  const excludePaths = loadExcludes();
4777
- const excludedDirs = parseExcludes(excludePaths.join(","));
4762
+ const excludedDirs = excludePaths.map(encodeProjectPath);
4778
4763
  const pruned = args.full ? 0 : pruneExcluded(db, excludePaths);
4779
4764
  if (args.full)
4780
4765
  db.exec("PRAGMA foreign_keys = OFF");
@@ -5074,7 +5059,7 @@ function listSessions(db, f) {
5074
5059
  ${whereSql}`;
5075
5060
  const ORDER = {
5076
5061
  started: "s.started_at",
5077
- title: "COALESCE(s.ai_title, s.slug)",
5062
+ title: "COALESCE(NULLIF(s.ai_title, ''), s.slug)",
5078
5063
  turns: "s.turn_count",
5079
5064
  duration: "s.duration_ms",
5080
5065
  errors: "tool_error_count",
@@ -5664,7 +5649,7 @@ function listFindings(db, f) {
5664
5649
  };
5665
5650
  const findings = queryAll(db, `SELECT f.id, f.session_id, f.tool_call_id, f.event_uuid, f.turn_id, f.rule_id, f.category,
5666
5651
  f.framework_ref, f.severity, f.title, f.evidence, tc.tool_name,
5667
- COALESCE(s.ai_title, s.slug) AS session_title, s.source_id, s.is_sidechain,
5652
+ COALESCE(NULLIF(s.ai_title, ''), s.slug) AS session_title, s.source_id, s.is_sidechain,
5668
5653
  s.started_at, p.path AS project_path, s.project_id ${triageCols}
5669
5654
  FROM findings f
5670
5655
  JOIN sessions s ON s.id = f.session_id
@@ -5857,12 +5842,12 @@ function dashboardOverview(db, f) {
5857
5842
  GROUP BY t.model`, ...uw.params);
5858
5843
  const tokens = zeroSplit();
5859
5844
  let cost = 0;
5860
- const unpriced2 = [];
5845
+ const used = [];
5861
5846
  for (const u of usage) {
5862
5847
  addUsage(tokens, u);
5863
5848
  cost += costForUsage(u.model, usageForCost(u));
5864
- if (u.model && !rateForModel(u.model) && (u.i || u.o || u.cw || u.cr))
5865
- unpriced2.push(u.model);
5849
+ if (u.i || u.o || u.cw || u.cr)
5850
+ used.push(u.model);
5866
5851
  }
5867
5852
  const totalTokens = tokens.input + tokens.output + tokens.cache_creation + tokens.cache_read;
5868
5853
  const tnw = withModel(w, "tn.model");
@@ -5886,7 +5871,7 @@ function dashboardOverview(db, f) {
5886
5871
  total_tokens: totalTokens,
5887
5872
  cache_read_ratio: totalTokens ? tokens.cache_read / totalTokens : 0,
5888
5873
  cost: Number(cost.toFixed(4)),
5889
- unpriced_models: [...new Set(unpriced2)].sort(),
5874
+ unpriced_models: unpricedModels(used),
5890
5875
  turn_duration_ms: turnDur,
5891
5876
  session_duration_ms: sessDur,
5892
5877
  workflows: workflowAgg(db, f)
@@ -5904,9 +5889,12 @@ function chooseBucket(db, f) {
5904
5889
  return "week";
5905
5890
  return "month";
5906
5891
  }
5892
+ function bucketOf(db, f, param) {
5893
+ return param === "day" || param === "week" || param === "month" ? param : chooseBucket(db, f);
5894
+ }
5907
5895
  var bucketExpr = (b, col) => b === "day" ? `strftime('%Y-%m-%d', ${col})` : b === "week" ? `strftime('%Y-W%W', ${col})` : `strftime('%Y-%m', ${col})`;
5908
5896
  function dashboardTimeseries(db, f, bucketParam) {
5909
- const bucket = bucketParam === "day" || bucketParam === "week" || bucketParam === "month" ? bucketParam : chooseBucket(db, f);
5897
+ const bucket = bucketOf(db, f, bucketParam);
5910
5898
  const w = sessionWhere(f);
5911
5899
  const expr = bucketExpr(bucket, "s.started_at");
5912
5900
  const byBucket = /* @__PURE__ */ new Map();
@@ -5969,7 +5957,7 @@ function modelBreakdown(db, w) {
5969
5957
  FROM token_usage t JOIN sessions s ON s.id = t.session_id ${uw.sql} GROUP BY t.model`, ...uw.params)) {
5970
5958
  const key = canonicalModel(u.model);
5971
5959
  cost.set(key, (cost.get(key) ?? 0) + costForUsage(u.model, usageForCost(u)));
5972
- if (!rateForModel(u.model))
5960
+ if ((u.i || u.o || u.cw || u.cr) && u.model !== SYNTHETIC_MODEL && !rateForModel(u.model))
5973
5961
  unpriced2.add(key);
5974
5962
  }
5975
5963
  return modelRows.map((u) => ({
@@ -6060,7 +6048,6 @@ function dashboardBreakdowns(db, f) {
6060
6048
  error_types: errorTypeBreakdown(db, w)
6061
6049
  };
6062
6050
  }
6063
- var bucketFor = (b) => b === "day" || b === "week" || b === "month" ? b : "day";
6064
6051
  function dashboardTime(db, f, bucketParam) {
6065
6052
  const w = sessionWhere(f);
6066
6053
  const mw = mainOnly(w);
@@ -6079,7 +6066,7 @@ function dashboardTime(db, f, bucketParam) {
6079
6066
  return {
6080
6067
  burn_hours,
6081
6068
  turn_hours,
6082
- latency: modelLatency(db, mw, bucketParam ? bucketFor(bucketParam) : chooseBucket(db, f)),
6069
+ latency: modelLatency(db, mw, bucketOf(db, f, bucketParam)),
6083
6070
  review: reviewLatency(db, mw)
6084
6071
  };
6085
6072
  }
@@ -6142,7 +6129,7 @@ function reviewLatency(db, mw) {
6142
6129
  }
6143
6130
  function dashboardAudit(db, f, bucketParam) {
6144
6131
  const w = sessionWhere(f);
6145
- const bucket = bucketParam ? bucketFor(bucketParam) : chooseBucket(db, f);
6132
+ const bucket = bucketOf(db, f, bucketParam);
6146
6133
  return {
6147
6134
  bucket,
6148
6135
  edit_reliability: editReliability(db, w),
@@ -6202,6 +6189,9 @@ function findingsOverTime(db, w, bucket) {
6202
6189
  import { existsSync as existsSync7, mkdirSync as mkdirSync5 } from "node:fs";
6203
6190
  import { join as join10 } from "node:path";
6204
6191
  var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "[::1]"]);
6192
+ function isLoopbackBind(host) {
6193
+ return LOOPBACK_HOSTS.has(host) || LOOPBACK_HOSTS.has(`[${host}]`);
6194
+ }
6205
6195
  function originAllowed(origin) {
6206
6196
  if (!origin)
6207
6197
  return true;
@@ -6702,7 +6692,7 @@ async function startServer(overrides = {}) {
6702
6692
  const { host, port } = resolveServerConfig({ port: overrides.port, host: overrides.host });
6703
6693
  const pricing = installPricing();
6704
6694
  const webDist = resolveWebDist(here, repoRoot);
6705
- if (host !== "127.0.0.1" && host !== "localhost" && !process.env.AGENT_LENS_ALLOW_NONLOCAL) {
6695
+ if (!isLoopbackBind(host) && !process.env.AGENT_LENS_ALLOW_NONLOCAL) {
6706
6696
  console.error(`agent-lens-server: refusing to bind non-loopback host '${host}' (privacy). Set AGENT_LENS_ALLOW_NONLOCAL=1 to override.`);
6707
6697
  process.exit(1);
6708
6698
  }
@@ -6712,7 +6702,7 @@ async function startServer(overrides = {}) {
6712
6702
  }
6713
6703
  const triageDbPath = triageDbFor(dbPath);
6714
6704
  const db = openReadonly(dbPath);
6715
- const enforceLoopbackHost = host === "127.0.0.1" || host === "localhost";
6705
+ const enforceLoopbackHost = isLoopbackBind(host);
6716
6706
  const app = await createApp(db, {
6717
6707
  webDist,
6718
6708
  triageDbPath,