Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mergeMessage.ts

53 lines2.0 KB

1const AGENT_EMAILS = new Set([
2 "noreply@anthropic.com",
3 "claude@anthropic.com",
4 "noreply@openai.com",
5 "codex@openai.com",
6 "cursoragent@cursor.com",
7 "copilot@github.com",
8 "noreply@github.com",
9]);
10​
11const GENERATED_BY_AGENT =
12 /^(?:πŸ€–\s*)?generated (?:with|by)\s+(?:claude(?: code)?|codex|cursor|github copilot|copilot|opencode|grok|antigravity)[.!]?$/i;
13​
14export function removeAgentCredits(message: string): string {
15 let fence: string | undefined;
16 let removed = false;
17 const newline = message.includes("\r\n") ? "\r\n" : "\n";
18 const lines = message.split(/\r?\n/).filter((line) => {
19 if (/^(?: {4}|\t)/.test(line)) return true;
20 const delimiter = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line);
21 const marker = delimiter?.[1];
22 const remainder = delimiter?.[2] ?? "";
23 if (marker !== undefined) {
24 if (fence === undefined) {
25 if (marker[0] === "~" || !remainder.includes("`")) fence = marker;
26 } else if (
27 marker[0] === fence[0] &&
28 marker.length >= fence.length &&
29 /^[ \t]*$/.test(remainder)
30 ) {
31 fence = undefined;
32 }
33 return true;
34 }
35 if (fence !== undefined) return true;
36 const text = line.trim().replace(/^(?:[-*]\s+)/, "");
37 const author = /^co-authored-by:\s*(.*?)\s*<([^<>]+)>\s*$/i.exec(text);
38 // GitHub's generic noreply address is also used by people; require Copilot's name.
39 const email = author?.[2]?.toLowerCase();
40 const agentAuthor =
41 email !== undefined &&
42 AGENT_EMAILS.has(email) &&
43 (email !== "noreply@github.com" || /^github copilot$|^copilot$/i.test(author![1]!));
44 const footer = text.replace(
45 /\[([^\]]+)\]\(https:\/\/(?:claude\.ai|claude\.com|www\.anthropic\.com|chatgpt\.com|openai\.com|cursor\.com|github\.com|opencode\.ai|x\.ai|antigravity\.google)(?:\/[^\s)]*)?\)/gi,
46 "$1",
47 );
48 if (!agentAuthor && !GENERATED_BY_AGENT.test(footer)) return true;
49 removed = true;
50 return false;
51 });
52 return removed ? lines.join(newline).replace(/(?:\r?\n[ \t]*)+$/, "") : message;