/** * Commit trailer block that the Bash and ExecCommand tool descriptions tell the * agent to end git commit messages with. * * The descriptions contain a `{{COMMIT_TRAILER}}` placeholder. By default it * becomes the standard Letta Code block (the "Generated with" line, a blank * line, and the co-author line). Deployments that run the agent under their own * identity can set `BASH_COMMIT_TRAILER` to replace the whole block. The value * may span several lines, written either with real newlines or with literal * `\n` escapes (for example * `Generated by Example Bot\n\nCo-Authored-By: Example Bot `). */ export const COMMIT_TRAILER_PLACEHOLDER = "{{COMMIT_TRAILER}}"; export const DEFAULT_COMMIT_TRAILER = "👾 Generated with [Letta Code](https://letta.com)\n\nCo-Authored-By: Letta Code "; /** * Returns the trailer block to use. Literal `\n` escapes are expanded to * newlines and CRLF line endings are normalized. Falls back to the default * when the variable is unset, empty, or whitespace-only. */ export function resolveCommitTrailer( env: NodeJS.ProcessEnv = process.env, ): string { const raw = env.BASH_COMMIT_TRAILER; if (raw === undefined) return DEFAULT_COMMIT_TRAILER; const trailer = raw .replace(/\\r\\n|\\n/g, "\n") .replace(/\r\n?/g, "\n") .trim(); return trailer.length === 0 ? DEFAULT_COMMIT_TRAILER : trailer; } /** * Replaces every trailer placeholder in a tool description. When the * placeholder is indented, each following non-empty line of a multi-line * trailer gets the same indentation so the block stays aligned. */ export function applyCommitTrailer( description: string, trailer: string = resolveCommitTrailer(), ): string { const lines = trailer.split("\n"); return description .split("\n") .map((line) => { const index = line.indexOf(COMMIT_TRAILER_PLACEHOLDER); if (index === -1) return line; const indent = line.slice(0, index); const block = /^[ \t]*$/.test(indent) ? lines .map((trailerLine, i) => i === 0 || trailerLine.length === 0 ? trailerLine : `${indent}${trailerLine}`, ) .join("\n") : trailer; return line.split(COMMIT_TRAILER_PLACEHOLDER).join(block); }) .join("\n"); }