Rewrite denoise V0
Contract
| Field | Bound contract |
|---|---|
| Trigger | User asks to clean up/sync/dedupe/de-noise/rewrite an iterated artifact, or nearby artifacts may have drifted |
| Authority | Reversible local: write only the named target artifact; restore from backup on failure |
| Side effect | Rewrites the target artifact in place; no new files unless explicitly asked |
| Done | Result reads as a clean v0 to fresh eyes: lighter, current, accurate; no patch traces, no changelog scars |
Inputs
- Target artifact (required): the file path to rewrite.
- Scope hint (optional): user-supplied boundary or focus area within the artifact.
Procedure
- Confirm the target artifact exists on disk. If it does not, stop; report
MISSand do not create a replacement. - Read the full artifact. Record its current content as the rollback snapshot.
- Identify source noise: lines that are raw source dumps, one sentence per line where the source wrapped, or list items split across multiple lines that belong on one line.
- Unwrap source noise: merge wrapped paragraphs into single logical lines; merge split list items into one line per item. Preserve meaning; do not paraphrase.
- Identify sediment: patch traces, changelog scars, duplicate passages, stale deltas, historical aliases, compatibility notes, and content that no longer reflects the current state.
- Rewrite the entire artifact from scratch as a clean v0. Do not patch the existing text; derive it fresh from the current facts. Keep only what is current, accurate, and load-bearing.
- Apply edit-safety conventions:
- Assert every referenced target exists before editing. Report
MISSif not found; never silently skip. - Use unicode-safe operations on all text.
- Apply changes per occurrence, never as a blanket sweep.
- Script large structural moves as explicit steps rather than single edits.
- When in doubt, repair from the source of truth rather than guessing.
- Assert every referenced target exists before editing. Report
- Verify the result reads as a clean v0 to fresh eyes: lighter than the original, current, accurate, with no patch traces or changelog scars.
- Write the rewritten artifact to the original path, replacing it in place.
- If the user asked for new files (e.g., a diff or summary), produce those as well.
Failure and recovery
- Target missing: the artifact does not exist at the given path. Stop immediately. Report
MISS. Do not create a new file. - Rewrite drifts from contract: the rewritten content introduces claims, structure, or scope not present in the original. Discard the rewrite. Restore from the rollback snapshot. Report what drifted.
- Verification fails: the result does not read as a clean v0: patch traces, changelog scars, or source noise remain. Do not write. Iterate the rewrite or restore from snapshot.
- Partial result: if the rewrite is interrupted after step 9, the artifact is in an unknown state. Restore from the rollback snapshot and restart.
Output
The target artifact rewritten in place as a clean v0. Optionally, additional files if the user requested them.