agent-insights 0.0.19 → 0.0.22

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.js CHANGED
@@ -1255,11 +1255,18 @@ var adapterList = Object.values(adapters);
1255
1255
 
1256
1256
  // src/commands/disable.ts
1257
1257
  init_paths();
1258
+ var CONFIG_KEY_BY_ID = {
1259
+ "claude-code": "claudeCode",
1260
+ cursor: "cursor",
1261
+ codex: "codex",
1262
+ pi: "pi"
1263
+ };
1258
1264
  async function runDisable(opts) {
1259
1265
  const repoRoot = process.cwd();
1266
+ const knownIds = new Set(adapterList.map((a) => a.id));
1260
1267
  const targets = opts.agent ? [opts.agent] : adapterList.map((a) => a.id);
1261
1268
  for (const id of targets) {
1262
- if (id !== "claude-code" && id !== "cursor") {
1269
+ if (!knownIds.has(id)) {
1263
1270
  log.warn(`Unknown agent id "${id}"`);
1264
1271
  continue;
1265
1272
  }
@@ -1271,11 +1278,9 @@ async function runDisable(opts) {
1271
1278
  }
1272
1279
  const cfg = await loadConfig();
1273
1280
  if (cfg) {
1274
- if (!opts.agent || opts.agent === "claude-code") {
1275
- cfg.agents.claudeCode.enabled = false;
1276
- }
1277
- if (!opts.agent || opts.agent === "cursor") {
1278
- cfg.agents.cursor.enabled = false;
1281
+ for (const id of targets) {
1282
+ const key = CONFIG_KEY_BY_ID[id];
1283
+ if (key) cfg.agents[key].enabled = false;
1279
1284
  }
1280
1285
  if (!opts.agent) cfg.enabled = false;
1281
1286
  await saveConfig(cfg);
@@ -1391,7 +1396,10 @@ var AnalyzerTranscriptStore = class {
1391
1396
  "x-session-id": input.sessionId,
1392
1397
  "x-agent": input.agent,
1393
1398
  "x-user-hash": input.userHash,
1394
- ...input.userEmail ? { "x-user-email": input.userEmail } : {}
1399
+ ...input.userEmail ? { "x-user-email": input.userEmail } : {},
1400
+ ...input.gitInfo?.repoName ? { "x-git-repo-name": input.gitInfo.repoName } : {},
1401
+ ...input.gitInfo?.branch ? { "x-git-branch": input.gitInfo.branch } : {},
1402
+ ...input.gitInfo?.commitSha ? { "x-git-commit-sha": input.gitInfo.commitSha } : {}
1395
1403
  });
1396
1404
  const res = await fetch(url, { method: "POST", headers, body });
1397
1405
  if (!res.ok) {
@@ -1525,7 +1533,69 @@ async function runDoctor(opts) {
1525
1533
  }
1526
1534
 
1527
1535
  // src/commands/hook.ts
1536
+ import { basename as basename2 } from "path";
1528
1537
  init_store();
1538
+
1539
+ // src/util/git-info.ts
1540
+ import { execSync as execSync2 } from "child_process";
1541
+ import { basename } from "path";
1542
+ function readGitInfo(cwd) {
1543
+ let raw;
1544
+ try {
1545
+ raw = execSync2("git rev-parse HEAD --show-toplevel", {
1546
+ cwd,
1547
+ stdio: ["ignore", "pipe", "ignore"],
1548
+ timeout: 1500
1549
+ }).toString("utf8");
1550
+ } catch {
1551
+ return void 0;
1552
+ }
1553
+ const [commitSha, top] = raw.split("\n").map((s) => s.trim());
1554
+ if (!top) return void 0;
1555
+ let repoName = basename(top);
1556
+ try {
1557
+ const remote = execSync2("git config --get remote.origin.url", {
1558
+ cwd,
1559
+ stdio: ["ignore", "pipe", "ignore"],
1560
+ timeout: 1500
1561
+ }).toString("utf8").trim();
1562
+ const parsed = parseRemoteUrl(remote);
1563
+ if (parsed) repoName = parsed;
1564
+ } catch {
1565
+ }
1566
+ let branch;
1567
+ try {
1568
+ const out = execSync2("git rev-parse --abbrev-ref HEAD", {
1569
+ cwd,
1570
+ stdio: ["ignore", "pipe", "ignore"],
1571
+ timeout: 1500
1572
+ }).toString("utf8").trim();
1573
+ if (out && out !== "HEAD") branch = out;
1574
+ } catch {
1575
+ }
1576
+ const info = { repoName };
1577
+ if (branch) info.branch = branch;
1578
+ if (commitSha) info.commitSha = commitSha;
1579
+ return info;
1580
+ }
1581
+ function parseRemoteUrl(url) {
1582
+ const trimmed = url.trim().replace(/\.git$/, "");
1583
+ if (!trimmed) return void 0;
1584
+ const sshMatch = trimmed.match(/^[^@\s]+@[^:\s]+:(.+)$/);
1585
+ if (sshMatch?.[1]) return stripSlashes(sshMatch[1]);
1586
+ try {
1587
+ const u = new URL(trimmed);
1588
+ const path = stripSlashes(u.pathname);
1589
+ return path || void 0;
1590
+ } catch {
1591
+ return void 0;
1592
+ }
1593
+ }
1594
+ function stripSlashes(s) {
1595
+ return s.replace(/^\/+/, "").replace(/\/+$/, "");
1596
+ }
1597
+
1598
+ // src/commands/hook.ts
1529
1599
  async function runHook(eventName, opts) {
1530
1600
  const cfg = await loadConfig();
1531
1601
  if (!cfg || !cfg.enabled) {
@@ -1555,12 +1625,15 @@ async function runHook(eventName, opts) {
1555
1625
  try {
1556
1626
  const store = createTranscriptStore(cfg.transcriptStore);
1557
1627
  const userEmail = await loadEmail();
1628
+ const cwd = (typeof data?.["cwd"] === "string" ? data["cwd"] : void 0) ?? process.cwd();
1629
+ const gitInfo = readGitInfo(cwd) ?? cwdFallback(cwd);
1558
1630
  const result = await store.upload({
1559
1631
  transcriptPath: mapped.transcriptPath,
1560
1632
  userHash: event.userHash ?? userHash(),
1561
1633
  sessionId: mapped.sessionId ?? "unknown",
1562
1634
  agent: adapter.id,
1563
- ...userEmail ? { userEmail } : {}
1635
+ ...userEmail ? { userEmail } : {},
1636
+ ...gitInfo ? { gitInfo } : {}
1564
1637
  });
1565
1638
  debug("transcript uploaded", {
1566
1639
  size: result.size,
@@ -1667,6 +1740,11 @@ async function readStdinSafely() {
1667
1740
  });
1668
1741
  });
1669
1742
  }
1743
+ function cwdFallback(cwd) {
1744
+ const name = basename2(cwd);
1745
+ if (!name || name === "/" || name === ".") return void 0;
1746
+ return { repoName: name };
1747
+ }
1670
1748
  function parseJsonObject(raw) {
1671
1749
  if (!raw) return void 0;
1672
1750
  try {
@@ -1997,7 +2075,7 @@ function yn(v) {
1997
2075
  var program = new Command();
1998
2076
  program.name("agent-insights").description(
1999
2077
  "Internal CLI for AI coding agent observability (Claude Code, Cursor)."
2000
- ).version("0.0.19");
2078
+ ).version("0.0.22");
2001
2079
  program.command("login").description("Authenticate with Vercel (Sign in with Vercel).").action(async () => {
2002
2080
  await runLogin();
2003
2081
  });