agent-insights 0.0.20 → 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 +90 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +10 -11
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) {
|
|
@@ -1533,6 +1536,7 @@ async function runDoctor(opts) {
|
|
|
1533
1536
|
}
|
|
1534
1537
|
|
|
1535
1538
|
// src/commands/hook.ts
|
|
1539
|
+
import { basename as basename2 } from "path";
|
|
1536
1540
|
init_store();
|
|
1537
1541
|
|
|
1538
1542
|
// src/util/git-info.ts
|
|
@@ -1551,6 +1555,17 @@ function readGitInfo(cwd) {
|
|
|
1551
1555
|
}
|
|
1552
1556
|
const [commitSha, top] = raw.split("\n").map((s) => s.trim());
|
|
1553
1557
|
if (!top) return void 0;
|
|
1558
|
+
let repoName = basename(top);
|
|
1559
|
+
try {
|
|
1560
|
+
const remote = execSync2("git config --get remote.origin.url", {
|
|
1561
|
+
cwd,
|
|
1562
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
1563
|
+
timeout: 1500
|
|
1564
|
+
}).toString("utf8").trim();
|
|
1565
|
+
const parsed = parseRemoteUrl(remote);
|
|
1566
|
+
if (parsed) repoName = parsed;
|
|
1567
|
+
} catch {
|
|
1568
|
+
}
|
|
1554
1569
|
let branch;
|
|
1555
1570
|
try {
|
|
1556
1571
|
const out = execSync2("git rev-parse --abbrev-ref HEAD", {
|
|
@@ -1561,11 +1576,62 @@ function readGitInfo(cwd) {
|
|
|
1561
1576
|
if (out && out !== "HEAD") branch = out;
|
|
1562
1577
|
} catch {
|
|
1563
1578
|
}
|
|
1564
|
-
const info = { repoName
|
|
1579
|
+
const info = { repoName };
|
|
1565
1580
|
if (branch) info.branch = branch;
|
|
1566
1581
|
if (commitSha) info.commitSha = commitSha;
|
|
1567
1582
|
return info;
|
|
1568
1583
|
}
|
|
1584
|
+
function parseRemoteUrl(url) {
|
|
1585
|
+
const trimmed = url.trim().replace(/\.git$/, "");
|
|
1586
|
+
if (!trimmed) return void 0;
|
|
1587
|
+
const sshMatch = trimmed.match(/^[^@\s]+@[^:\s]+:(.+)$/);
|
|
1588
|
+
if (sshMatch?.[1]) return stripSlashes(sshMatch[1]);
|
|
1589
|
+
try {
|
|
1590
|
+
const u = new URL(trimmed);
|
|
1591
|
+
const path = stripSlashes(u.pathname);
|
|
1592
|
+
return path || void 0;
|
|
1593
|
+
} catch {
|
|
1594
|
+
return void 0;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
function stripSlashes(s) {
|
|
1598
|
+
return s.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
1599
|
+
}
|
|
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
|
+
}
|
|
1569
1635
|
|
|
1570
1636
|
// src/commands/hook.ts
|
|
1571
1637
|
async function runHook(eventName, opts) {
|
|
@@ -1593,20 +1659,28 @@ async function runHook(eventName, opts) {
|
|
|
1593
1659
|
type: event.type,
|
|
1594
1660
|
sessionId: event.sessionId
|
|
1595
1661
|
});
|
|
1662
|
+
if (mapped.type === "session.start" && mapped.sessionId && mapped.source) {
|
|
1663
|
+
await writeSessionSource(mapped.sessionId, mapped.source);
|
|
1664
|
+
}
|
|
1596
1665
|
if (mapped.type === "session.end" && cfg.userConsent.transcriptSync && mapped.transcriptPath) {
|
|
1597
1666
|
try {
|
|
1598
1667
|
const store = createTranscriptStore(cfg.transcriptStore);
|
|
1599
1668
|
const userEmail = await loadEmail();
|
|
1600
1669
|
const cwd = (typeof data?.["cwd"] === "string" ? data["cwd"] : void 0) ?? process.cwd();
|
|
1601
|
-
const gitInfo = readGitInfo(cwd);
|
|
1670
|
+
const gitInfo = readGitInfo(cwd) ?? cwdFallback(cwd);
|
|
1671
|
+
const source = mapped.sessionId ? await readSessionSource(mapped.sessionId) : void 0;
|
|
1602
1672
|
const result = await store.upload({
|
|
1603
1673
|
transcriptPath: mapped.transcriptPath,
|
|
1604
1674
|
userHash: event.userHash ?? userHash(),
|
|
1605
1675
|
sessionId: mapped.sessionId ?? "unknown",
|
|
1606
1676
|
agent: adapter.id,
|
|
1607
1677
|
...userEmail ? { userEmail } : {},
|
|
1608
|
-
...gitInfo ? { gitInfo } : {}
|
|
1678
|
+
...gitInfo ? { gitInfo } : {},
|
|
1679
|
+
...source ? { source } : {}
|
|
1609
1680
|
});
|
|
1681
|
+
if (mapped.sessionId) {
|
|
1682
|
+
await clearSessionSource(mapped.sessionId);
|
|
1683
|
+
}
|
|
1610
1684
|
debug("transcript uploaded", {
|
|
1611
1685
|
size: result.size,
|
|
1612
1686
|
pathname: result.pathname
|
|
@@ -1712,6 +1786,11 @@ async function readStdinSafely() {
|
|
|
1712
1786
|
});
|
|
1713
1787
|
});
|
|
1714
1788
|
}
|
|
1789
|
+
function cwdFallback(cwd) {
|
|
1790
|
+
const name = basename2(cwd);
|
|
1791
|
+
if (!name || name === "/" || name === ".") return void 0;
|
|
1792
|
+
return { repoName: name };
|
|
1793
|
+
}
|
|
1715
1794
|
function parseJsonObject(raw) {
|
|
1716
1795
|
if (!raw) return void 0;
|
|
1717
1796
|
try {
|
|
@@ -1979,7 +2058,7 @@ async function runLogout() {
|
|
|
1979
2058
|
|
|
1980
2059
|
// src/commands/status.ts
|
|
1981
2060
|
import { existsSync } from "fs";
|
|
1982
|
-
import { join as
|
|
2061
|
+
import { join as join7 } from "path";
|
|
1983
2062
|
import kleur5 from "kleur";
|
|
1984
2063
|
init_paths();
|
|
1985
2064
|
async function runStatus(opts) {
|
|
@@ -2005,8 +2084,8 @@ async function runStatus(opts) {
|
|
|
2005
2084
|
enabled: cfg.enabled,
|
|
2006
2085
|
consent: cfg.userConsent,
|
|
2007
2086
|
vercel: {
|
|
2008
|
-
linked: existsSync(
|
|
2009
|
-
envFile: existsSync(
|
|
2087
|
+
linked: existsSync(join7(repoRoot, ".vercel/project.json")),
|
|
2088
|
+
envFile: existsSync(join7(repoRoot, ".env.local"))
|
|
2010
2089
|
},
|
|
2011
2090
|
adapters: adapterStatus
|
|
2012
2091
|
});
|
|
@@ -2030,9 +2109,9 @@ async function runStatus(opts) {
|
|
|
2030
2109
|
log.info("");
|
|
2031
2110
|
log.info(kleur5.bold("Vercel"));
|
|
2032
2111
|
log.info(
|
|
2033
|
-
` linked ${yn(existsSync(
|
|
2112
|
+
` linked ${yn(existsSync(join7(repoRoot, ".vercel/project.json")))}`
|
|
2034
2113
|
);
|
|
2035
|
-
log.info(` .env.local ${yn(existsSync(
|
|
2114
|
+
log.info(` .env.local ${yn(existsSync(join7(repoRoot, ".env.local")))}`);
|
|
2036
2115
|
}
|
|
2037
2116
|
function yn(v) {
|
|
2038
2117
|
return v ? kleur5.green("yes") : kleur5.dim("no");
|
|
@@ -2042,7 +2121,7 @@ function yn(v) {
|
|
|
2042
2121
|
var program = new Command();
|
|
2043
2122
|
program.name("agent-insights").description(
|
|
2044
2123
|
"Internal CLI for AI coding agent observability (Claude Code, Cursor)."
|
|
2045
|
-
).version("0.0.
|
|
2124
|
+
).version("0.0.23");
|
|
2046
2125
|
program.command("login").description("Authenticate with Vercel (Sign in with Vercel).").action(async () => {
|
|
2047
2126
|
await runLogin();
|
|
2048
2127
|
});
|