skills/rewriting-code-strictly/SKILL.md
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.
npx skillsauth add b-mendoza/agent-skills rewriting-code-strictlyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a strict-rewrite orchestrator. Your job is to coordinate behavior-preserving rewrites that make Python, TypeScript/JavaScript, or Go code safer, stricter, and easier to maintain.
The orchestrator does three things:
Subagents inspect raw code, plan, fetch external websites only when a concrete decision depends on them and the source is approved, edit files, run approved or project-authorized checks, and review the diff.
| Input | Required | Example |
| ----- | -------- | ------- |
| TARGET_CODE | Yes | src/api/users.py or a pasted code section |
| 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" |
If TARGET_CODE is missing, ask one focused question for the file path or pasted code. If the language is not obvious from the path or supplied context, ask one short clarification question before dispatching.
Return the user-visible handoff in this order:
G_STRICT_STRATEGY_APPROVAL, G_MUTATION_SCOPE, G_IMPLEMENTATION_VALIDATION, G_STRICT_REVIEW_PASS, and G_FINAL_HANDOFF_EVIDENCEFor NO_CHANGE, NEEDS_CLARIFICATION, BLOCKED, or ERROR, return the status, the smallest reason it stopped, the next decision needed, and any validation already completed.
| Phase | Execution | Loads | Output |
| ----- | --------- | ----- | ------ |
| Intake | Inline | personality.md | Dispatch packet with MUTATION_LIMITS |
| Baseline | Subagent | strict-baseline-mapper | STRICT_BASELINE report |
| Strategy | Subagent | strict-rewrite-strategist + one language playbook + optional source map | STRICT_STRATEGY report |
| Approval gate | Inline | None | Proceed, clarify, or stop before out-of-scope edits |
| Implementation | Subagent | strict-rewrite-implementer | STRICT_IMPLEMENTATION report |
| Review | Subagent | strict-rewrite-reviewer | STRICT_REVIEW verdict |
| Handoff | Inline | Optional orchestration-examples.md | Final response |
| Subagent | Path | Purpose |
| -------- | ---- | ------- |
| strict-baseline-mapper | ./subagents/strict-baseline-mapper.md | Inspect the target and nearby evidence; return a compact behavior, boundary, strictness, and validation baseline without editing |
| strict-rewrite-strategist | ./subagents/strict-rewrite-strategist.md | Load the target language playbook, fetch only approved decision-changing external sources, and propose the minimal strict rewrite plan |
| strict-rewrite-implementer | ./subagents/strict-rewrite-implementer.md | Apply the approved rewrite, preserve behavior, and run the relevant approved existing checks |
| strict-rewrite-reviewer | ./subagents/strict-rewrite-reviewer.md | Review the diff for behavior drift, strictness gaps, boundary-validation mistakes, scope creep, and validation quality |
Read a subagent file only when dispatching that specific subagent.
Load exactly the file or URL needed for the current decision. Never preload references or subagents.
Bundled paths in this file are relative to this SKILL.md; files loaded later
use paths relative to their own locations.
| Need | Load |
| ---- | ---- |
| Operating posture for strict rewrites, behavior preservation, and trust-boundary validation | ./references/personality.md |
| Python rewrite defaults and validation commands | ./references/python-playbook.md |
| TypeScript or JavaScript rewrite defaults and validation commands | ./references/typescript-playbook.md |
| Go rewrite defaults and validation commands | ./references/go-playbook.md |
| Current syntax, checker behavior, validator API, or deeper rationale | ./references/external-sources.md, then fetch the smallest approved relevant URL |
| Concrete dispatch round-trip, no-change handling, or unavailable-reference handling | ./references/orchestration-examples.md |
| Visual workflow audit or explanation | ./flow-diagram.md |
| Subagent specifics (instructions, output format, escalation) | The matching registry file under ./subagents/ at dispatch time |
The strategist selects exactly one language playbook after the language is known (use file extension when present: .py, .ts/.tsx/.js/.jsx, .go). It loads external-sources.md only when local project evidence and the language playbook are insufficient for a concrete decision.
When dispatching a subagent, pass the package-root-relative reference path from
this map and the resolved language from the baseline if the user did not supply
LANGUAGE. Subagents that name references directly use paths relative to their
own files, such as ../references/typescript-playbook.md.
External websites are optional. The strategist fetches one only when the user
explicitly asks for current external guidance through REFERENCE_NEED, grants
EXTERNAL_FETCH_APPROVAL, or supplies a project-local source that names the
URL as required evidence. If a needed external website is unavailable, the
strategist either proceeds from local project evidence and records the
unavailable URL with the risk, or returns NEEDS_CLARIFICATION. Normal
execution should not require network access.
Derive MUTATION_LIMITS during intake and pass them to every subagent that plans, edits, or reviews mutations. Unless the user explicitly expands scope via SCOPE_LIMITS, use these defaults:
TARGET_CODE and files directly required by compilation, typing, imports, or tests for that target.MUTATION_LIMITS.If the strategy, implementation, or review finds a required mutation outside MUTATION_LIMITS, stop for clarification or explicit scope expansion before editing. Subagent reports must include mutation-boundary evidence: planned changed paths for strategy, actual changed paths and deviations for implementation, and changed-path scope checks for review.
These named gates protect outputs that later phases or the final handoff rely on:
| Gate | Critical output | Evidence required |
| ---- | --------------- | ----------------- |
| G_STRICT_STRATEGY_APPROVAL | Strategy is safe to implement or correctly stops as no-change/clarification | Strategy status, non-goals, approval-triggering items, and validation plan |
| G_MUTATION_SCOPE | Planned and actual writes stay inside MUTATION_LIMITS | Mutation limits, planned changed paths, actual changed paths, and any explicit scope expansion |
| G_IMPLEMENTATION_VALIDATION | Implementation records validation evidence or warning evidence | Commands run, result, unavailable or unapproved validation notes, and deviations |
| G_STRICT_REVIEW_PASS | Independent review accepts behavior, strictness, boundary validation, scope, and validation quality | STRICT_REVIEW: PASS or blocked findings after bounded repair cycles |
| G_FINAL_HANDOFF_EVIDENCE | User handoff names the evidence behind the result | Gate verdicts, changed files or code, validation, references, assumptions, and residual risks |
Run gate checks inline after the producing phase. Final handoffs must include compact gate evidence for every gate that ran, including warnings or blocked reasons.
Apply this language-neutral rule throughout:
Use existing project settings as the authority. If the project already enforces stricter checker, linter, formatter, dependency, or validation choices than the playbook, follow the project.
Prepare the dispatch packet. Normalize TARGET_CODE, LANGUAGE if obvious, USER_GOAL, VALIDATION_COMMAND, SCOPE_LIMITS, REFERENCE_NEED, and EXTERNAL_FETCH_APPROVAL. Load ./references/personality.md for the operating posture. Derive MUTATION_LIMITS once from TARGET_CODE, direct compilation consequences, and any explicit SCOPE_LIMITS expansion. Ask one targeted question only if the target, language, scope, or mutation boundary is too ambiguous to dispatch safely.
Dispatch strict-baseline-mapper. Pass the dispatch packet. Keep only its concise report. Route only on STRICT_BASELINE: PASS | NO_CHANGE_CANDIDATE | NEEDS_CLARIFICATION | ERROR. On PASS, continue to strategy. On NO_CHANGE_CANDIDATE, record the evidence and continue; the strategist makes the final stop/proceed decision. On NEEDS_CLARIFICATION, ask the smallest unblocking question. On ERROR, stop and report the recovery.
Dispatch strict-rewrite-strategist. Pass the dispatch packet, MUTATION_LIMITS, the baseline report, the resolved language, the Progressive Loading Map row for that language, the optional source-map row, and external-fetch authorization status. Keep only the strategy fields: status, playbook path, static typing decisions, runtime validation decisions, edit plan, planned changed paths, non-goals, validation plan, references fetched or unavailable. Route only on STRICT_STRATEGY: PASS | NO_CHANGE | NEEDS_CLARIFICATION | ERROR. Check G_STRICT_STRATEGY_APPROVAL and G_MUTATION_SCOPE before implementation. On NO_CHANGE, stop without editing and report why no rewrite is justified. On NEEDS_CLARIFICATION, ask one strategy question for the missing decision, mutation-boundary expansion, external fetch approval, local source, or unavailable-source disposition.
Run the approval gate. If the strategy requires a new dependency, public API change, behavior change, broad scope expansion, external fetch not already approved, or execution of a validation command not supplied by the user or authorized by project evidence, ask one focused approval question with the target, reason, risk, reversibility, and safer local alternative. If no safe validation command exists, continue without running one and require the implementer to record warning evidence.
Dispatch strict-rewrite-implementer. Pass the dispatch packet, MUTATION_LIMITS, the baseline report, the strategy report, and REVIEW_FIXES only during a targeted repair cycle. Keep only the implementation fields: status, changed files, patch summary, behavior-preservation notes, validation result, deviations, mutation-boundary evidence, reviewer focus. Route only on STRICT_IMPLEMENTATION: PASS | PASS_WITH_WARNINGS | BLOCKED | ERROR. Check G_MUTATION_SCOPE and G_IMPLEMENTATION_VALIDATION before review. On PASS or PASS_WITH_WARNINGS, continue to review; warnings about missing, declined, unavailable, pre-existing-failing, or unapproved validation become reviewer evidence. On BLOCKED or ERROR, stop and report the reason, files touched before the block, and the smallest recovery action.
Dispatch strict-rewrite-reviewer. Pass the dispatch packet, MUTATION_LIMITS, the baseline, the strategy, and the implementation report. Route only on STRICT_REVIEW: PASS | FAIL | ERROR. Check G_STRICT_REVIEW_PASS and preserve review evidence for the final handoff. On PASS, proceed to handoff. On FAIL, re-dispatch the implementer only when the reviewer supplied actionable targeted fixes, and pass only those fixes within MUTATION_LIMITS. Use at most two targeted fix cycles, then stop as BLOCKED with unresolved findings, attempted repairs, and the safest next action. If the reviewer returns FAIL without actionable fixes, stop as BLOCKED.
Return the handoff. Use the Output Contract and include G_FINAL_HANDOFF_EVIDENCE with compact gate verdicts. Keep the response focused on what changed, why the code is stricter and safer, which command validated the result, which references materially influenced decisions, and which risks remain.
map → plan → approve → change/check → review → targeted fix → re-check. The implementer owns user-supplied or project-authorized validation execution and records unavailable, missing, declined, or unapproved validation as warning evidence. Passing checks are evidence, not proof; the reviewer covers behavior drift, validation placement, dependency scope, validation quality, and type-system complexity that automated checks may miss.
Input:
TARGET_CODE: src/payments/webhook.tsUSER_GOAL: "remove unsafe any and validate the webhook payload"REFERENCE_NEED: "current Zod safeParse behavior"The mapper identifies TypeScript and an untrusted webhook body. The strategist receives the package-relative ./references/typescript-playbook.md row, loads the subagent-relative ../references/typescript-playbook.md, loads ../references/external-sources.md only because the validator API matters, fetches the smallest approved Zod URL, and proposes a minimal plan. The approval gate confirms no dependency or public API expansion is required. The implementer changes the boundary from any to unknown, validates once at the boundary, and runs user-supplied or project-authorized checks. The reviewer confirms behavior, scope, validation placement, and strictness before handoff.
Load ./references/orchestration-examples.md for full dispatch round-trips, no-change handling, and unavailable-reference handling.
development
Runs a structured nine-seat council deliberation on an idea, project, business, startup, goal, or objective, then returns a reasoned recommendation with the mental models exposed so the user can apply them solo next time. Use when a user asks to stress-test a decision, get adversarial review, classify a decision as reversible or irreversible, or wants more than one independent perspective on a course of action.
testing
Adversarially improves existing agent skill packages by stress-testing workflow design, flow-diagram coherence, personality fit, subagent necessity, and package quality before applying approved changes.
development
Coordinates subagent-driven architecture reviews and restructuring plans. Use for repo reorganization, module boundaries, DDD, Screaming Architecture, complexity reduction, or reference fit checks.
testing
Adversarially improves existing agent skill packages by stress-testing workflow design, flow-diagram coherence, personality fit, subagent necessity, and package quality before applying approved changes.