apply_auto_corrections
Fix text by applying auto-correction patterns from a chosen tool context, using persistent syntax rules and best practices that carry over across chat sessions.
Instructions
Apply auto-correction patterns from matching contexts to text
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text to apply corrections to | |
| tool_name | Yes | Tool context to use for corrections |
Implementation Reference
- src/engine/engine.ts:277-279 (helper)Engine delegate method that calls contextMatcher.getAutoCorrections() to fetch correction rules for the given tool.
getAutoCorrections(tool: string) { return this.contextMatcher.getAutoCorrections(this.contexts, tool); } - src/engine/context-matcher.ts:62-88 (helper)Core logic: matches contexts to the given tool, iterates their auto_corrections, and returns an array of {name, pattern, replacement} objects.
getAutoCorrections( contexts: Map<string, Context>, tool: string, ): Array<{ name: string; pattern: string; replacement: string }> { const matches = this.match(contexts, { tool }); const corrections: Array<{ name: string; pattern: string; replacement: string; }> = []; for (const { context } of matches) { if (!context.auto_convert || !context.auto_corrections) continue; for (const [name, correction] of Object.entries( context.auto_corrections, )) { corrections.push({ name, pattern: correction.pattern, replacement: correction.replacement, }); } } return corrections; } - src/schema/context.schema.ts:38-41 (schema)Zod schema for AutoCorrection: validates pattern (min 1 char) and replacement strings.
export const AutoCorrectionSchema = z.object({ pattern: z.string().min(1), replacement: z.string(), }); - src/types/context.ts:62-68 (schema)TypeScript interface for AutoCorrection with pattern (regex) and replacement (supports capture group refs).
export interface AutoCorrection { /** Regex pattern to match. */ pattern: string; /** Replacement string (supports capture group refs: $1, $2). */ replacement: string; }