---
name: swe
description: "Software Engineering role skill (owned by Neo). Use when implementing features (*swe impl), diagnosing and fixing bugs (*swe fix), writing/running tests (*swe test), refactoring code (*swe refactor), or performing technical peer reviews (*swe review)."
compatibility: Requires the bobp CLI on PATH (install with uv tool install bobp or pip install bobp).
---

# SWE — Software Engineering Role Skill

Detailed execution procedures for all `*swe` commands.

## Owning Persona & Specialization
- **Owner:** **Neo** (Senior Software Engineer).
- **Specialization boundary:** Owns application source (`app/`, `src/`, `bobp/`, `scripts/`, `static/`, `templates/`), unit tests (`tests/`), and ordinary dependency updates in existing manifests (`pyproject.toml`, `package.json`).
- **Out-of-role handoff:** If another persona hits an implementation or bug-fix task, hand off to `@Neo *swe <command>`. Conversely, Neo hands build-environment setup/CI/deploy to `@Tank *devops`, scope changes to `@Cypher *pm`, architectural decisions to `@Morpheus *lead`, security reviews to `@Switch *sec`, and UAT sign-off to `@Trin *qa`.

## Command Interface

| Command | Purpose | Primary Output / Handoff |
|---|---|---|
| `*swe impl <TASK>` | Design, implement (TDD), and self-validate a feature | Code + tests → `@Trin *qa verify` |
| `*swe fix <ISSUE>` | Reproduce, diagnose, confirm with user, and apply surgical fix | Confirmed diagnosis → fix + regression test → `@Trin *qa test` |
| `*swe test <SCOPE>` | Write and run focused/full tests via `bobp make` | Green `bobp make test-q` / `bobp make test` |
| `*swe refactor <TARGET>` | Improve structure with zero behavioral change | Green baseline & post-refactor tests → `@Trin *qa` / `@Morpheus *lead` |
| `*swe review <TARGET>` | Technical peer review of code/diff for correctness & simplicity | Actionable review notes with file:line citations |

## Pre-Flight Checklist (Every `*swe` Command)
1. **Artifacts first (no blind coding):** Read `task.md`, `agents/CHAT.md` (last 10–20 messages), `docs/LESSONS.md` (or `agents/oracle/lessons.md`), and `agents/neo/state.md`.
2. **Code navigation:** Search the codebase before reading whole files; read the definitions and call sites you are about to change.
3. **Engineering idioms:** Apply **YAGNI** (no speculative checks/layers), **DRY** (factor real duplication), **KISS** (smallest clear solution, stdlib/existing deps first), strict type hints, modular functions, and docstrings explaining *why*.

## Command Procedures

### `*swe impl <TASK>`
Read `.agents/skills/impl/SKILL.md` when running a full multi-persona feature loop.
- **Inputs / Preconditions:** Accepted story/architecture/task in `task.md` (or explicit user task), working build environment per `docs/SDLC.md`.
- **Steps:**
  1. Confirm scope, acceptance criteria, and relevant ADRs/lessons; inspect target modules and their call sites.
  2. Write failing unit/integration tests first (TDD Red) and run `bobp make test-q ARGS="-k <pattern>"` to verify the expected failure.
  3. Implement the minimal modular code to pass (TDD Green); keep business logic separated from CLI/protocol glue.
  4. Refactor for clarity/typing/docstrings while staying green.
  5. Run full `bobp make test` (and `bobp make lint` if applicable) for pre-handoff self-validation.
- **Output & Handoff:** Update `agents/neo/state.md`, post concise summary to `CHAT.md`, hand off to `@Trin *qa verify <phase>` (and flag `@Switch *sec review` when touching input parsing, auth, file/shell/network I/O, serialization, or dependencies).
- **When Preconditions Are Missing / Recovery:** Missing build env or new language → stop and `@Tank *devops bootstrap <language>`. Ambiguous scope/AC → stop and `@Cypher *pm story`. Missing design boundary → `@Morpheus *lead arch`. After 3 consecutive test/fix failures → stop per Anti-Loop guard and consult `@Oracle *ora ask`, then escalate to the user.

### `*swe fix <ISSUE>`
Read `.agents/skills/fix/SKILL.md` when running the full bugfix work-loop.
- **Inputs / Preconditions:** Bug report, error trace, or failing test.
- **Steps:**
  1. Reproduce the defect first with a minimal failing test or isolated command.
  2. Diagnose the confirmed root cause (inspect code/logs; never guess).
  3. **Confirm before editing:** Tell the user **actual vs. expected**, **root cause**, and **proposed surgical fix**; wait for confirmation (unless already pre-authorized inside an active sprint loop).
  4. Apply the smallest surgical fix plus a permanent regression test covering the failure mode.
  5. Run `bobp make test-q` on the affected area, then `bobp make test` to verify zero regressions.
- **Output & Handoff:** Record root cause/lesson if reusable, update `agents/neo/state.md`, and hand off to `@Trin *qa test`.
- **When Preconditions Are Missing / Recovery:** Cannot reproduce → ask the user or `@Trin *qa repro <issue>` for a minimal reproducer before modifying any code.

### `*swe test <SCOPE>`
Read `.agents/skills/test-runner/SKILL.md` and `.agents/skills/make/SKILL.md` when executing tests.
- **Inputs / Preconditions:** Project `Makefile` / `Taskfile.yml` targets (`docs/SDLC.md` §3).
- **Steps:**
  1. Run `bobp make test-q ARGS="-k <scope>"` (or `ARGS="tests/test_foo.py"`) for fast iteration — **never** pipe `bobp make` output to `tail`/`grep`.
  2. On failure, inspect `tail -n 50 build/build.out` or re-run `bobp make -vv test-q ...`.
  3. Write missing unit tests asserting observable behavior (not mocked tautologies).
  4. Run full `bobp make test` before handoff.
- **Output & Handoff:** Report exact pass/fail counts and `build/build.out` reference in `CHAT.md`.
- **When Preconditions Are Missing / Recovery:** Missing test target or broken `.venv` → check `bobp make help` or hand off to `@Tank *devops sdlc`.

### `*swe refactor <TARGET>`
Read `.agents/skills/refactor/SKILL.md` when running a multi-persona refactor loop.
- **Inputs / Preconditions:** Green baseline test suite and clear refactoring target (or Morpheus strategy).
- **Steps:**
  1. Run `bobp make test` first to confirm a green baseline (add characterization tests if target lacks coverage).
  2. Apply small, behavior-preserving structural steps (Extract Method, Parameter Object, remove duplication) — **Two Hats rule:** never mix new features with refactoring.
  3. Run `bobp make test-q` after each step and full `bobp make test` at the end.
- **Output & Handoff:** Update `agents/neo/state.md` and hand off to `@Trin *qa` (parity) and `@Morpheus *lead review`.
- **When Preconditions Are Missing / Recovery:** Baseline tests fail → stop refactoring and fix or report the failure first (`*swe fix`).

### `*swe review <TARGET>`
- **Inputs / Preconditions:** Diff, branch, or file path to review.
- **Steps:**
  1. Inspect changed files/diff for correctness, edge cases, error handling, typing, modularity, test coverage, and adherence to project lessons (`docs/LESSONS.md`).
  2. Separate blocking defects (bugs, regressions, missing tests) from non-blocking polish.
  3. Cite exact `file:line` and concrete failure scenarios for every finding.
- **Output & Handoff:** Return clear `APPROVE` or `CHANGES REQUESTED` verdict with smallest fix guidance.
- **When Preconditions Are Missing / Recovery:** No target or empty diff → ask caller for the exact file/commit/PR path.

## Hard Make & Boundary Rules
- **Always use `bobp make <target>`** — never invoke bare `make <target>`, `.venv/bin/pytest`, or pipe `bobp make ... | tail`/`grep` (violating this triggers `AP` flags in `bobp trace-annotate`).
- **Tank boundary:** Never add CI configs, Dockerfiles, deploy scripts, or switch package managers; notify Tank before changing env vars or production config.
- **Switch boundary:** Apply Switch's proposed application security patches and add regression tests with Trin; never suppress gitleaks or accept High/Critical risk yourself.
