Логотип Model Guided Code Repair

Model Guided Code Repair

Спільнота
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.

Огляд

ВидавецьArabelaTso
РепозиторійSkills-4-SE
Назва навичкиmodel-guided-code-repair
Зірки
258
Форки
25
Файли в пакеті
1
ЛіцензіяApache-2.0
Посилання
  • Інструкції у форматі Markdown

    Файл SKILL.md, який модель завантажує за потреби, тож токени витрачаються лише тоді, коли запит справді відповідає навичці.

  • Працює з будь-якою LLM

    Навички ШІ — це звичайний Markdown, а не код для певного постачальника, тому вони працюють із GPT, Claude, Gemini, Grok або локальною моделлю.

  • Файлів у комплекті: 1

    Скрипти, шаблони й довідкові матеріали, які модель може читати під час роботи. Файли доступні лише для читання й ніколи не виконуються.

  • Відкритий вихідний код

    Видавець на GitHub: ArabelaTso. Перед установленням перегляньте вихідні файли навички.

Встановлення

Установіть навичку ШІ Model Guided Code Repair у TypingMind, щоб використовувати її з будь-якою LLM, або додайте її до іншого агента, що читає SKILL.md.

1

Встановити в TypingMind

TypingMind встановлює навичку безпосередньо з її папки на GitHub — читає SKILL.md, збирає файли ресурсів у пакет і зберігає результат локально.

  1. Відкрийте застосунок і перейдіть до розділу «Плагіни» → «Навички».
  2. Виберіть «Встановити з GitHub».
  3. Вставте наведений нижче URL папки навички та підтвердьте встановлення.
    https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/model-guided-code-repair
  4. Увімкніть навичку в кожному чаті, де хочете її використовувати.
Плагіни → Навички → Додати навичку → За URL GitHub, потім вставте URL папки й натисніть «Продовжити».
2

Встановити в іншому агенті

Будь-який агент, що підтримує формат Agent Skills, може використовувати цю навичку — скопіюйте папку до каталогу навичок цього агента.

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
Після копіювання перезапустіть Claude Code, щоб завантажити нову навичку.

Використовуйте навичку в TypingMind

Увімкніть навичку Model Guided Code Repair в будь-якому чаті TypingMind, і далі модель усе зробить сама. Назва й опис навички містяться в системному промпті, а щойно надходить відповідний запит, модель самостійно завантажує повні інструкції — вам не потрібно викликати навичку вручну, і до фактичного використання вона не витрачає токенів.

Модель самостійно завантажує навичку Model Guided Code Repair, щойно надходить відповідний запит.

Працює з будь-якою моделлю ШІ

Навички ШІ — це звичайні інструкції у форматі Markdown, а не код для певного постачальника, тому навичка Model Guided Code Repair не прив’язана до моделі, для якої її створено. Установіть її один раз у TypingMind і використовуйте з GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama або локальною моделлю, яку ви запускаєте самостійно, — усе з вашими власними ключами API.

  • Завантажується лише за потреби

    Системний промпт містить лише назву й опис. Інструкції завантажуються за першого відповідного запиту, тож поки навичка не потрібна, токени на її інструкції не витрачаються.

  • Змінюйте моделі під час чату

    Оскільки навичка — це інструкції, а не код, зміна моделі не порушує її роботу: наступна модель читає той самий файл SKILL.md.

Інструкції навички

Це вміст файлу SKILL.md, який завантажує модель. Прочитайте його перед установленням — навичка містить інструкції, яких дотримуватиметься ваша модель.

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.

Файли в пакеті

Модель читає ці файли за потреби, поки навичку завантажено. Вони доступні для читання й ніколи не виконуються.

Поширені запитання

Що робить навичка ШІ 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.

Навіщо використовувати Model Guided Code Repair у TypingMind?

Тому що ви встановлюєте її один раз і використовуєте з будь-якою моделлю. Model Guided Code Repair — це звичайний Markdown, а не код для конкретного постачальника, тому та сама навичка працює з GPT-5, Claude, Gemini, Grok або локальною моделлю. Ви можете змінити модель навіть посеред чату, і навичка продовжить працювати. TypingMind використовує ваші власні ключі API, тож ви платите безпосередньо постачальникам замість передплати за кожне місце користувача, а ваші навички й чати залишаються у вашому сховищі.

Як встановити Model Guided Code Repair у TypingMind?

Відкрийте в TypingMind Плагіни → Навички → Встановити з GitHub і вставте https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/model-guided-code-repair. TypingMind прочитає файл SKILL.md, додасть супровідні файли та встановить навичку, яку можна вмикати окремо для кожного чату.

Які моделі ШІ можуть використовувати Model Guided Code Repair?

Будь-яка модель, яку ви підключите в TypingMind. Навички ШІ — це звичайні інструкції у форматі Markdown, а не код для конкретного постачальника, тому GPT, Claude, Gemini, Grok і локальні моделі можуть завантажувати цю навичку, коли запит їй відповідає.

Зі скількома моделями ШІ можна використовувати Model Guided Code Repair?

Зі скількома забажаєте. У TypingMind ви можете використовувати Model Guided Code Repair із будь-якою моделлю, яка підтримує навички, зокрема з GPT, Claude, Gemini, Grok, DeepSeek, Mistral чи Llama. Для цього ви використовуєте власні ключі API.

Чи безкоштовна навичка ШІ Model Guided Code Repair?

Так. На GitHub цю навичку публікує ArabelaTso за ліцензією Apache-2.0. Ви платите лише своєму постачальнику ШІ за використані токени.

Що таке навички ШІ?

Навичка ШІ — це набір інструкцій для повторного використання, який навчає модель ШІ виконувати одне конкретне завдання. Він відповідає відкритому формату Agent Skills: файл SKILL.md із назвою та описом, а також скрипти, шаблони чи довідкові файли, які можуть знадобитися моделі. Модель читає інструкції лише тоді, коли ваш запит відповідає навичці, тому встановлена навичка нічого не коштує, доки її не використано.

Чим навички ШІ відрізняються від плагінів або серверів MCP?

Плагін або сервер MCP надає моделі нові інструменти, які вона може викликати, — код, який десь виконується й повертає результат. Натомість навичка ШІ дає моделі знання й пояснює порядок дій: як підійти до завдання, яких кроків дотримуватися та яким має бути якісний результат. Навички — це звичайний Markdown, тож їм не потрібні ні сервер, ні ключ API, ні середовище виконання, і вони працюють із будь-якою моделлю.

Усі

Створіть власний робочий простір зі ШІ вже зараз

Підпишіться на нашу розсилку, щоб дізнаватися про нові функції та майбутні розіграші 👇