agent-insights 0.0.22 → 0.0.23

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
@@ -683,11 +683,13 @@ var claudeCodeAdapter = {
683
683
  const sessionId = asString(data["session_id"]) ?? asString(data["sessionId"]);
684
684
  const toolName = asString(data["tool_name"]) ?? asString(data["toolName"]) ?? asString(data["tool"]?.["name"]);
685
685
  const transcriptPath = asString(data["transcript_path"]) ?? asString(data["transcriptPath"]);
686
+ const source = asString(data["source"]);
686
687
  return {
687
688
  type,
688
689
  ...sessionId !== void 0 ? { sessionId } : {},
689
690
  ...toolName !== void 0 ? { toolName } : {},
690
- ...transcriptPath !== void 0 ? { transcriptPath } : {}
691
+ ...transcriptPath !== void 0 ? { transcriptPath } : {},
692
+ ...source !== void 0 ? { source } : {}
691
693
  };
692
694
  },
693
695
  async install(repoRoot, scope = "global") {
@@ -1399,7 +1401,8 @@ var AnalyzerTranscriptStore = class {
1399
1401
  ...input.userEmail ? { "x-user-email": input.userEmail } : {},
1400
1402
  ...input.gitInfo?.repoName ? { "x-git-repo-name": input.gitInfo.repoName } : {},
1401
1403
  ...input.gitInfo?.branch ? { "x-git-branch": input.gitInfo.branch } : {},
1402
- ...input.gitInfo?.commitSha ? { "x-git-commit-sha": input.gitInfo.commitSha } : {}
1404
+ ...input.gitInfo?.commitSha ? { "x-git-commit-sha": input.gitInfo.commitSha } : {},
1405
+ ...input.source ? { "x-session-source": input.source } : {}
1403
1406
  });
1404
1407
  const res = await fetch(url, { method: "POST", headers, body });
1405
1408
  if (!res.ok) {
@@ -1595,6 +1598,41 @@ function stripSlashes(s) {
1595
1598
  return s.replace(/^\/+/, "").replace(/\/+$/, "");
1596
1599
  }
1597
1600
 
1601
+ // src/util/session-source.ts
1602
+ init_paths();
1603
+ import { mkdir as mkdir8, readFile as readFile9, rm as rm2, writeFile as writeFile8 } from "fs/promises";
1604
+ import { join as join6 } from "path";
1605
+ function markerPath(sessionId) {
1606
+ const safe = sessionId.replace(/[^A-Za-z0-9_-]/g, "_");
1607
+ return join6(sessionCacheDir(), `source-${safe}.json`);
1608
+ }
1609
+ async function writeSessionSource(sessionId, source) {
1610
+ try {
1611
+ await mkdir8(sessionCacheDir(), { recursive: true });
1612
+ await writeFile8(
1613
+ markerPath(sessionId),
1614
+ JSON.stringify({ source, ts: (/* @__PURE__ */ new Date()).toISOString() }),
1615
+ "utf8"
1616
+ );
1617
+ } catch {
1618
+ }
1619
+ }
1620
+ async function readSessionSource(sessionId) {
1621
+ try {
1622
+ const raw = await readFile9(markerPath(sessionId), "utf8");
1623
+ const parsed = JSON.parse(raw);
1624
+ return typeof parsed.source === "string" ? parsed.source : void 0;
1625
+ } catch {
1626
+ return void 0;
1627
+ }
1628
+ }
1629
+ async function clearSessionSource(sessionId) {
1630
+ try {
1631
+ await rm2(markerPath(sessionId), { force: true });
1632
+ } catch {
1633
+ }
1634
+ }
1635
+
1598
1636
  // src/commands/hook.ts
1599
1637
  async function runHook(eventName, opts) {
1600
1638
  const cfg = await loadConfig();
@@ -1621,20 +1659,28 @@ async function runHook(eventName, opts) {
1621
1659
  type: event.type,
1622
1660
  sessionId: event.sessionId
1623
1661
  });
1662
+ if (mapped.type === "session.start" && mapped.sessionId && mapped.source) {
1663
+ await writeSessionSource(mapped.sessionId, mapped.source);
1664
+ }
1624
1665
  if (mapped.type === "session.end" && cfg.userConsent.transcriptSync && mapped.transcriptPath) {
1625
1666
  try {
1626
1667
  const store = createTranscriptStore(cfg.transcriptStore);
1627
1668
  const userEmail = await loadEmail();
1628
1669
  const cwd = (typeof data?.["cwd"] === "string" ? data["cwd"] : void 0) ?? process.cwd();
1629
1670
  const gitInfo = readGitInfo(cwd) ?? cwdFallback(cwd);
1671
+ const source = mapped.sessionId ? await readSessionSource(mapped.sessionId) : void 0;
1630
1672
  const result = await store.upload({
1631
1673
  transcriptPath: mapped.transcriptPath,
1632
1674
  userHash: event.userHash ?? userHash(),
1633
1675
  sessionId: mapped.sessionId ?? "unknown",
1634
1676
  agent: adapter.id,
1635
1677
  ...userEmail ? { userEmail } : {},
1636
- ...gitInfo ? { gitInfo } : {}
1678
+ ...gitInfo ? { gitInfo } : {},
1679
+ ...source ? { source } : {}
1637
1680
  });
1681
+ if (mapped.sessionId) {
1682
+ await clearSessionSource(mapped.sessionId);
1683
+ }
1638
1684
  debug("transcript uploaded", {
1639
1685
  size: result.size,
1640
1686
  pathname: result.pathname
@@ -2012,7 +2058,7 @@ async function runLogout() {
2012
2058
 
2013
2059
  // src/commands/status.ts
2014
2060
  import { existsSync } from "fs";
2015
- import { join as join6 } from "path";
2061
+ import { join as join7 } from "path";
2016
2062
  import kleur5 from "kleur";
2017
2063
  init_paths();
2018
2064
  async function runStatus(opts) {
@@ -2038,8 +2084,8 @@ async function runStatus(opts) {
2038
2084
  enabled: cfg.enabled,
2039
2085
  consent: cfg.userConsent,
2040
2086
  vercel: {
2041
- linked: existsSync(join6(repoRoot, ".vercel/project.json")),
2042
- envFile: existsSync(join6(repoRoot, ".env.local"))
2087
+ linked: existsSync(join7(repoRoot, ".vercel/project.json")),
2088
+ envFile: existsSync(join7(repoRoot, ".env.local"))
2043
2089
  },
2044
2090
  adapters: adapterStatus
2045
2091
  });
@@ -2063,9 +2109,9 @@ async function runStatus(opts) {
2063
2109
  log.info("");
2064
2110
  log.info(kleur5.bold("Vercel"));
2065
2111
  log.info(
2066
- ` linked ${yn(existsSync(join6(repoRoot, ".vercel/project.json")))}`
2112
+ ` linked ${yn(existsSync(join7(repoRoot, ".vercel/project.json")))}`
2067
2113
  );
2068
- log.info(` .env.local ${yn(existsSync(join6(repoRoot, ".env.local")))}`);
2114
+ log.info(` .env.local ${yn(existsSync(join7(repoRoot, ".env.local")))}`);
2069
2115
  }
2070
2116
  function yn(v) {
2071
2117
  return v ? kleur5.green("yes") : kleur5.dim("no");
@@ -2075,7 +2121,7 @@ function yn(v) {
2075
2121
  var program = new Command();
2076
2122
  program.name("agent-insights").description(
2077
2123
  "Internal CLI for AI coding agent observability (Claude Code, Cursor)."
2078
- ).version("0.0.22");
2124
+ ).version("0.0.23");
2079
2125
  program.command("login").description("Authenticate with Vercel (Sign in with Vercel).").action(async () => {
2080
2126
  await runLogin();
2081
2127
  });