Skip to content

enhance(cli): Compose --keep-first/--keep-last with --first/--last - #877

Merged
JeanMertz merged 1 commit into
mainfrom
jp-c-fist
Jul 25, 2026
Merged

enhance(cli): Compose --keep-first/--keep-last with --first/--last#877
JeanMertz merged 1 commit into
mainfrom
jp-c-fist

Conversation

@JeanMertz

Copy link
Copy Markdown
Collaborator

jp conversation compact previously rejected --keep-first/--keep-last whenever --first/--last were also given. Users who wanted to compact a bounded window while still preserving a prefix or suffix inside that window had no way to express it.

--keep-first N --first M now compacts the first M turns minus the preserved prefix, e.g. --keep-first 1 --first 16 compacts turns 2 through 16. Likewise --keep-last N --last M compacts the last M turns minus the preserved suffix, e.g. --keep-last 2 --last 16 compacts the 14 turns before the final 2.

Since clap's conflicts_with can't express "reject only when the kept count exceeds the selected count," a Compact::validate step runs before compaction and rejects --keep-first/--keep-last values larger than the corresponding --first/--last count, returning an error instead of silently compacting nothing. Equal values are still allowed, since that legitimately selects an empty range.

…last`

`jp conversation compact` previously rejected `--keep-first`/`--keep-last`
whenever `--first`/`--last` were also given. Users who wanted to compact
a bounded window while still preserving a prefix or suffix inside that
window had no way to express it.

`--keep-first N --first M` now compacts the first M turns minus the
preserved prefix, e.g. `--keep-first 1 --first 16` compacts turns 2
through 16. Likewise `--keep-last N --last M` compacts the last M turns
minus the preserved suffix, e.g. `--keep-last 2 --last 16` compacts the
14 turns before the final 2.

Since clap's `conflicts_with` can't express "reject only when the kept
count exceeds the selected count," a `Compact::validate` step runs
before compaction and rejects `--keep-first`/`--keep-last` values larger
than the corresponding `--first`/`--last` count, returning an error
instead of silently compacting nothing. Equal values are still allowed,
since that legitimately selects an empty range.

Signed-off-by: Jean Mertz <git@jeanmertz.com>
@JeanMertz
JeanMertz merged commit a85c7fe into main Jul 25, 2026
16 checks passed
@JeanMertz
JeanMertz deleted the jp-c-fist branch July 25, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant