Skip to content
Back to skills

Rewriting Code Strictly

ASecurity

Rewrite existing Python, TypeScript/JavaScript, or Go code for strict static typing, boundary validation, and maintainable idioms while preserving behavior. Use when the user asks to harden code, remove unsafe escape hatches, add validation, or align with mypy, Pyright, tsc, go vet, or Staticcheck. Coordinates baseline mapping, strategy, approved implementation, and review through co-located subagents and just-in-time language references.

  • 3 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 7, 2026
developmentjavascripttypescriptpythonrustgojavaapi

Works with

  • terminal
  • api

Security analysis

A100/100

Pro scans all 12 files and shows the line behind each finding

Scanned November 7, 2026

npx -y skills add b-mendoza/agent-skills --skill rewriting-code-strictly --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rewriting Code Strictly?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rewriting Code Strictly
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/b-mendoza-rewriting-code-strictly/badge)](https://www.skillsdirectory.com/skills/b-mendoza-rewriting-code-strictly)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: "rewriting-code-strictly"
description: "Rewrite existing Python, TypeScript/JavaScript, or Go code for strict static typing, boundary validation, and maintainable idioms while preserving behavior. Use when the user asks to harden code, remove unsafe escape hatches, add validation, or align with mypy, Pyright, tsc, go vet, or Staticcheck. Coordinates baseline mapping, strategy, approved implementation, and review through co-located subagents and just-in-time language references."
---

# Rewriting Code Strictly

Strict-rewrite orchestrator for behavior-preserving Python, TypeScript/JavaScript, or Go rewrites. Think, decide, and dispatch one subagent at a time; keep only status, decisions, validation verdicts, changed paths, risks, and material URLs.

## Inputs

| Input                     | Required | Example                                     |
| ------------------------- | -------- | ------------------------------------------- |
| `TARGET_CODE`             | Yes      | `src/api/users.py` or pasted code           |
| `LANGUAGE`                | No       | `python`, `typescript`, `go`                |
| `USER_GOAL`               | No       | `"make this strict and easier to maintain"` |
| `VALIDATION_COMMAND`      | No       | `mypy src/api/users.py`                     |
| `SCOPE_LIMITS`            | No       | `"do not add dependencies"`                 |
| `REFERENCE_NEED`          | No       | `"Pydantic strict mode"`                    |
| `EXTERNAL_FETCH_APPROVAL` | No       | `"approved for Pydantic docs only"`         |

Missing `TARGET_CODE` or unclear language → one focused question before dispatch.

## Output Contract

Handoff order: (1) original behavior, (2) weaknesses, (3) typing vs validation decisions, (4) files/code, (5) validation results, (6) references used or unavailable, (7) assumptions/risks, (8) gate evidence for `G_STRICT_STRATEGY_APPROVAL`, `G_MUTATION_SCOPE`, `G_IMPLEMENTATION_VALIDATION`, `G_STRICT_REVIEW_PASS`, `G_FINAL_HANDOFF_EVIDENCE`.

For all user-facing handoffs, explain the outcome in prose without a status line, standalone status token, or routing envelope. Internal terminal decisions and subagent handoffs keep their existing markers. Stops (`NO_CHANGE`, `NEEDS_CLARIFICATION`, `BLOCKED`, `ERROR`) include the smallest reason, next decision, and any validation already completed. Missing-target stops request the file or pasted code; behavior-conflict stops show the conflicting behavior and ask which requirement to preserve. State that nothing was changed only if the stop occurred before any edit; otherwise list the edits made and the validation state.

## State Machine Overview

Non-normative overview. Follow the canonical [`state-machine.md`](./state-machine.md) for states, transitions, guards, and terminals.

| Group              | Result                                                         |
| ------------------ | -------------------------------------------------------------- |
| Intake gates       | Target, language, scope; derive `MUTATION_LIMITS`              |
| Baseline           | Mapper; `NO_CHANGE_CANDIDATE` continues (not a stop)           |
| Strategy           | Strategist; only `NO_CHANGE` stops before edits                |
| Gates + approval   | Check gates; `AskApproval` **resumes implement on approve**    |
| Implement / review | Mutate, review; ≤2 repairs re-enter implement                  |
| Terminals          | `PASS`, `NO_CHANGE`, `NEEDS_CLARIFICATION`, `BLOCKED`, `ERROR` |

Missing validation command → continue with implementer warning evidence; the reviewer still runs. Implementer owns authorized checks; reviewer covers drift checks may miss.

## Subagent Registry

| Subagent                     | Path                                        | Purpose                                |
| ---------------------------- | ------------------------------------------- | -------------------------------------- |
| `strict-baseline-mapper`     | `./subagents/strict-baseline-mapper.md`     | Read-only baseline map                 |
| `strict-rewrite-strategist`  | `./subagents/strict-rewrite-strategist.md`  | Playbook, optional fetch, minimal plan |
| `strict-rewrite-implementer` | `./subagents/strict-rewrite-implementer.md` | Apply rewrite; run authorized checks   |
| `strict-rewrite-reviewer`    | `./subagents/strict-rewrite-reviewer.md`    | Independent review verdict             |

Read a subagent only when dispatching it.

## Progressive Loading Map

Load only what the current decision needs. Paths here are relative to this `SKILL.md`; later files use their own relative paths.

| Need                         | Load                                                            |
| ---------------------------- | --------------------------------------------------------------- |
| Posture                      | `./references/personality.md`                                   |
| Python / TS/JS / Go defaults | matching `./references/*-playbook.md`                           |
| External URL map             | `./references/external-sources.md` (orchestrator or strategist) |
| Examples                     | `./references/orchestration-examples.md`                        |
| State machine                | `./state-machine.md`                                            |
| Subagent contract            | `./subagents/<name>.md` at dispatch                             |

One playbook after language is known. Playbooks do not chain-load `external-sources.md`; the map and strategist own that hop. Pass package-root-relative paths at dispatch; subagents may use `../references/...`.

Fetch URLs only with `REFERENCE_NEED`, `EXTERNAL_FETCH_APPROVAL`, or project-local required evidence. Unavailable URL → local evidence + risk, or `NEEDS_CLARIFICATION`. Network is optional for normal runs.

## Default Mutation Limits

Derive in `DeriveLimits`. Unless `SCOPE_LIMITS` expands them: write only in `TARGET_CODE` and direct compilation/typing/import/test consequences; preserve behavior, public contracts, deps, settings, unrelated work; no new deps, broad cleanup, public API, private config, generated artifacts, or repo tooling without approval; repairs stay on reviewer-named fixes inside limits. Out-of-limits need → clarify or expand before editing. Reports include mutation-boundary evidence.

## Critical Output Gates

| Gate                          | Evidence                                                |
| ----------------------------- | ------------------------------------------------------- |
| `G_STRICT_STRATEGY_APPROVAL`  | Status, non-goals, approval items, validation plan      |
| `G_MUTATION_SCOPE`            | Limits, planned/actual paths, expansions                |
| `G_IMPLEMENTATION_VALIDATION` | Commands, results, unavailable/unapproved notes         |
| `G_STRICT_REVIEW_PASS`        | `STRICT_REVIEW: PASS` or blocked findings after repairs |
| `G_FINAL_HANDOFF_EVIDENCE`    | Gate verdicts, files, validation, references, risks     |

## Core Decision Rule

Static types for stable internals; runtime validation at trust boundaries; convert boundary data to typed internals before deeper use; keep escape hatches local and justified. Project settings outrank playbook defaults when stricter.

## Example

`TARGET_CODE=src/payments/webhook.ts`, remove unsafe `any`, validate webhook, `REFERENCE_NEED` for Zod. Mapper finds TS + untrusted body. Strategist loads typescript playbook and, only if needed, `external-sources.md` + approved Zod URL. No expansion → implement → review → handoff. See `./references/orchestration-examples.md` for approval resume, no-change, and unavailable-reference round-trips.

Files in this skill

  • SKILL.md7.5 KB
  • references/external-sources.md6.3 KB
  • references/go-playbook.md2.1 KB
  • references/orchestration-examples.md4.3 KB
  • references/personality.md2.9 KB
  • references/python-playbook.md2.2 KB
  • references/typescript-playbook.md2 KB
  • state-machine.md10.5 KB
  • subagents/strict-baseline-mapper.md4.7 KB
  • subagents/strict-rewrite-implementer.md6.1 KB
  • subagents/strict-rewrite-reviewer.md4.8 KB
  • subagents/strict-rewrite-strategist.md7.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.