Skip to content

fix: append_file after_line=-1 inserts at wrong position in prepend mode #16

Description

@four-bytes-robby

Bug

Found by cubic-dev-ai on PR #15. In src/tools/append-file.ts, when mode=prepend and after_line=-1, the content is inserted at the wrong position (beginning or after last content line) instead of before the last line.

Expected

after_line=-1 should mean "insert before the last line" (i.e., second-to-last position), consistent with negative array indexing semantics.

Fix

Adjust the line-splitting logic so -1 correctly maps to lines.length - 2 (insert before the last element).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions