// Example mod: redact secrets from everything the transcript keeps. // // hooks.transformMessage sees every message before it is committed: your prompt, each model // reply, every tool result, steering and follow-up messages. What it returns is what the // transcript stores AND what every later request sends, so a key a tool printed never reaches // the model on the next turn. The role and every tool_use / tool_result id must stay as they // were; a rewrite that changes them is rejected and the message is kept. import type {ModApi} from '@commandcode/harness'; const SECRET_PATTERNS = [ /\bsk-[A-Za-z0-9_-]{16,}\b/g, // API keys /\bgh[pousr]_[A-Za-z0-9]{20,}\b/g, // GitHub tokens /\bAKIA[0-9A-Z]{16}\b/g, // AWS access key ids ]; function redact(text: string): string { return SECRET_PATTERNS.reduce( (current, pattern) => current.replace(pattern, '[REDACTED]'), text, ); } export default function (cmd: ModApi): void { cmd.hooks({ transformMessage: ({message}) => { if (message.role === 'assistant') return message; return { ...message, content: message.content.map(block => { if (block.type === 'text') return {...block, text: redact(block.text)}; if (block.type !== 'tool_result') return block; return { ...block, content: block.content.map(part => part.type === 'text' ? {...part, text: redact(part.text)} : part, ), }; }), }; }, }); }