@swestash/agent-lens 0.16.0 → 0.17.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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { existsSync as existsSync10, writeFileSync as writeFileSync3 } from "node:fs";
4
+ import { existsSync as existsSync11, writeFileSync as writeFileSync3 } from "node:fs";
5
5
  import { join as join12 } from "node:path";
6
6
  import { fileURLToPath as fileURLToPath4 } from "node:url";
7
7
 
@@ -4643,11 +4643,12 @@ function runMetrics(argv = process.argv.slice(2)) {
4643
4643
  }
4644
4644
 
4645
4645
  // ../server/dist/run.js
4646
- import { existsSync as existsSync8 } from "node:fs";
4646
+ import { existsSync as existsSync9 } from "node:fs";
4647
4647
  import { dirname as dirname7 } from "node:path";
4648
4648
  import { fileURLToPath as fileURLToPath3 } from "node:url";
4649
4649
 
4650
4650
  // ../server/dist/db.js
4651
+ import { existsSync as existsSync6 } from "node:fs";
4651
4652
  import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
4652
4653
 
4653
4654
  // ../server/dist/sql-util.js
@@ -5105,6 +5106,17 @@ function getSession(db, id) {
5105
5106
  file_changes: loadFileChanges(db, id)
5106
5107
  };
5107
5108
  }
5109
+ function sessionLocation(db, id) {
5110
+ const session = queryGet(db, "SELECT source_id FROM sessions WHERE id = ?", id);
5111
+ if (!session)
5112
+ return null;
5113
+ const files = queryAll(db, "SELECT DISTINCT source_file FROM events WHERE session_id = ? AND source_file IS NOT NULL", id).map((r) => r.source_file);
5114
+ if (files.length === 0)
5115
+ return null;
5116
+ const live = files.filter((f) => !f.includes("/.versions/"));
5117
+ const path3 = live.find((f) => f.endsWith(`/${id}.jsonl`)) ?? live[0] ?? files[0];
5118
+ return { session_id: id, path: path3, exists: existsSync6(path3), source_id: session.source_id };
5119
+ }
5108
5120
  function safeJson(s) {
5109
5121
  if (!s)
5110
5122
  return null;
@@ -5468,7 +5480,7 @@ function securitySummary(db) {
5468
5480
  }
5469
5481
 
5470
5482
  // ../server/dist/app.js
5471
- import { existsSync as existsSync7 } from "node:fs";
5483
+ import { existsSync as existsSync8 } from "node:fs";
5472
5484
  import Fastify from "fastify";
5473
5485
  import fastifyStatic from "@fastify/static";
5474
5486
 
@@ -5956,7 +5968,7 @@ function findingsOverTime(db, w, bucket) {
5956
5968
  }
5957
5969
 
5958
5970
  // ../server/dist/refresh.js
5959
- import { existsSync as existsSync6, mkdirSync as mkdirSync5 } from "node:fs";
5971
+ import { existsSync as existsSync7, mkdirSync as mkdirSync5 } from "node:fs";
5960
5972
  import { join as join10 } from "node:path";
5961
5973
  var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["127.0.0.1", "localhost", "[::1]"]);
5962
5974
  function originAllowed(origin) {
@@ -5984,7 +5996,7 @@ function runRefresh() {
5984
5996
  try {
5985
5997
  const collected = collectAll();
5986
5998
  const archiveRoot = resolveArchiveDir();
5987
- if (!existsSync6(archiveRoot))
5999
+ if (!existsSync7(archiveRoot))
5988
6000
  mkdirSync5(archiveRoot, { recursive: true });
5989
6001
  runIngest([]);
5990
6002
  return { ok: true, collected };
@@ -6286,6 +6298,13 @@ async function createApp(db, opts = {}) {
6286
6298
  return notFound(reply);
6287
6299
  return result;
6288
6300
  });
6301
+ app.get("/api/sessions/:id/location", async (req, reply) => {
6302
+ const { id } = req.params;
6303
+ const result = sessionLocation(db, id);
6304
+ if (!result)
6305
+ return notFound(reply, "no archive path recorded for this session");
6306
+ return result;
6307
+ });
6289
6308
  app.get("/api/workflows/:run_id", async (req, reply) => {
6290
6309
  const { run_id } = req.params;
6291
6310
  const result = getWorkflow(db, run_id);
@@ -6405,7 +6424,7 @@ async function createApp(db, opts = {}) {
6405
6424
  return notFound(reply);
6406
6425
  reply.header("content-type", "text/markdown; charset=utf-8").header("content-disposition", `attachment; filename="${out.filename}"`).send(out.markdown);
6407
6426
  });
6408
- if (opts.webDist && existsSync7(opts.webDist)) {
6427
+ if (opts.webDist && existsSync8(opts.webDist)) {
6409
6428
  await app.register(fastifyStatic, { root: opts.webDist });
6410
6429
  app.setNotFoundHandler((req, reply) => {
6411
6430
  if (req.url.startsWith("/api/"))
@@ -6430,7 +6449,7 @@ async function startServer(overrides = {}) {
6430
6449
  console.error(`agent-lens-server: refusing to bind non-loopback host '${host}' (privacy). Set AGENT_LENS_ALLOW_NONLOCAL=1 to override.`);
6431
6450
  process.exit(1);
6432
6451
  }
6433
- if (!existsSync8(dbPath)) {
6452
+ if (!existsSync9(dbPath)) {
6434
6453
  console.error(`agent-lens-server: db not found: ${dbPath} (run ingest first)`);
6435
6454
  process.exit(1);
6436
6455
  }
@@ -6446,7 +6465,7 @@ async function startServer(overrides = {}) {
6446
6465
  try {
6447
6466
  await app.listen({ host, port });
6448
6467
  console.log(`agent-lens-server: http://${host}:${port} (db: ${dbPath})`);
6449
- if (!existsSync8(webDist))
6468
+ if (!existsSync9(webDist))
6450
6469
  console.log(" note: web SPA not built \u2014 run `pnpm --filter @agent-lens/web build`");
6451
6470
  } catch (err) {
6452
6471
  console.error(err);
@@ -6455,7 +6474,7 @@ async function startServer(overrides = {}) {
6455
6474
  }
6456
6475
 
6457
6476
  // src/watch.ts
6458
- import { existsSync as existsSync9 } from "node:fs";
6477
+ import { existsSync as existsSync10 } from "node:fs";
6459
6478
  import { join as join11 } from "node:path";
6460
6479
  import chokidar from "chokidar";
6461
6480
  async function runWatch(opts = {}) {
@@ -6493,7 +6512,7 @@ async function runWatch(opts = {}) {
6493
6512
  }
6494
6513
  };
6495
6514
  cycle();
6496
- const watchPaths = sources.map((s) => join11(s.configDir, "projects")).filter((p) => existsSync9(p));
6515
+ const watchPaths = sources.map((s) => join11(s.configDir, "projects")).filter((p) => existsSync10(p));
6497
6516
  if (watchPaths.length === 0) {
6498
6517
  console.error("agent-lens watch: no source 'projects' directories found \u2014 nothing to watch");
6499
6518
  }
@@ -6570,7 +6589,7 @@ cli.command("metrics", "Re-run classification over an already-ingested DB").opti
6570
6589
  });
6571
6590
  cli.command("export <sessionId>", "Write a session to a shareable Markdown file (redacted by default)").option("--out <file>", "Write to this file (default: stdout)").option("--level <level>", "Redaction level: secrets (default) | structure").option("--no-redact", "Verbatim, UNREDACTED output (opt-out)").option("--db <path>", "SQLite DB path (overrides AGENT_LENS_DB / config db)").action((sessionId, opts) => {
6572
6591
  const { path: dbPath } = resolveDbPath(opts.db);
6573
- if (!existsSync10(dbPath)) {
6592
+ if (!existsSync11(dbPath)) {
6574
6593
  console.error(`agent-lens: db not found: ${dbPath} (run ingest first)`);
6575
6594
  process.exit(1);
6576
6595
  }