Code agent

From oyi77/1ai-skills · View interactive version

Code agent is an AI agent skill from the GitHub repository oyi77/1ai-skills. Use when implementing features from specs — reads requirements, writes code with tests, iterates until verification passes.

How to use this skill

Skill file

Overview

This agent implements features directly from specifications: it reads the requirements, writes the code, and iterates until the spec is satisfied. Use it when you have a clear written spec and want the implementation owned end-to-end. It delivers working code plus the reasoning trail behind each change.

Code Agent

Quick Reference — see parent for full agent ecosystem.

The Code Agent converts specs and plans into working, tested code. It reads requirements or a plan JSON, produces implementation across multiple files, writes companion tests, and iterates until all verification gates pass. Its primary contract is correctness: the output must compile, pass tests, and follow project conventions.

When Not to Use

Dependencies

Commands

# Refer to the skill's usage section for specific commands
# Adapt these to your workflow

Key Responsibilities

Code Example

"""Minimal code agent pattern — implement from plan."""

import json, subprocess, sys
from pathlib import Path

def implement(plan_path: str, output_dir: str) -> dict:
    plan = json.loads(Path(plan_path).read_text())
    changed = []

    for step in plan["steps"]:
        for file_spec in step.get("files", []):
            # Read existing file or create new
            path = Path(output_dir) / file_spec["path"]
            if path.exists():
                original = path.read_text()
            else:
                original = ""

            # Apply the implementation (simplified — real agent calls an LLM)
            new_code = f"# {file_spec['path']}\n# {file_spec['description']}\n{original}"
            path.write_text(new_code)
            changed.append(str(path))

    # Write tests
    for spec in plan.get("tests", []):
        test_path = Path(output_dir) / spec["path"]
        test_path.write_text(f"# Test for {spec['target']}\ndef test_{spec['name']}():\n    assert True\n")
        changed.append(str(test_path))

    return {"files_changed": changed, "tests_written": len(plan.get("tests", []))}

if __name__ == "__main__":
    result = implement(sys.argv[1], sys.argv[2])
    print(json.dumps(result, indent=2))

Checklist

Workflow

  1. Identify the task or trigger.
  2. Prepare inputs and configure parameters.
  3. Execute the core routine.
  4. Verify the output against expected results.
  5. Iterate based on feedback or new data.

Verification

Anti-Rationalization Table

| Rationalization | Reality |

|---|---|

| "I will write the tests after it works" | Tests written after the fact cover happy path only, missing edge cases the spec implied |

| "The existing patterns are close enough" | Near-matches introduce subtle inconsistencies. Follow the file's exact conventions — imports, naming, error handling |

| "It compiles, so it is correct" | Compilation proves syntax, not logic. Your test suite is the real proof |

When to Use

Use when implementing features from structured plans or specs, fixing bugs with known root causes, writing new modules, or adding unit/integration tests. Do NOT use for ambiguous requirements (run planning-agent first), real-time decisions, or tasks requiring tools the agent cannot access.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.