Skip to content

fix(cli): keep unrelated AGENTS.md content intact on remove - #3185

Open
L4XB wants to merge 1 commit into
upstash:masterfrom
L4XB:fix/remove-rule-section-seam
Open

fix(cli): keep unrelated AGENTS.md content intact on remove#3185
L4XB wants to merge 1 commit into
upstash:masterfrom
L4XB:fix/remove-rule-section-seam

Conversation

@L4XB

@L4XB L4XB commented Sep 11, 2026

Copy link
Copy Markdown

Summary

ctx7 remove for the append-style rule files (AGENTS.md, GEMINI.md) cut the <!-- context7 --> section and then ran .replace(/\n{3,}/g, "\n\n").replace(/^\n+/, "") on the whole file. That silently rewrote content the CLI never added: two blank lines inside a fenced code block were collapsed, and the spacing between the user's own sections changed.

This PR normalizes only the seam left by the removed section (at most one blank line between the surrounding content, a single trailing newline) and leaves everything else byte for byte as it was. The section lookup itself is unchanged.

Before / after for

# Project rules

```text
line a


line b
```


## Team notes

<!-- context7 -->
…
<!-- context7 -->

## Tail section
  • before this PR: the blank lines inside the code block and before ## Team notes are collapsed
  • after this PR: only the Context7 section is gone, the rest is identical

Tests

Two cases added to packages/cli/src/__tests__/remove.test.ts: the file above is compared with toBe against the expected byte-identical result, and a trailing section removal keeps the preceding content (including trailing spaces on the user's lines).

pnpm --filter ./packages/cli test    # 19 files, 370 tests
pnpm lint:check / typecheck          # clean

Changeset: ctx7 patch.

uninstallRule cut the Context7 section and then collapsed every run of
three or more newlines in the whole file, and stripped leading newlines.
That silently rewrote the user's own content: blank lines inside fenced
code blocks and the spacing between their sections were changed by a
command that should only remove what setup added.

Normalize only the seam left by the removed section (at most one blank
line between the surrounding content, single trailing newline) and leave
everything else byte for byte as it was.
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