propose_commit
Validate and save code files by enforcing strict formatting rules, including header comments, nesting depth, and file length limits, while creating restore points for safety.
Instructions
The ONLY way to write code. Validates the code against strict rules before saving: 2-line header comments, no inline comments, max nesting depth, max file length. Creates a shadow restore point before writing. REJECTS code that violates formatting rules.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Where to save the file (relative to project root). | |
| new_content | Yes | The complete file content to save. |
Implementation Reference
- src/tools/propose-commit.ts:99-135 (handler)The proposeCommit function implements the core tool logic: validating file headers, inline comments, and code complexity (nesting depth) before saving the file and creating a shadow restore point.
export async function proposeCommit(options: ProposeCommitOptions): Promise<string> { const fullPath = resolve(options.rootDir, options.filePath); const ext = extname(fullPath); const lines = options.newContent.split("\n"); const allErrors: ValidationError[] = []; if (isSupportedFile(fullPath)) { allErrors.push(...validateHeader(lines, ext)); allErrors.push(...validateNoInlineComments(lines, ext)); } allErrors.push(...validateAbstraction(lines)); const commentErrors = allErrors.filter((e) => e.rule === "no-comments"); if (commentErrors.length > 5) { return [ `REJECTED: ${allErrors.length} violations found.\n`, ...allErrors.slice(0, 10).map((e) => ` ❌ [${e.rule}] ${e.message}`), allErrors.length > 10 ? ` ... and ${allErrors.length - 10} more violations` : "", "\nFix all violations and resubmit.", ].join("\n"); } const warnings = allErrors.filter((e) => e.rule !== "no-comments" || commentErrors.length <= 5); await createRestorePoint(options.rootDir, [options.filePath], `Pre-commit: ${options.filePath}`); await mkdir(dirname(fullPath), { recursive: true }); await writeFile(fullPath, options.newContent, "utf-8"); const result = [`✅ File saved: ${options.filePath}`]; if (warnings.length > 0) { result.push(`\n⚠ ${warnings.length} warning(s):`); for (const w of warnings) result.push(` ⚠ [${w.rule}] ${w.message}`); } result.push(`\nRestore point created. Use undo tools if needed.`); return result.join("\n"); } - src/tools/propose-commit.ts:9-13 (schema)Input validation interface for propose_commit tool.
export interface ProposeCommitOptions { rootDir: string; filePath: string; newContent: string; }