python-project-retrofit
Execute a locked Python Retrofit V2 plan with risk-aligned human gates and acceptance checks.
SKILL.mdskills/python-project-retrofit/SKILL.md
GitHubPurpose
Execute a Retrofit V2 retrofit-plan.md against an existing Python project without losing human control over conflicts, destructive actions, risk mismatches, or acceptance.
Trigger / When to use
Use this skill when:
- an existing Python repository already has an approved Retrofit V2
retrofit-plan.md - the task is to execute retrofit work rather than author the retrofit contract
- the workflow must detect shadow files, mine implicit configuration remnants, enforce risk alignment, and emit a Sensing Delta Report before acceptance
- the retrofit must hand off immediately to
python3 .<platform>/skills/sense-env-scaffold/scripts/sense_env.py --mode acceptance --contract-file retrofit-plan.md
Do not use this skill when:
- the repository is greenfield or baseline-only; use
python-project-init-greenfield retrofit-plan.mdis missing, malformed, still under negotiation, or still uses pre-V2 headings- the task is to author or review the retrofit plan itself
- the user expects the agent to auto-merge conflicting config files or guess through ambiguous structure changes
Inputs
- the target repository root
- the locked Retrofit V2
retrofit-plan.mdpath - the current filesystem state, including existing entrypoints, packages, and config remnants
- current Git working-tree state before any move, deletion, or overwrite
- the parsed
yaml [migration-strategy]fields:risk_level,destructive_actions, andbackup_required - explicit human decisions for Gate 1 and Gate 2, plus any HIGH-risk destructive authorization when a clean or backed-up path is ready
- the provenance destination at
.<platform>/skills-provenance.json
Process
- Confirm retrofit fit and parse the Retrofit V2 contract first.
- Read
retrofit-plan.md. - Require this exact heading order:
## Survey Summary## Gap Analysis## Target Transformation## Migration Strategy## Acceptance Criteria
- Require a parseable
yaml [migration-strategy]block under## Migration Strategy. - Require a parseable
yaml [sensing-assertions]block under## Acceptance Criteria. - Reject old headings or compatibility mapping instead of guessing.
- Read
- Validate the machine-readable risk metadata before touching the workspace.
- Require
risk_level,destructive_actions, andbackup_required. - Allow only
LOWorHIGHforrisk_level;MEDIUMis not executable yet. - Treat prose outside the blocks as human context only.
- Require
- Capture the pre-retrofit state.
- Sense the current layout, package paths, entrypoints, and toolchain remnants.
- Record the facts that will later populate the Sensing Delta Report.
- Parse the target transformation and declared strategy.
- Use
## Target Transformationplusyaml [migration-strategy]as the execution contract. - Treat
Migration Directionas strategy declaration only. - Do not reinterpret missing targets or invent migration policy.
- Use
- Run the Risk Alignment Check before execution gates.
- Compare the declared risk metadata to the observable workspace and planned operations.
- If the contract says
LOWbut scanning reveals destructive actions, hard-block and require plan or risk correction. - If destructive intent is obvious but
destructive_actionsis incomplete, stop instead of improvising a partial preview.
- Run Gate 1: Shadow File Detection before any restructure.
- Detect duplicate semantic intent at different paths, such as root
app.pyversus targetsrc/service/main.py. - Present exactly four human choices: move, delete, coexist, or abort.
- Do not continue until the human chooses one option for each conflict.
- Detect duplicate semantic intent at different paths, such as root
- Run Gate 2: Implicit Config Mining after Gate 1 is resolved.
- Scan for
poetry.lock,pyproject.toml,setup.py,setup.cfg,.venv,conda.yml,requirements.txt, andPipfile. - Present exactly four human choices when remnants are found: migrate, delete, preserve, or abort.
- Do not continue until the human confirms the disposition of each config family.
- Scan for
- Choose the runtime confirmation lane from
risk_level.LOW: use the lightweight confirmation path for additive or non-destructive work only.HIGH: generate a destructive preview fromdestructive_actionsplus current scan results, regenerate or update that preview if Gate 1 or Gate 2 decisions change the destructive scope, then require explicit human authorization for the final destructive scope before any destructive step.- Neither lane bypasses Gate 1, Gate 2, or Git safety.
- Run Gate 3: Git safety and pre-destructive check immediately before any move, deletion, or overwrite.
- Inspect Git working-tree status immediately before the destructive step.
- If the tree is dirty, hard-block the retrofit.
- Require an explicit human path of either committing existing changes or creating a backup before destructive work can resume.
- This gate cannot be bypassed.
- Apply only human-confirmed retrofit operations.
- Move, delete, preserve, or migrate only what the human approved.
- Never auto-merge conflicting configurations.
- Do not let
Migration Directionordestructive_actionssubstitute for runtime gate answers.
- Generate the Sensing Delta Report after the retrofit changes land.
- Emit JSON with a top-level
delta_summaryobject. - Include
timestamp,pre_retrofit_state,post_retrofit_state,changes,new_files,deleted_files, andmodified_files. - For every change record include
fact_key,before,after, andoperation, whereoperationis one ofMOVED,CREATED,MODIFIED, orDELETED.
- Emit JSON with a top-level
- Record provenance in
.<platform>/skills-provenance.json.- Record the retrofit date, creator, and Delta Report reference.
- Keep provenance repo-visible and governance-oriented.
- Close the loop with acceptance.
- Treat
skills/...as canonical source and.<platform>/skills/...as the platform projection surface used for the runnable entrypoint. - Hand off to
python3 .<platform>/skills/sense-env-scaffold/scripts/sense_env.py --mode acceptance --contract-file retrofit-plan.md. - If acceptance cannot run, report the blocking reason instead of claiming success.
- Treat
- Clean up scratch artifacts created during the retrofit flow while preserving
retrofit-plan.md, the Delta Report artifact, and provenance.
Examples
- Positive: Read a Retrofit V2
retrofit-plan.md, block a mislabeledLOWplan if the workspace reveals destructive moves, otherwise run Gate 1 and Gate 2, require HIGH-risk destructive preview and authorization when needed, emit the Sensing Delta Report, then hand off topython3 .<platform>/skills/sense-env-scaffold/scripts/sense_env.py --mode acceptance --contract-file retrofit-plan.md. - Negative: Accept old Retrofit headings, treat
Migration Directionas permission to skip human choices, or continue with destructive work after aLOWrisk mismatch or dirty Git state.
Outputs
- an existing Python project restructured to the approved Retrofit V2 target
- explicit human gate outcomes for shadow files, implicit configs, and destructive paths
- a Sensing Delta Report JSON artifact with before/after facts and
MOVED/CREATED/MODIFIED/DELETEDoperations - provenance recorded in
.<platform>/skills-provenance.json - an acceptance handoff result or a concrete blocking error
Verification
- confirm
retrofit-plan.mdcontains the locked Retrofit V2 sections and valid[migration-strategy]and[sensing-assertions]blocks - confirm
risk_levelis explicit, executable, and aligned with observed destructive surfaces - confirm a
LOWplan hard-blocks when scanning reveals destructive actions - confirm
HIGHplans require destructive preview plus explicit human authorization before destructive work - confirm all three gates block progress rather than warn passively
- confirm dirty Git state stops destructive retrofit until the human commits or produces a backup
- confirm the Delta Report uses the required JSON fields and only the allowed operations
- confirm acceptance uses the exact
sense_env.py --mode acceptance --contract-file retrofit-plan.mdhandoff
Red Flags
- a request to “just pick the most likely path” for conflicting files or configs
- a Retrofit V2 contract marked
LOWeven though the workspace reveals moves, deletes, overwrites, or relocations - conflicting config surfaces that would need heuristic line-by-line merging
Migration Directionbeing treated as runtime consent instead of strategy context- a claim that acceptance can be skipped because the filesystem now looks correct
Common Rationalizations
- “The plan says replace the old entrypoint, so we do not need Gate 1.”
- “This is probably still LOW because the move is small.”
- “We can merge
pyproject.tomlandsetup.cfgheuristically.” - “The repo is dirty, but Git can recover it later.”
- “Acceptance is redundant because the contract already describes the target state.”
Boundaries
- Do not author or redesign the retrofit plan; consume the locked Retrofit V2 contract that already exists.
- Do not execute or broaden acceptance assertions;
sense_env.py --mode acceptanceowns assertion execution. - Do not replace human-authored design or business logic; only restructure baseline and configuration surfaces.
- Do not auto-merge conflicting configurations.
- Do not generate
.github/copilot-instructions.mdcontent. - Do not proceed through any gate without explicit human confirmation.
Validation
Required Checks
retrofit-plan.mdis present, readable, and contains the locked Retrofit V2 section orderyaml [migration-strategy]block is parseable andrisk_levelisLOWorHIGHyaml [sensing-assertions]block is parseable under## Acceptance Criteriarisk_levelis aligned with observable destructive surfaces before any gate runs- Git working-tree is clean before any destructive step (Gate 3)
Quality Checks
- All three gates produced explicit human-confirmed outcomes before execution proceeded
- The Sensing Delta Report includes all required fields:
delta_summary,timestamp,pre_retrofit_state,post_retrofit_state,changes,new_files,deleted_files,modified_files - Every change record includes
fact_key,before,after, and a validoperationvalue - Provenance is recorded in
.<platform>/skills-provenance.json - Acceptance handoff used the exact
sense_env.py --mode acceptance --contract-file retrofit-plan.mdinvocation
On Soft Fail
- Mark output as INCOMPLETE; emit the blocking reason explicitly; continue with best-effort output when possible rather than halting entirely
- Mark INCOMPLETE if partial — e.g., if acceptance cannot run, emit the blocking reason and mark the retrofit INCOMPLETE rather than claiming success
Failure Handling
Missing Context
- BLOCKED — if
retrofit-plan.mdis not provided or cannot be read, stop and ask for the correct path before proceeding
Ambiguous Requirement
- If a
retrofit-plan.mdsection is ambiguous or missing required machine-readable blocks, stop and request clarification or a corrected plan; do not infer intent from prose - If
risk_levelisMEDIUMor absent, hard-block and require a corrected[migration-strategy]block - If Gate 1 or Gate 2 presents a conflict without a clear human choice, re-present the four options and wait; do not default to any option
Execution Limitation
- If the repository cannot be inspected (permissions, missing Git state, or inaccessible paths), stop and report the specific blocking condition
- If a destructive migration step partially fails, do not attempt to roll back automatically; report what succeeded and what failed, mark the retrofit INCOMPLETE, and require human review before retrying
- If
sense_env.pyis unavailable or returns a non-zero exit code, report the exact error and mark the retrofit INCOMPLETE rather than claiming success
Local references
examples.md: detailed Retrofit V2 execution scenarios, risk-lane behavior, and anti-patternsreferences/retrofit-plan-v2-contract.md: executor-side parsing contract for Retrofit V2 headings and machine-readable blocksreferences/retrofit-conflict-resolution.md: Shadow File Detection, Implicit Config Mining, gate ordering, and runtime stop-and-ask rulesreferences/retrofit-safety-guidelines.md: risk-alignment blocking, destructive preview, Git safety checks, backup expectations, and hard-block behaviorreferences/sensing-delta-contract.md: Sensing Delta Report schema, operation semantics, and interpretation guidance