agent-insights 0.0.16 → 0.0.18

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
@@ -74,7 +74,7 @@ If the browser did not open, visit:
74
74
  return { code, codeVerifier };
75
75
  }
76
76
  function listenForCallback(expectedState, timeoutMs) {
77
- return new Promise((resolve, reject) => {
77
+ return new Promise((resolve2, reject) => {
78
78
  const server = createServer((req, res) => {
79
79
  const url = new URL(req.url ?? "/", `http://localhost:${CALLBACK_PORT}`);
80
80
  if (url.pathname !== "/callback") {
@@ -121,7 +121,7 @@ function listenForCallback(expectedState, timeoutMs) {
121
121
  return;
122
122
  }
123
123
  finish(
124
- () => resolve(code),
124
+ () => resolve2(code),
125
125
  html("\u2713 Logged in! You can close this tab."),
126
126
  200
127
127
  );
@@ -599,16 +599,16 @@ async function runCursorWrapper(opts) {
599
599
  process.exitCode = code;
600
600
  }
601
601
  function spawnCursor(path) {
602
- return new Promise((resolve) => {
602
+ return new Promise((resolve2) => {
603
603
  const child = spawn("cursor", [path], {
604
604
  stdio: "inherit",
605
605
  env: process.env
606
606
  });
607
607
  child.on("error", (err) => {
608
608
  log.fail(`failed to launch cursor: ${err.message}`);
609
- resolve(127);
609
+ resolve2(127);
610
610
  });
611
- child.on("exit", (code) => resolve(code ?? 0));
611
+ child.on("exit", (code) => resolve2(code ?? 0));
612
612
  });
613
613
  }
614
614
  function emit(event) {
@@ -626,6 +626,33 @@ import { rm } from "fs/promises";
626
626
  import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
627
627
  import { homedir as homedir2 } from "os";
628
628
  import { dirname as dirname2, join as join2 } from "path";
629
+
630
+ // src/util/hook-command.ts
631
+ import { realpathSync } from "fs";
632
+ function resolve() {
633
+ const node = process.execPath;
634
+ let script = process.argv[1] ?? "";
635
+ try {
636
+ script = realpathSync(script);
637
+ } catch {
638
+ }
639
+ return { node, script };
640
+ }
641
+ function quote(s) {
642
+ if (s.length === 0) return "''";
643
+ if (!/[\s'"\\$`<>|&;()*?#~]/.test(s)) return s;
644
+ return `'${s.replace(/'/g, "'\\''")}'`;
645
+ }
646
+ function hookCommandString(event) {
647
+ const { node, script } = resolve();
648
+ return `${quote(node)} ${quote(script)} hook ${event}`;
649
+ }
650
+ function hookCommandArgv(event) {
651
+ const { node, script } = resolve();
652
+ return { node, script, args: ["hook", event] };
653
+ }
654
+
655
+ // src/adapters/claude-code.ts
629
656
  var HOOK_COMMAND_NAME = "agent-insights";
630
657
  var HOOK_MAP = {
631
658
  SessionStart: "session.start",
@@ -720,7 +747,8 @@ function resolveClaudePath(repoRoot, scope) {
720
747
  }
721
748
  function isAgentInsightsCommand(cmd) {
722
749
  if (!cmd) return false;
723
- return cmd.startsWith(`${HOOK_COMMAND_NAME} hook`);
750
+ if (cmd.startsWith(`${HOOK_COMMAND_NAME} hook`)) return true;
751
+ return /\bagent-insights\b.*\bcli\.js\b.*\bhook\b/.test(cmd);
724
752
  }
725
753
  function isHookCommand(value) {
726
754
  if (!value || typeof value !== "object") return false;
@@ -763,7 +791,7 @@ function removeAgentInsightsMatchers(matchers) {
763
791
  return result;
764
792
  }
765
793
  function addAgentInsightsHook(matchers, event) {
766
- const command = `${HOOK_COMMAND_NAME} hook ${event}`;
794
+ const command = hookCommandString(event);
767
795
  const entry = { type: "command", command };
768
796
  for (const group of matchers) {
769
797
  if (group.matcher === "") {
@@ -875,7 +903,8 @@ function resolveCodexPath(repoRoot, scope) {
875
903
  }
876
904
  function isAgentInsightsCommand2(cmd) {
877
905
  if (!cmd) return false;
878
- return cmd.startsWith(`${HOOK_COMMAND_NAME2} hook`);
906
+ if (cmd.startsWith(`${HOOK_COMMAND_NAME2} hook`)) return true;
907
+ return /\bagent-insights\b.*\bcli\.js\b.*\bhook\b/.test(cmd);
879
908
  }
880
909
  function isHookCommand2(value) {
881
910
  if (!value || typeof value !== "object") return false;
@@ -913,7 +942,7 @@ function removeAgentInsightsMatchers2(matchers) {
913
942
  return result;
914
943
  }
915
944
  function addAgentInsightsHook2(matchers, event) {
916
- const command = `${HOOK_COMMAND_NAME2} hook ${event}`;
945
+ const command = hookCommandString(event);
917
946
  const entry = { type: "command", command };
918
947
  for (const group of matchers) {
919
948
  if (group.matcher === "") {
@@ -992,7 +1021,7 @@ var cursorAdapter = {
992
1021
  const existing = (hooks[event] ?? []).filter(
993
1022
  (h) => !isAgentInsightsCommand3(h.command)
994
1023
  );
995
- existing.push({ command: `${HOOK_COMMAND_NAME3} hook ${event}` });
1024
+ existing.push({ command: hookCommandString(event) });
996
1025
  hooks[event] = existing;
997
1026
  }
998
1027
  next.hooks = hooks;
@@ -1038,7 +1067,8 @@ function resolveCursorPath(repoRoot, scope) {
1038
1067
  }
1039
1068
  function isAgentInsightsCommand3(cmd) {
1040
1069
  if (!cmd) return false;
1041
- return cmd.startsWith(`${HOOK_COMMAND_NAME3} hook`);
1070
+ if (cmd.startsWith(`${HOOK_COMMAND_NAME3} hook`)) return true;
1071
+ return /\bagent-insights\b.*\bcli\.js\b.*\bhook\b/.test(cmd);
1042
1072
  }
1043
1073
  async function readJson3(path) {
1044
1074
  try {
@@ -1067,6 +1097,7 @@ var HOOK_MAP4 = {
1067
1097
  var PI_HOOK_EVENTS = Object.keys(HOOK_MAP4);
1068
1098
  var EXTENSION_MARKER = "// installed-by: agent-insights";
1069
1099
  function extensionSource() {
1100
+ const { node, script } = hookCommandArgv("Placeholder");
1070
1101
  return `${EXTENSION_MARKER}
1071
1102
  // Generated by \`agent-insights init\`. Edit-with-caution: it's overwritten on every install.
1072
1103
 
@@ -1074,10 +1105,12 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
1074
1105
  import { spawn } from "node:child_process";
1075
1106
 
1076
1107
  const EVENTS = ${JSON.stringify(PI_HOOK_EVENTS)} as const;
1108
+ const NODE_BIN = ${JSON.stringify(node)};
1109
+ const CLI_SCRIPT = ${JSON.stringify(script)};
1077
1110
 
1078
1111
  function emit(event: string, payload: Record<string, unknown>): void {
1079
1112
  try {
1080
- const child = spawn("agent-insights", ["hook", event], {
1113
+ const child = spawn(NODE_BIN, [CLI_SCRIPT, "hook", event], {
1081
1114
  stdio: ["pipe", "ignore", "ignore"],
1082
1115
  detached: true,
1083
1116
  });
@@ -1557,7 +1590,7 @@ function buildEvent(adapter, mapped) {
1557
1590
  var STDIN_TIMEOUT_MS = 200;
1558
1591
  async function readStdinSafely() {
1559
1592
  if (process.stdin.isTTY) return "";
1560
- return new Promise((resolve) => {
1593
+ return new Promise((resolve2) => {
1561
1594
  let buf = "";
1562
1595
  let settled = false;
1563
1596
  const finish = () => {
@@ -1571,7 +1604,7 @@ async function readStdinSafely() {
1571
1604
  process.stdin.unref();
1572
1605
  } catch {
1573
1606
  }
1574
- resolve(buf);
1607
+ resolve2(buf);
1575
1608
  };
1576
1609
  const idle = setTimeout(finish, STDIN_TIMEOUT_MS);
1577
1610
  idle.unref();
@@ -1737,6 +1770,9 @@ async function promptChoices(opts) {
1737
1770
  bypassSecret = opts.bypassSecret;
1738
1771
  } else {
1739
1772
  const existing = await loadBypassSecret();
1773
+ log.hint(
1774
+ `Generate one at ${kleur3.underline("https://vercel.com/vercel-labs/agent-insights/settings/deployment-protection#protection-bypass-for-automation")}`
1775
+ );
1740
1776
  const answer = await safePrompt(
1741
1777
  () => password({
1742
1778
  message: existing ? "Vercel deployment-protection bypass secret (Enter to keep existing, '-' to clear):" : "Vercel deployment-protection bypass secret (Enter to skip):",
@@ -1917,7 +1953,7 @@ function yn(v) {
1917
1953
  var program = new Command();
1918
1954
  program.name("agent-insights").description(
1919
1955
  "Internal CLI for AI coding agent observability (Claude Code, Cursor)."
1920
- ).version("0.0.16");
1956
+ ).version("0.0.18");
1921
1957
  program.command("login").description("Authenticate with Vercel (Sign in with Vercel).").action(async () => {
1922
1958
  await runLogin();
1923
1959
  });