Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe("removeAgentCredits", () => {
"* Co-authored-by: Codex <noreply@openai.com>",
"co-authored-by: Cursor <cursoragent@cursor.com>",
"Co-authored-by: Copilot <copilot@github.com>",
"Co-Authored-By:\tGitHub Copilot <NOREPLY@GITHUB.COM>",
"",
"🤖 Generated with [Claude Code](https://claude.ai/code)",
].join("\n"),
Expand Down
41 changes: 28 additions & 13 deletions packages/source-control-core/src/server/mergeMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ const AGENT_EMAILS = new Set([
const GENERATED_BY_AGENT =
/^(?:🤖\s*)?generated (?:with|by)\s+(?:claude(?: code)?|codex|cursor|github copilot|copilot|opencode|grok|antigravity)[.!]?$/i;

const CO_AUTHOR_PREFIX = /^co-authored-by:/i;

function isAgentAuthor(text: string): boolean {
const prefix = CO_AUTHOR_PREFIX.exec(text);
if (prefix === null || !text.endsWith(">")) return false;
const emailStart = text.lastIndexOf("<");
if (emailStart < prefix[0].length) return false;
const email = text.slice(emailStart + 1, -1).toLowerCase();
if (!AGENT_EMAILS.has(email)) return false;
// GitHub's generic noreply address is also used by people; require Copilot's name.
return (
email !== "noreply@github.com" ||
/^(?:github )?copilot$/i.test(text.slice(prefix[0].length, emailStart).trim())
);
}

export function removeAgentCredits(message: string): string {
let fence: string | undefined;
let removed = false;
Expand All @@ -34,20 +50,19 @@ export function removeAgentCredits(message: string): string {
}
if (fence !== undefined) return true;
const text = line.trim().replace(/^(?:[-*]\s+)/, "");
const author = /^co-authored-by:\s*(.*?)\s*<([^<>]+)>\s*$/i.exec(text);
// GitHub's generic noreply address is also used by people; require Copilot's name.
const email = author?.[2]?.toLowerCase();
const agentAuthor =
email !== undefined &&
AGENT_EMAILS.has(email) &&
(email !== "noreply@github.com" || /^github copilot$|^copilot$/i.test(author![1]!));
const footer = text.replace(
/\[([^\]]+)\]\(https:\/\/(?:claude\.ai|claude\.com|www\.anthropic\.com|chatgpt\.com|openai\.com|cursor\.com|github\.com|opencode\.ai|x\.ai|antigravity\.google)(?:\/[^\s)]*)?\)/gi,
"$1",
);
if (!agentAuthor && !GENERATED_BY_AGENT.test(footer)) return true;
if (!isAgentAuthor(text)) {
const footer = text.replace(
/\[([^[\]\r\n]+)\]\(https:\/\/(?:claude\.ai|claude\.com|www\.anthropic\.com|chatgpt\.com|openai\.com|cursor\.com|github\.com|opencode\.ai|x\.ai|antigravity\.google)(?:\/[^\s)[\]]*)?\)/gi,
"$1",
);
if (!GENERATED_BY_AGENT.test(footer)) return true;
}
removed = true;
return false;
});
return removed ? lines.join(newline).replace(/(?:\r?\n[ \t]*)+$/, "") : message;
if (!removed) return message;
while (lines.length > 1 && /^[ \t]*$/.test(lines.at(-1)!)) {
lines.pop();
}
return lines.join(newline);
}
Loading