Model Guided Code Repair logo

Model Guided Code Repair

Community
ArabelaTso
model-guided-code-repair

Automatically repair code violations of temporal properties using model-checking counterexamples as guidance. Use when working with formal verification results, temporal logic property violations (LTL, CTL), model checking counterexamples, or when asked to repair property violations, fix counterexamples, repair temporal properties, fix model checking violations, or repair code based on counterexamples. Applicable to concurrent systems, state machines, synchronization issues, safety/liveness properties, and resource management violations.

Overview

PublisherArabelaTso
RepositorySkills-4-SE
Skill namemodel-guided-code-repair
Stars
258
Forks
25
Bundled files
1
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by ArabelaTso on GitHub. Read the source before you install it.

Installation

Install the Model Guided Code Repair AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/model-guided-code-repair
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE.git /tmp/Skills-4-SE
mkdir -p .claude/skills
cp -r /tmp/Skills-4-SE/skills/model-guided-code-repair .claude/skills/model-guided-code-repair
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Model Guided Code Repair in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Model Guided Code Repair on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Model Guided Code Repair is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Model-Guided Code Repair

Overview

This skill enables automatic repair of code that violates temporal properties by analyzing model-checking counterexamples. It reasons about the root cause of violations at the model level, proposes minimal and semantically justified code modifications, and validates repairs through re-verification or test generation.

Repair Workflow

Follow this sequential process when repairing temporal property violations:

1. Analyze Input

Gather and understand three required inputs:

  • Program source code: The code containing the violation
  • Violated temporal property: The formal specification (LTL, CTL, or natural language description)
  • Counterexample trace: The execution path demonstrating the violation

Read all inputs carefully. If the temporal property is in natural language, formalize it first.

2. Understand the Counterexample

Trace through the counterexample step-by-step:

  • Identify the sequence of states and transitions
  • Map counterexample states to program locations (line numbers, function calls)
  • Identify variable values at each step
  • Pinpoint the exact moment the property is violated

Output: A clear narrative of the execution path leading to the violation.

3. Identify Root Cause

Analyze why the violation occurs:

  • Missing guards: Are conditions missing that should prevent certain transitions?
  • Incorrect ordering: Are operations executed in the wrong sequence?
  • Race conditions: Are there synchronization issues in concurrent code?
  • Missing state updates: Are variables not being updated correctly?
  • Incorrect logic: Are conditional expressions wrong?

Output: A precise diagnosis of the model-level cause.

4. Propose Repair Strategy

Design a minimal repair that:

  • Directly addresses the root cause
  • Preserves intended program behavior
  • Minimizes code changes
  • Maintains code readability

Common repair strategies:

  • Add guards: Insert conditional checks to prevent invalid transitions
  • Reorder operations: Adjust execution sequence to satisfy temporal ordering
  • Add synchronization: Insert locks, semaphores, or barriers for concurrent code
  • Update state management: Fix variable assignments or state transitions
  • Strengthen preconditions: Add assertions or input validation

Output: A clear repair plan with justification.

5. Generate Repaired Code

Implement the repair:

  • Make minimal, targeted changes to the source code
  • Clearly mark what was changed (comments or annotations)
  • Ensure the repair is syntactically correct
  • Preserve existing code style and conventions

Output: Modified source code with changes clearly indicated.

6. Validate the Repair

Verify that the repair resolves the violation:

Option A: Re-run Model Checker

  • Execute the model checker on the repaired code
  • Verify the temporal property now holds
  • Check that no new violations were introduced

Option B: Generate and Run Tests

  • Create test cases based on the counterexample
  • Generate additional tests for edge cases
  • Execute tests and verify they pass
  • Ensure existing tests still pass (regression testing)

Output: Validation results showing the property is satisfied.

7. Document the Repair

Provide a comprehensive explanation:

  • Root cause: What caused the violation
  • Repair strategy: Why this approach was chosen
  • Minimality justification: Why this is the smallest necessary change
  • Behavior preservation: How intended functionality is maintained
  • Validation results: Evidence that the repair works

Output Format

Structure the final output as follows:

## Repaired Code

[Modified source code with changes clearly marked]

## Changes Made

- [Line X]: [Description of change]
- [Line Y]: [Description of change]

## Root Cause Analysis

[Explanation of what caused the violation]

## Repair Strategy

[Why this repair approach was chosen]
[Why it is minimal and semantically justified]

## Behavior Preservation

[How the repair maintains intended program behavior]

## Validation Results

[Model checking results OR test execution results]
[Confirmation that the property now holds]

Common Scenarios

Safety Property Violations

Example: "The system must never enter an error state"

  • Look for missing error checks or exception handling
  • Add guards to prevent invalid state transitions
  • Validate with assertions or model checking

Liveness Property Violations

Example: "Every request must eventually be processed"

  • Look for deadlocks, infinite loops, or missing progress conditions
  • Add fairness constraints or progress guarantees
  • Validate with liveness checking or timeout tests

Synchronization Issues

Example: "Shared resources must be accessed atomically"

  • Look for race conditions or missing locks
  • Add synchronization primitives (mutexes, semaphores)
  • Validate with concurrency testing or model checking

State Machine Violations

Example: "State transitions must follow the specified protocol"

  • Look for missing state checks or incorrect transition logic
  • Add state validation or fix transition conditions
  • Validate with state machine verification

Tips for Effective Repairs

  • Start simple: Try the minimal fix first before complex refactoring
  • Preserve structure: Maintain the original code architecture when possible
  • Consider side effects: Ensure repairs don't break other properties
  • Document assumptions: Note any assumptions made during repair
  • Test thoroughly: Validate beyond just the violated property
  • Iterate if needed: If the first repair doesn't work, analyze why and adjust

Integration with Model Checkers

This skill works with various model checking tools:

  • SPIN: For Promela models and LTL properties
  • NuSMV/nuXmv: For SMV models and CTL/LTL properties
  • CBMC: For C programs with assertions
  • Java PathFinder: For Java programs
  • TLA+: For TLA+ specifications

When counterexamples are provided in tool-specific formats, translate them into a clear execution trace before analysis.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Model Guided Code Repair AI skill do?

Automatically repair code violations of temporal properties using model-checking counterexamples as guidance. Use when working with formal verification results, temporal logic property violations (LTL, CTL), model checking counterexamples, or when asked to repair property violations, fix counterexamples, repair temporal properties, fix model checking violations, or repair code based on counterexamples. Applicable to concurrent systems, state machines, synchronization issues, safety/liveness properties, and resource management violations.

Why use Model Guided Code Repair on TypingMind?

Because you install it once and use it with any model. Model Guided Code Repair is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Model Guided Code Repair in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/model-guided-code-repair. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Model Guided Code Repair?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Model Guided Code Repair?

As many as you like. As long as a model supports skills, you can use Model Guided Code Repair with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Model Guided Code Repair AI skill free?

Yes. It is published on GitHub by ArabelaTso under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇