AlexandrAI AGENTS.md
agents-md

AlexandrAI Tools Delete PDF Pages Agent Guide

Agent guide for deleting selected one-based PDF pages while preventing empty output documents.

AGENTS.md

Guidance for coding agents working on AlexandrAI Tools Delete PDF Pages in the alexandrai-tools project.

Project overview

This guide covers src/tools/delete-pages-pdf. It shares the one-based page range grammar used by the page extraction tools, then Body.astro turns parsed pages into a deletion set, keeps every source page whose one-based page number is not selected, rejects attempts to delete all pages, copies the remaining indices into a new PDF, and downloads pages-deleted.pdf.

Primary source files

  • src/tools/delete-pages-pdf/index.ts defines meta, PageRangeError, and parsePageRanges.
  • src/tools/delete-pages-pdf/index.test.ts covers comma-separated pages, ranges, overlaps, clamping, blank specs, reversed ranges, zero pages, and garbage input.
  • src/tools/delete-pages-pdf/Body.astro owns PDF loading, delete-set construction, keep-index filtering, all-pages guard, copyPages output, and download action.
  • src/tools/delete-pages-pdf/i18n.ts owns localized page range copy.
  • src/lib/tools.ts registers the tool metadata.

Setup commands

npm install npm test npm run typecheck npm run build npm run dev

Change rules

  • Parse user input as one-based page numbers.
  • Deduplicate overlapping delete ranges before filtering kept pages.
  • Clamp range ends to the source page count.
  • Ignore single pages beyond the total page count.
  • Reject reversed ranges, zero pages, and malformed tokens.
  • Prevent deleting every page from the source document.
  • Copy kept pages in their original order to the output document.

Testing

Test parser behavior, deletion of single pages and ranges, overlapping selections, out-of-range pages, blank range behavior, all-pages deletion rejection, kept page order, output page count, download filename, and clear-state reset.

PR checklist

  • npm test passes for delete-pages-pdf.
  • PDF and binary file processing remain browser-local.
  • Pure helper behavior, UI state, and i18n labels stay aligned.
  • Invalid input, empty output, and download behavior are covered by tests.