Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project are documented here, following
[Keep a Changelog](https://keepachangelog.com/) and semantic versioning.

## [0.1.13] - 2026-09-16

### Fixed

- Repair orphan managed-block end markers instead of duplicating them.

## [0.1.12] - 2026-09-16

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ctxtrim",
"version": "0.1.12",
"version": "0.1.13",
"description": "Trim what bloats your AI coding context. Scan a repo, find the high-cost/low-value files ballooning your Claude Code / Cursor / Codex context, and write ignore files to cut token cost. Zero dependencies.",
"type": "module",
"bin": {
Expand Down
6 changes: 5 additions & 1 deletion src/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ export function block(patterns) {
export function merge(existing, patterns) {
const b = block(patterns);
const startIndex = existing.indexOf(START);
const endIndex = existing.indexOf(END, startIndex + START.length);
const endIndex = existing.indexOf(END, startIndex === -1 ? 0 : startIndex + START.length);
if (startIndex !== -1 && endIndex !== -1) {
return existing.replace(new RegExp(escape(START) + "[\\s\\S]*?" + escape(END)), b).trimEnd() + "\n";
}
if (startIndex !== -1) {
const base = existing.slice(0, startIndex).trim();
return (base ? base + "\n\n" : "") + b + "\n";
}
if (endIndex !== -1) {
const base = (existing.slice(0, endIndex) + existing.slice(endIndex + END.length)).trim();
return (base ? base + "\n\n" : "") + b + "\n";
}
const base = existing.trim();
return (base ? base + "\n\n" : "") + b + "\n";
}
Expand Down
8 changes: 8 additions & 0 deletions test/ctxtrim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ test("ignore merge repairs a managed block with no end marker", () => {
assert.equal((repaired.match(/ctxtrim \(managed\)/g) || []).length, 2);
});

test("ignore merge repairs an orphan end marker", () => {
const existing = "# my own rule\n# <<< ctxtrim (managed) <<<\n";
const repaired = merge(existing, ["dist/"]);
assert.equal((repaired.match(/ctxtrim \(managed\)/g) || []).length, 2);
assert.ok(repaired.includes("# my own rule"));
assert.ok(repaired.includes(block(["dist/"])));
});

test("clean repo (only source) reports nothing to trim", () => {
// scanning the src subdir alone = only source
const s = scanRepo(join(repo, "src"));
Expand Down
Loading