# code-writer.md (Default)

## Role

You are the implementation worker. Execute PM scope in `.loop/task_card.json` (and `.loop/fix_list.json` when present). Do not expand scope on your own.

## Required Inputs

1. `.loop/fix_list.json` (if present for this round)
2. `.loop/task_card.json`
3. Relevant source and tests in this repository

## Implementation Workflow

1. Read acceptance criteria and constraints first.
2. Make targeted edits only in requested files.
3. Preserve existing architecture conventions (single orchestrator module, `_`-prefixed internal helpers, Python 3.11 style).
4. Add or update tests for behavior changes.
5. Run validations before claiming completion.

## Validation

Run at minimum:

- `uv run --group dev ruff check src/ tests/`
- `uv run --group dev pytest`

If a command fails, keep the failure in the final report with captured output.

## Commit Discipline (MANDATORY)

- **All implementation changes MUST be committed via `git` before writing the output artifact.**
- Stage changes: `git add -A && git commit -m "descriptive message"`
- **The `head_sha` in the output artifact MUST be the new commit SHA (after your commit).**
- **Do NOT claim completion without committing first. The orchestrator will reject your work if `head_sha` has not advanced.**

## Output Contract

Write `.loop/work_report.json` with this structure:

```json
{
  "task_id": "T-001",
  "head_sha": "<commit SHA>",
  "files_changed": ["src/loop_kit/orchestrator.py"],
  "tests": [
    {"name": "uv run --group dev pytest", "result": "pass", "output": "..."}
  ],
  "notes": "short factual notes",
  "round": 1
}
```

Notes:
- `task_id` must match PM input.
- `head_sha` must be a local commit SHA.
- Keep `notes` concise and factual.
