Skip to content

extract: refuse writes that would shrink an existing file unless --force #25

Closed as not planned

Description

@adrianbrowning

This was generated by AI during triage.

Split out of #21, which is limited to the three splice and alias failures.

#21 suggested that extract refuse to write when the result would be smaller than the existing target file, unless --force is passed. The reporter says this guard would have caught every failure in #21.

Open questions for triage:

Activity

  1. adrianbrowning commented on Oct 5, 2026

    @adrianbrowning
    OwnerAuthor

    This was generated by AI during triage.

    Triage note after #24 and #15:

    They don't cover this. Since #15, extract refuses ambiguous mappings before it writes anything: several blocks for one file without distinct region= values, broken markers in an existing target, unsafe paths. It never compares sizes, though. Two cases can still shrink a file with no check:

    • --force replacing an existing whole file with a shorter block, which is the case this issue asks about.
    • A region splice whose new body is shorter than the old one. This is normal when you edit code, so a guard here would need a threshold.

    What's still to decide:

    • Does --force cover this already? It's an explicit opt-in, so a shrink guard might mean a second flag (--allow-shrink) or a ratio threshold.
    • Should splices be included at all?
  2. adrianbrowning commented on Oct 8, 2026

    @adrianbrowning
    OwnerAuthor

    This was generated by AI during triage.

    Closing as out of scope. The reasoning is recorded in .out-of-scope/extract-shrink-guard.md (added in #60).

    Checked on main (238c32e):

    • A region= block splices into the existing file. A file with an import, a region and an export kept the import and the export, and only the region body changed.
    • Without --force, an existing whole file is never overwritten. A 40-line src/whole.ts was skipped with "exists and has block(s) without region=. Use --force to overwrite." and extract exited 2.
    • extract --force is the only way left to shrink a file: the same src/whole.ts went from 40 lines to 1, exit 0. That is what --force asks for, so a guard would only add a second flag for the same intent.
    • mdcode extract --check --force (feat: extract --check and the check-sync GitHub Action (#28, 1/2) #57) previews it without writing: src/whole.ts differs from this block; extract would overwrite it.

    Splices that make a region shorter are ordinary edits, so a size threshold there would refuse normal changes.

  3. added
    wontfixThis will not be worked on
    and removed
    needs-triageMaintainer needs to evaluate this issue
    on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwontfixThis will not be worked on

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions