Skip to main content
Glama

check_before_edit

Review warnings about past mistakes, decisions, and requirements before editing files to maintain project consistency.

Instructions

Check context before editing a file - get warnings about past mistakes, decisions, and requirements to maintain consistency

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_pathNoPath to manuscript directory (defaults to current directory)
file_pathYesFile to check before editing

Implementation Reference

  • Tool handler: extracts file_path from args and delegates execution to WritersAid instance
    private async checkBeforeEdit(args: Record<string, unknown>) {
      const filePath = args.file_path as string;
    
      return this.writersAid.checkBeforeEdit({ filePath });
    }
  • MCP tool schema: defines input schema requiring file_path and provides description
    {
      name: "check_before_edit",
      description: "Check context before editing a file - get warnings about past mistakes, decisions, and requirements to maintain consistency",
      inputSchema: {
        type: "object",
        properties: {
          project_path: { type: "string", description: "Path to manuscript directory (defaults to current directory)" },
          file_path: { type: "string", description: "File to check before editing" },
        },
        required: ["file_path"],
      },
    },
  • Core implementation: Queries SQLite DB for file-related decisions, mistakes, commits, concepts; computes warnings by severity, provides full context and summary to guide edits
    async checkBeforeEdit(filePath: string): Promise<{
      filePath: string;
      shouldProceed: boolean;
      warnings: Array<{
        type: "mistake" | "decision" | "requirement";
        severity: "high" | "medium" | "low";
        message: string;
        details: string;
        timestamp?: number;
      }>;
      context: {
        recentDecisions: Array<{
          decision: string;
          rationale?: string;
          timestamp: number;
        }>;
        pastMistakes: Array<{
          mistake: string;
          correction?: string;
          howFixed?: string;
          timestamp: number;
        }>;
        recentCommits: Array<{
          hash: string;
          message: string;
          timestamp: number;
        }>;
        relatedConcepts: Array<{
          name: string;
          definition: string;
          version: number;
        }>;
      };
      summary: string;
    }> {
      const warnings: Array<{
        type: "mistake" | "decision" | "requirement";
        severity: "high" | "medium" | "low";
        message: string;
        details: string;
        timestamp?: number;
      }> = [];
    
      // Get file-specific decisions
      const decisionRows = this.db
        .prepare(
          `SELECT decision_text, rationale, timestamp, decision_type
           FROM writing_decisions
           WHERE file_path = ?
           ORDER BY timestamp DESC
           LIMIT 5`
        )
        .all(filePath) as Array<{
        decision_text: string;
        rationale: string | null;
        timestamp: number;
        decision_type: string | null;
      }>;
    
      const recentDecisions = decisionRows.map((row) => ({
        decision: row.decision_text,
        rationale: row.rationale || undefined,
        timestamp: row.timestamp,
      }));
    
      // Add warnings for important decisions
      for (const decision of decisionRows) {
        if (
          decision.decision_type === "structure" ||
          decision.decision_type === "terminology"
        ) {
          warnings.push({
            type: "decision",
            severity: "medium",
            message: `Previous ${decision.decision_type} decision exists`,
            details: decision.decision_text,
            timestamp: decision.timestamp,
          });
        }
      }
    
      // Get file-specific mistakes
      const mistakeRows = this.db
        .prepare(
          `SELECT description, correction, how_fixed, timestamp, mistake_type
           FROM writing_mistakes
           WHERE file_path = ?
           ORDER BY timestamp DESC
           LIMIT 5`
        )
        .all(filePath) as Array<{
        description: string;
        correction: string | null;
        how_fixed: string | null;
        timestamp: number;
        mistake_type: string;
      }>;
    
      const pastMistakes = mistakeRows.map((row) => ({
        mistake: row.description,
        correction: row.correction || undefined,
        howFixed: row.how_fixed || undefined,
        timestamp: row.timestamp,
      }));
    
      // Add high-priority warnings for recent mistakes
      for (const mistake of mistakeRows) {
        const daysSince = (Date.now() - mistake.timestamp) / (1000 * 60 * 60 * 24);
        const severity = daysSince < 7 ? "high" : daysSince < 30 ? "medium" : "low";
    
        warnings.push({
          type: "mistake",
          severity: severity as "high" | "medium" | "low",
          message: `Past ${mistake.mistake_type} error in this file`,
          details: mistake.description,
          timestamp: mistake.timestamp,
        });
      }
    
      // Get recent commits for the file
      const commitRows = this.db
        .prepare(
          `SELECT commit_hash, message, timestamp
           FROM manuscript_commits
           WHERE files_changed LIKE ?
           ORDER BY timestamp DESC
           LIMIT 5`
        )
        .all(`%"${filePath}"%`) as Array<{
        commit_hash: string;
        message: string;
        timestamp: number;
      }>;
    
      const recentCommits = commitRows.map((row) => ({
        hash: row.commit_hash.substring(0, 8),
        message: row.message,
        timestamp: row.timestamp * 1000,
      }));
    
      // Get concepts mentioned in file
      const conceptRows = this.db
        .prepare(
          `SELECT concept_name, definition, version_number
           FROM concept_evolution
           WHERE file_path = ?
           ORDER BY version_number DESC
           LIMIT 3`
        )
        .all(filePath) as Array<{
        concept_name: string;
        definition: string;
        version_number: number;
      }>;
    
      const relatedConcepts = conceptRows.map((row) => ({
        name: row.concept_name,
        definition: row.definition,
        version: row.version_number,
      }));
    
      // Generate summary
      const summaryParts: string[] = [];
      if (recentDecisions.length > 0) {
        summaryParts.push(
          `${recentDecisions.length} previous decision(s) recorded`
        );
      }
      if (pastMistakes.length > 0) {
        summaryParts.push(`${pastMistakes.length} past mistake(s) to avoid`);
      }
      if (recentCommits.length > 0) {
        summaryParts.push(
          `${recentCommits.length} recent commit(s) for context`
        );
      }
      if (relatedConcepts.length > 0) {
        summaryParts.push(`${relatedConcepts.length} concept(s) defined here`);
      }
    
      const summary =
        summaryParts.length > 0
          ? summaryParts.join(", ")
          : "No prior context found for this file";
    
      // Determine if editing should proceed with caution
      const highSeverityWarnings = warnings.filter((w) => w.severity === "high");
      const shouldProceed = highSeverityWarnings.length === 0;
    
      return {
        filePath,
        shouldProceed,
        warnings: warnings.sort((a, b) => {
          const severityOrder = { high: 0, medium: 1, low: 2 };
          return severityOrder[a.severity] - severityOrder[b.severity];
        }),
        context: {
          recentDecisions,
          pastMistakes,
          recentCommits,
          relatedConcepts,
        },
        summary,
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'get warnings' but doesn't disclose behavioral traits such as output format, error handling, performance characteristics, or whether it's read-only or has side effects. For a tool with no annotation coverage, this leaves significant gaps in understanding how it behaves beyond basic purpose.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Check context before editing a file') and elaborates concisely on the specific warnings provided. Every word earns its place with no redundancy or unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that likely returns complex warnings or validation results. It doesn't explain what 'warnings' entail, how they're formatted, or what 'consistency' means in practice. For a pre-edit check tool, this leaves the agent guessing about the tool's output and operational impact.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('project_path' and 'file_path') adequately. The description adds no additional parameter semantics beyond what's in the schema, such as file format expectations or validation rules. Baseline 3 is appropriate since the schema handles parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Check context before editing a file' with specific goals ('get warnings about past mistakes, decisions, and requirements to maintain consistency'). It distinguishes itself from siblings like 'get_file_context' or 'get_requirements' by focusing on pre-edit validation rather than general information retrieval. However, it doesn't explicitly contrast with all similar tools like 'validate_structure' or 'check_readability'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context ('before editing a file') but lacks explicit guidance on when to use this versus alternatives like 'validate_structure' or 'check_terminology'. It doesn't specify prerequisites, exclusions, or edge cases, leaving the agent to infer timing from the phrase 'before editing' without clear operational boundaries.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/xiaolai/claude-writers-aid-mcp'

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