Get the FREE Ultimate OpenClaw Setup Guide →

code-completion-semantic-constraints

Scanned
npx machina-cli add skill ArabelaTso/Skills-4-SE/code-completion-semantic-constraints --openclaw
Files (1)
SKILL.md
4.6 KB

Code Completion with Semantic Constraints

Overview

Complete partial code snippets while satisfying specified semantic constraints. Produces compilable code, verification tests, and a detailed report explaining how each constraint was satisfied.

Workflow

1. Parse Input

Extract and categorize the provided information:

Partial Code: Identify the incomplete code structure (function signature, class skeleton, method stub, etc.)

Semantic Constraints: Categorize constraints by type:

  • Type constraints: Variable types, return types, generic bounds
  • Invariants: Pre-conditions, post-conditions, loop invariants
  • Behavioral constraints: Expected input/output pairs, edge case handling
  • Interface contracts: Method signatures, protocol conformance
  • Performance constraints: Time/space complexity requirements

2. Analyze Constraints

For each constraint:

  • Determine if it's satisfiable
  • Identify dependencies between constraints
  • Note any conflicts or ambiguities
  • If constraints are unclear or conflicting, ask for clarification before proceeding

3. Complete the Code

Generate code that:

  • Compiles without errors in the target language
  • Satisfies all specified constraints
  • Follows language idioms and best practices
  • Includes necessary imports, type annotations, and error handling
  • Uses minimal complexity (avoid over-engineering)

4. Generate Verification Tests

Create minimal test cases that verify:

  • Type constraints are respected
  • Pre-conditions and post-conditions hold
  • Expected input/output behavior is correct
  • Edge cases are handled properly
  • Performance constraints are met (if specified)

5. Produce Constraint Satisfaction Report

Document how each constraint was satisfied:

  • Map each constraint to the code that satisfies it
  • Explain the reasoning for implementation choices
  • Note any assumptions made
  • Highlight any constraints that required trade-offs

Examples

Example 1: Type and Behavioral Constraints

Input:

def process_items(items):
    # TODO: complete this function
    pass

Constraints:

  • items is a list of integers
  • Return a list of unique integers in ascending order
  • Handle empty list (return empty list)
  • Time complexity: O(n log n)

Output: Completed function with sorting logic, tests for empty/normal/duplicate cases, and report explaining constraint satisfaction.

Example 2: Interface Contract

Input:

public class DataCache implements Cache {
    // TODO: implement required methods
}

Constraints:

  • Implement Cache interface (get, put, remove methods)
  • Thread-safe operations
  • LRU eviction policy with max size 100
  • Return null for missing keys

Output: Complete class implementation, concurrency tests, and report mapping each interface method to implementation.

Example 3: Invariant Preservation

Input:

void update_balance(Account* acc, int amount) {
    // TODO: complete
}

Constraints:

  • Pre-condition: acc != NULL && acc->balance >= 0
  • Post-condition: acc->balance >= 0 (balance never negative)
  • If amount would make balance negative, set to 0 instead

Output: Implementation with bounds checking, tests for edge cases, and report showing invariant preservation.

Output Format

Provide three components:

1. Completed Code

  • Fully compilable and executable
  • Includes necessary imports, type annotations, error handling
  • Follows language conventions

2. Verification Tests

  • Minimal test suite covering constraint verification
  • Include edge cases and boundary conditions
  • Use appropriate testing framework for the language

3. Constraint Satisfaction Report

  • Table or list mapping each constraint to implementation details
  • Explanation of design choices
  • Any assumptions or trade-offs made

Language Support

This skill works with any programming language. Adapt constraint types and verification approaches to language-specific features (e.g., type systems, contract programming, assertion libraries).

Source

git clone https://github.com/ArabelaTso/Skills-4-SE/blob/main/skills/code-completion-semantic-constraints/SKILL.mdView on GitHub

Overview

Code Completion with Semantic Constraints fills in partial code while honoring type constraints, invariants, pre/post-conditions, interface contracts, and expected input/output behavior. It outputs compilable code along with tests and a constraint satisfaction report that explains how each constraint was met.

How This Skill Works

Input is parsed into partial code and categorized semantic constraints (types, invariants, behavioral expectations, interface contracts, performance). The system checks satisfiability, then generates a full implementation, accompanying tests, and a report mapping how constraints are satisfied.

When to Use It

  • Complete a function that takes a list and returns sorted unique elements.
  • Fill a method body that must maintain the invariant that x stays positive.
  • Implement an interface method with specific type constraints.
  • Enforce pre-conditions and post-conditions and handle edge cases in a class method.
  • Produce compilable code with tests and a constraint satisfaction report.

Quick Start

  1. Step 1: Provide partial code and clearly list constraints.
  2. Step 2: The tool analyzes constraints, generates a compilable implementation and tests.
  3. Step 3: Run tests and review the constraint satisfaction report.

Best Practices

  • Define precise constraints inline or in the prompt.
  • Keep partial code focused to minimize ambiguity.
  • Specify edge cases and expected input/output behavior.
  • Include unit tests for pre/post conditions and invariants.
  • Review the constraint satisfaction report to trace decisions.

Example Use Cases

  • Python: process_items(items) returns sorted unique integers.
  • Java: DataCache implements Cache with thread-safe get/put/remove, LRU eviction max 100, and null for missing keys.
  • C: update_balance(Account* acc, int amount) preserves non-negative balance with pre/post conditions.
  • Go: generic function constrained by type parameters and validated output.
  • TypeScript: repository interface method implemented with runtime checks and tests.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers