@swestash/agent-lens 0.8.1 → 0.8.3
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/agent-lens.js +32 -19
- package/dist/agent-lens.js.map +1 -1
- package/package.json +1 -1
package/dist/agent-lens.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { existsSync as existsSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync3 } from "fs";
|
|
5
|
-
import { dirname as dirname6, join as
|
|
5
|
+
import { dirname as dirname6, join as join12 } from "path";
|
|
6
6
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
7
7
|
|
|
8
8
|
// ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
@@ -1315,6 +1315,12 @@ function resolveDataDir(repoRoot = findRepoRoot()) {
|
|
|
1315
1315
|
return join(repoRoot, "data");
|
|
1316
1316
|
return userDataDir();
|
|
1317
1317
|
}
|
|
1318
|
+
function resolveArchiveDir(repoRoot = findRepoRoot()) {
|
|
1319
|
+
return join(resolveDataDir(repoRoot), "archive");
|
|
1320
|
+
}
|
|
1321
|
+
function triageDbFor(dbPath) {
|
|
1322
|
+
return join(dirname(dbPath), "triage.db");
|
|
1323
|
+
}
|
|
1318
1324
|
function resolveConfigFile(repoRoot, dataDir) {
|
|
1319
1325
|
const candidates = [
|
|
1320
1326
|
process.env.AGENT_LENS_CONFIG,
|
|
@@ -1662,7 +1668,7 @@ function collectSource(source, archiveBase, excludedDirs, runTs, stats, log) {
|
|
|
1662
1668
|
}
|
|
1663
1669
|
function collectAll(opts = {}) {
|
|
1664
1670
|
const log = opts.log ?? ((m) => console.log(m));
|
|
1665
|
-
const archiveBase = opts.archiveBase ??
|
|
1671
|
+
const archiveBase = opts.archiveBase ?? resolveArchiveDir();
|
|
1666
1672
|
const sources = opts.sources ?? loadSources();
|
|
1667
1673
|
const excludedDirs = (opts.excludes ?? loadExcludes()).map(encodeProjectPath);
|
|
1668
1674
|
const runTs = opts.runTimestamp ?? collectTimestamp();
|
|
@@ -1722,9 +1728,16 @@ function acquireLock(lockPath, staleMs = 6 * 60 * 60 * 1e3) {
|
|
|
1722
1728
|
// ../core/dist/service.js
|
|
1723
1729
|
import { spawnSync } from "child_process";
|
|
1724
1730
|
import { mkdirSync as mkdirSync3, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1725
|
-
import { homedir as homedir2, platform as platform3 } from "os";
|
|
1731
|
+
import { homedir as homedir2, platform as platform3, userInfo } from "os";
|
|
1726
1732
|
import { join as join4 } from "path";
|
|
1727
1733
|
var DEFAULT_HOURS = [9, 13, 17, 21];
|
|
1734
|
+
function currentUser() {
|
|
1735
|
+
try {
|
|
1736
|
+
return userInfo().username;
|
|
1737
|
+
} catch {
|
|
1738
|
+
return process.env.USER || process.env.LOGNAME || "";
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1728
1741
|
var SYSTEMD_COLLECTOR_TIMER = "agent-lens-collect.timer";
|
|
1729
1742
|
var SYSTEMD_COLLECTOR_SERVICE = "agent-lens-collect.service";
|
|
1730
1743
|
var SYSTEMD_SERVER_SERVICE = "agent-lens-server.service";
|
|
@@ -1894,8 +1907,9 @@ function linuxInstall(targets, node, cli2, hours) {
|
|
|
1894
1907
|
console.log("agent-lens service: installed server daemon");
|
|
1895
1908
|
sh("systemctl", ["--user", "status", SYSTEMD_SERVER_SERVICE, "--no-pager"]);
|
|
1896
1909
|
}
|
|
1897
|
-
|
|
1898
|
-
|
|
1910
|
+
const user = currentUser();
|
|
1911
|
+
if (user && have("loginctl") && !sh("loginctl", ["enable-linger", user], true)) {
|
|
1912
|
+
console.log(`agent-lens: could not enable linger automatically; run: sudo loginctl enable-linger ${user}`);
|
|
1899
1913
|
}
|
|
1900
1914
|
}
|
|
1901
1915
|
function linuxUninstall(targets) {
|
|
@@ -4042,8 +4056,7 @@ function parseIngestArgs(argv) {
|
|
|
4042
4056
|
}
|
|
4043
4057
|
function runIngest(argv = process.argv.slice(2)) {
|
|
4044
4058
|
const args = parseIngestArgs(argv);
|
|
4045
|
-
const
|
|
4046
|
-
const archiveRoot = args.archive || process.env.AGENT_LENS_ARCHIVE || join9(dataDir, "archive");
|
|
4059
|
+
const archiveRoot = args.archive || resolveArchiveDir();
|
|
4047
4060
|
const { path: dbPath } = resolveDbPath(args.db);
|
|
4048
4061
|
if (!existsSync4(archiveRoot)) {
|
|
4049
4062
|
console.error(`agent-lens-ingest: archive not found: ${archiveRoot} (run 'agent-lens collect' first)`);
|
|
@@ -4169,7 +4182,7 @@ function runMetrics(argv = process.argv.slice(2)) {
|
|
|
4169
4182
|
|
|
4170
4183
|
// ../server/dist/run.js
|
|
4171
4184
|
import { existsSync as existsSync7 } from "fs";
|
|
4172
|
-
import { dirname as dirname5
|
|
4185
|
+
import { dirname as dirname5 } from "path";
|
|
4173
4186
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
4174
4187
|
|
|
4175
4188
|
// ../server/dist/db.js
|
|
@@ -5051,7 +5064,7 @@ function runRefresh() {
|
|
|
5051
5064
|
return null;
|
|
5052
5065
|
try {
|
|
5053
5066
|
const collected = collectAll();
|
|
5054
|
-
const archiveRoot =
|
|
5067
|
+
const archiveRoot = resolveArchiveDir();
|
|
5055
5068
|
if (!existsSync5(archiveRoot))
|
|
5056
5069
|
mkdirSync5(archiveRoot, { recursive: true });
|
|
5057
5070
|
runIngest([]);
|
|
@@ -5381,7 +5394,7 @@ async function startServer(overrides = {}) {
|
|
|
5381
5394
|
console.error(`agent-lens-server: db not found: ${dbPath} (run ingest first)`);
|
|
5382
5395
|
process.exit(1);
|
|
5383
5396
|
}
|
|
5384
|
-
const triageDbPath =
|
|
5397
|
+
const triageDbPath = triageDbFor(dbPath);
|
|
5385
5398
|
const db = openReadonly(dbPath);
|
|
5386
5399
|
const enforceLoopbackHost = host === "127.0.0.1" || host === "localhost";
|
|
5387
5400
|
const app = await createApp(db, { webDist, triageDbPath, enforceLoopbackHost });
|
|
@@ -5398,11 +5411,11 @@ async function startServer(overrides = {}) {
|
|
|
5398
5411
|
|
|
5399
5412
|
// src/watch.ts
|
|
5400
5413
|
import { existsSync as existsSync8 } from "fs";
|
|
5401
|
-
import { join as
|
|
5414
|
+
import { join as join11 } from "path";
|
|
5402
5415
|
import chokidar from "chokidar";
|
|
5403
5416
|
async function runWatch(opts = {}) {
|
|
5404
5417
|
const sources = loadSources();
|
|
5405
|
-
const lockPath =
|
|
5418
|
+
const lockPath = join11(resolveDataDir(findRepoRoot()), ".agent-lens.lock");
|
|
5406
5419
|
let running = false;
|
|
5407
5420
|
let pending = false;
|
|
5408
5421
|
const cycle = () => {
|
|
@@ -5435,7 +5448,7 @@ async function runWatch(opts = {}) {
|
|
|
5435
5448
|
}
|
|
5436
5449
|
};
|
|
5437
5450
|
cycle();
|
|
5438
|
-
const watchPaths = sources.map((s) =>
|
|
5451
|
+
const watchPaths = sources.map((s) => join11(s.configDir, "projects")).filter((p) => existsSync8(p));
|
|
5439
5452
|
if (watchPaths.length === 0) {
|
|
5440
5453
|
console.error("agent-lens watch: no source 'projects' directories found \u2014 nothing to watch");
|
|
5441
5454
|
}
|
|
@@ -5463,14 +5476,14 @@ async function runWatch(opts = {}) {
|
|
|
5463
5476
|
// src/index.ts
|
|
5464
5477
|
function version() {
|
|
5465
5478
|
try {
|
|
5466
|
-
const pkg = JSON.parse(readFileSync8(
|
|
5479
|
+
const pkg = JSON.parse(readFileSync8(join12(dirname6(fileURLToPath3(import.meta.url)), "../package.json"), "utf8"));
|
|
5467
5480
|
return pkg.version ?? "0.0.0";
|
|
5468
5481
|
} catch {
|
|
5469
5482
|
return "0.0.0";
|
|
5470
5483
|
}
|
|
5471
5484
|
}
|
|
5472
5485
|
function withLock(fn) {
|
|
5473
|
-
const lockPath =
|
|
5486
|
+
const lockPath = join12(resolveDataDir(findRepoRoot()), ".agent-lens.lock");
|
|
5474
5487
|
const lock = acquireLock(lockPath);
|
|
5475
5488
|
if (!lock) {
|
|
5476
5489
|
console.error("agent-lens: another collect/ingest run is in progress \u2014 skipping");
|
|
@@ -5553,17 +5566,17 @@ cli.command("config", "Show the effective configuration (sources, paths, server)
|
|
|
5553
5566
|
}
|
|
5554
5567
|
const { port, host, portOrigin, hostOrigin } = server;
|
|
5555
5568
|
const { path: dbPath, origin: dbOrigin } = resolveDbPath();
|
|
5556
|
-
const archive =
|
|
5557
|
-
const triageDb =
|
|
5569
|
+
const archive = resolveArchiveDir(repoRoot);
|
|
5570
|
+
const triageDb = triageDbFor(dbPath);
|
|
5558
5571
|
const keepDays = process.env.AGENT_LENS_VERSIONS_KEEP_DAYS || "90";
|
|
5559
5572
|
const keepOrigin = process.env.AGENT_LENS_VERSIONS_KEEP_DAYS ? "env" : "default";
|
|
5560
5573
|
console.log("agent-lens config (precedence: flag > env > config file > default)\n");
|
|
5561
5574
|
console.log("Paths");
|
|
5562
5575
|
console.log(` config file ${configFile ?? "(none \u2014 using built-in default source)"}`);
|
|
5563
5576
|
console.log(` data dir ${dataDir}${process.env.AGENT_LENS_DATA ? " [env]" : ""}`);
|
|
5564
|
-
console.log(` archive ${archive}
|
|
5577
|
+
console.log(` archive ${archive} [fixed: <data dir>/archive]`);
|
|
5565
5578
|
console.log(` db ${dbPath} [${dbOrigin}]`);
|
|
5566
|
-
console.log(` triage db ${triageDb}
|
|
5579
|
+
console.log(` triage db ${triageDb} [fixed: beside the db]`);
|
|
5567
5580
|
console.log("\nServer");
|
|
5568
5581
|
console.log(` host ${host} [${hostOrigin}]`);
|
|
5569
5582
|
console.log(` port ${port} [${portOrigin}]`);
|