caveat-cli 0.17.4 → 0.17.6

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/index.js CHANGED
@@ -6900,8 +6900,8 @@ import { join as join3 } from "node:path";
6900
6900
  // src/installShared.ts
6901
6901
  import { accessSync, copyFileSync, existsSync, mkdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
6902
6902
  import { dirname as dirname2, isAbsolute } from "node:path";
6903
- function quoteIfSpaces(p) {
6904
- return p.includes(" ") ? `"${p}"` : p;
6903
+ function quoteCommandPath(p) {
6904
+ return /[\s\\]/.test(p) ? `"${p}"` : p;
6905
6905
  }
6906
6906
  function commandTokens(command) {
6907
6907
  const tokens = [];
@@ -6949,7 +6949,7 @@ function mcpArgs(cliScriptPath) {
6949
6949
  return ["--disable-warning=ExperimentalWarning", cliScriptPath, "mcp-server"];
6950
6950
  }
6951
6951
  function hookCommand(nodePath, cliScriptPath, event) {
6952
- return `${quoteIfSpaces(nodePath)} ${quoteIfSpaces(cliScriptPath)} hook ${event}`;
6952
+ return `${quoteCommandPath(nodePath)} ${quoteCommandPath(cliScriptPath)} hook ${event}`;
6953
6953
  }
6954
6954
  function upsertHook(settings, event, command) {
6955
6955
  settings.hooks ??= {};
@@ -6959,7 +6959,7 @@ function upsertHook(settings, event, command) {
6959
6959
  for (const hook2 of entry.hooks ?? []) {
6960
6960
  if (isSameHookCommand(hook2.command, command)) return "unchanged";
6961
6961
  if (subcommand && isCaveatClaudeHookCommand(hook2.command, subcommand)) {
6962
- hook2.command = command;
6962
+ hook2.command = `${envPrefix(hook2.command)}${command}`;
6963
6963
  return "added";
6964
6964
  }
6965
6965
  }
@@ -6990,14 +6990,15 @@ function findExistingHookCommand(settings, event, command) {
6990
6990
  function isSameHookCommand(actual, expected) {
6991
6991
  return actual === expected || actual.endsWith(` ${expected}`);
6992
6992
  }
6993
- function isEnvPrefixedCommand(command) {
6994
- return /^[A-Z_][A-Z0-9_]*=/.test(command.trim());
6993
+ function envPrefix(command) {
6994
+ return command.match(/^((?:[A-Z_][A-Z0-9_]*=(?:"[^"]*"|'[^']*'|\S+)\s+)+)/)?.[1] ?? "";
6995
6995
  }
6996
6996
  function isCaveatClaudeHookCommand(actual, event) {
6997
6997
  const lower = actual.toLowerCase();
6998
- return !isEnvPrefixedCommand(actual) && lower.includes("caveat") && actual.includes(`hook ${event}`);
6998
+ return lower.includes("caveat") && actual.includes(`hook ${event}`);
6999
6999
  }
7000
7000
  function isCanonicalCaveatClaudeHookCommand(actual, event, nodePath, cliScriptPath) {
7001
+ if (actual !== hookCommand(nodePath, cliScriptPath, event)) return false;
7001
7002
  const tokens = commandTokens(actual);
7002
7003
  return tokens?.length === 4 && isCanonicalAsset(tokens[0], nodePath, constants.X_OK) && isCanonicalAsset(tokens[1], cliScriptPath, constants.R_OK) && tokens[2] === "hook" && tokens[3] === event;
7003
7004
  }
@@ -7133,7 +7134,7 @@ import { constants as constants2, existsSync as existsSync3, readFileSync as rea
7133
7134
  import { join as join4 } from "node:path";
7134
7135
  import { parse as parseToml } from "smol-toml";
7135
7136
  function hookCommand2(nodePath, cliScriptPath, event, platform = process.platform) {
7136
- return `${powershellCallPrefix(platform)}${quoteIfSpaces(nodePath)} ${quoteIfSpaces(cliScriptPath)} codex-hook ${event}`;
7137
+ return `${powershellCallPrefix(platform)}${quoteCommandPath(nodePath)} ${quoteCommandPath(cliScriptPath)} codex-hook ${event}`;
7137
7138
  }
7138
7139
  function eventCommandFragment(event) {
7139
7140
  return `codex-hook ${event}`;