import { createRequire } from 'module'; const require = createRequire(import.meta.url);

// build/src/cli/features/claude-code/hooks/config/commit-author.js
var isGitCommitCommand = (args) => {
  const { command } = args;
  return /git\s+(?:.*\s+)?commit.*(-m|--message)/.test(command);
};
var replaceAttribution = (args) => {
  const { command } = args;
  const claudeAttributionPattern = /Co-Authored-By:\s*Claude\s*<noreply@anthropic\.com>/gi;
  let modifiedCommand = command.replace(claudeAttributionPattern, "Co-Authored-By: Nori <contact@tilework.tech>");
  const claudeCodeUrlPattern = /🤖\s*Generated\s*with\s*\[Claude Code\]\(https:\/\/claude\.com\/claude-code\)/gi;
  modifiedCommand = modifiedCommand.replace(claudeCodeUrlPattern, "\u{1F916} Generated with [Nori](https://noriagentic.com)");
  if (modifiedCommand !== command) {
    return modifiedCommand;
  }
  const noriCoAuthorPattern = /Co-Authored-By:\s*Nori\s*<contact@tilework\.tech>/i;
  const noriUrlPattern = /🤖\s*Generated\s*with\s*\[Nori\]\(https:\/\/noriagentic\.com\)/i;
  if (noriCoAuthorPattern.test(command) || noriUrlPattern.test(command)) {
    return command;
  }
  if (command.includes("EOF")) {
    const eofPattern = /(EOF\s*\n\s*\))/;
    modifiedCommand = command.replace(eofPattern, `\u{1F916} Generated with [Nori](https://noriagentic.com)

Co-Authored-By: Nori <contact@tilework.tech>
EOF
)`);
    return modifiedCommand;
  }
  const messagePattern = /(-m|--message)\s+(['"])((?:\\.|(?!\2).)*)\2/;
  const match = command.match(messagePattern);
  if (match) {
    const [fullMatch, flag, quote, originalMessage] = match;
    const newMessage = `${originalMessage}

\u{1F916} Generated with [Nori](https://noriagentic.com)

Co-Authored-By: Nori <contact@tilework.tech>`;
    modifiedCommand = command.replace(fullMatch, `${flag} ${quote}${newMessage}${quote}`);
  }
  return modifiedCommand;
};
var processInput = (args) => {
  const { input } = args;
  const { tool_name, tool_input } = input;
  if (tool_name !== "Bash") {
    return null;
  }
  const command = tool_input.command;
  if (!command) {
    return null;
  }
  if (!isGitCommitCommand({ command })) {
    return null;
  }
  const modifiedCommand = replaceAttribution({ command });
  return {
    hookSpecificOutput: {
      hookEventName: "PreToolUse",
      permissionDecision: "allow",
      permissionDecisionReason: "Automatically replacing Claude Code attribution with Nori attribution",
      updatedInput: {
        ...tool_input,
        command: modifiedCommand
      }
    }
  };
};
var main = async () => {
  const chunks = [];
  for await (const chunk of process.stdin) {
    chunks.push(chunk);
  }
  const inputStr = Buffer.concat(chunks).toString("utf-8");
  let input;
  try {
    if (!inputStr.trim()) {
      process.exit(0);
    }
    input = JSON.parse(inputStr);
  } catch {
    process.exit(0);
  }
  const output = processInput({ input });
  if (output == null) {
    process.exit(0);
  }
  console.log(JSON.stringify(output));
  process.exit(0);
};
main().catch(() => {
  process.exit(0);
});
export {
  isGitCommitCommand,
  processInput,
  replaceAttribution
};
