Skip to main content
Glama

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
NameRequiredDescriptionDefault
file_pathYesWhere to save the file (relative to project root).
new_contentYesThe complete file content to save.

Implementation Reference

  • 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");
    }
  • Input validation interface for propose_commit tool.
    export interface ProposeCommitOptions {
      rootDir: string;
      filePath: string;
      newContent: string;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ForLoopCodes/contextplus'

If you have feedback or need assistance with the MCP directory API, please join our Discord server