Skip to content

feat(snapshot): add --snapshot-compact for token-efficient LLM consumption#61

Merged
avifenesh merged 6 commits intomainfrom
feature/compact-snapshot-format-46
Feb 24, 2026
Merged

feat(snapshot): add --snapshot-compact for token-efficient LLM consumption#61
avifenesh merged 6 commits intomainfrom
feature/compact-snapshot-format-46

Conversation

@avifenesh
Copy link
Collaborator

Summary

  • Add --snapshot-compact boolean flag that applies four token-saving transforms to ARIA snapshots
  • Link collapsing: merges link + /url: child into link "Title" -> /path
  • Heading inlining: merges heading with single link child into heading [hN] "Title" -> /path
  • Decorative image removal: strips img nodes with empty or single-char alt text
  • Duplicate URL dedup: removes second occurrence of same URL at same depth scope
  • Targets 50-70% token reduction on content-heavy pages

Implementation Details

  • New compactFormat() function in scripts/web-ctl.js with hardened regex patterns ([^"]+ instead of .+ to prevent ReDoS)
  • Pipeline position: trimByDepth -> compactFormat -> collapseRepeated -> textOnly -> trimByLines
  • 402 tests pass (24 new tests for compactFormat + 3 edge case tests + flag parsing/validation tests)

Test Plan

  • Guard clause tests (null, undefined, fallback strings, empty string)
  • Link collapsing tests (simple, no /url, extra children, nested)
  • Heading inlining tests (single child, multiple children, no level, plain link)
  • Image removal tests (empty alt, single-char, meaningful, with children)
  • URL dedup tests (same depth, different depth, scope reset)
  • Edge cases (blank lines, transform interaction, dedup after collapse)
  • Pipeline integration test
  • Flag parsing and source validation tests
  • npm test passes (402/402)
  • npm run validate passes

Closes #46

Register --snapshot-compact as a boolean flag and implement the
compactFormat() transform with four sub-passes: link collapsing,
heading inlining, decorative image removal, and duplicate URL dedup.
Insert in the getSnapshot pipeline between trimByDepth and collapseRepeated.
Add compactFormat() function replica to test file and comprehensive
tests covering guard clauses, link collapsing, heading inlining,
decorative image removal, duplicate URL dedup, combination transforms,
and getSnapshot pipeline integration with snapshotCompact option.
…ion tests

Add --snapshot-compact to BOOLEAN_FLAGS replica, flag parsing tests,
source validation for compactFormat function existence, and update
pipeline order test from four to five transforms.
Update SKILL.md with full subsection, commands/web-ctl.md with example,
README.md Common Flags table, and CHANGELOG.md with detailed entry.
Replace greedy .+ with bounded [^"]+ in quoted string regexes and \S+
in URL regexes to prevent ReDoS. Remove unused childIndent variable.
Add tests for blank lines, transform interaction, and dedup after collapse.
@avifenesh avifenesh merged commit 3510f24 into main Feb 24, 2026
2 of 4 checks passed
@avifenesh avifenesh deleted the feature/compact-snapshot-format-46 branch February 24, 2026 17:23
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.

Compact snapshot format for token-efficient LLM consumption

1 participant