Skip to content

Locator API: map a PDF position to a source range - #33

Merged
Amet13 merged 4 commits into
mainfrom
claude/relaxed-ramanujan-4sc5w7-locator
Dec 1, 2026
Merged

Amet13 merged 4 commits into
mainfrom
claude/relaxed-ramanujan-4sc5w7-locator

Conversation

@Amet13

@Amet13 Amet13 commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Closes #19.

Query and result

  • Query (proofback_model::locate::Query): page (1-based, required), rect [x0, y0, x1, y1] (PDF points, origin bottom-left), text. At least one of rect and a non-empty text is required. Query::validate enforces this plus bounds: finite coordinates, x0 ≤ x1 and y0 ≤ y1, text up to 4,096 characters.
  • Result (Location): file, line, column, end_line, end_column with the units of Target, plus confidence and reason with the values of Anchor. A page result has no source fields.
  • D-14 holds because the locator runs the import pipeline and only lowers confidence.

Surfaces

  • Rust: pub fn locate(input: &Input<'_>, queries: &[Query]) -> Vec<Location> in proofback-anchor. anchor_one is split so that the locator and the import share its core (anchor_marked); nothing is copied. With PDFium page text, a query's text is found on the page (the occurrence nearest rect) and read with the same PDF context the import uses. Without page text, the query text is aligned on its own.
  • WebAssembly: locate(pdf, synctex?, sources_json, queries_json).
  • Node: require('proofback').locate(pdf, { synctex, sources, queries }), with LocateQuery and LocateResult TypeScript types. Documented in npm/README.md.
  • CLI: proofback locate --pdf <file> [--synctex <file>] --page <n> [--rect x0,y0,x1,y1] [--text <s>] [--json]. With --stdin, one JSON query per line and one JSON result per line. Documented in PLAN §7.

Behaviour

  • Writes nothing. The CLI builds the source tree from --project or the current directory with a default configuration; it never opens .proofback/. A test checks that no .proofback/ appears.
  • Without PDFium: queries with text work. The isolated parser child has a new pages= mode that returns page boxes (lopdf) and, when PDFium is present, the text of the queried pages.
  • Without SyncTeX: text-only mode.
  • Confinement and limits (PLAN §10): PDF parsing stays in the resource-limited child process. SyncTeX paths resolve inside the root as before. Queries are bounded: 100,000 per call, 4,096 characters of text, 64 MB of JSON Lines.
  • Exit codes (PLAN §7): 2 for a malformed command line; 3 for an unreadable PDF or SyncTeX file, or an invalid or unparseable query line (the message names the line).

Schema and docs

site/schema/locate-v1.json is generated from the types by cargo xtask schema, and --check covers it as it covers v1.json. The locator is documented in PLAN §7, npm/README.md, site/llms.txt and the CHANGELOG.

Acceptance

  • Locator equals import: proofback-corpus/tests/locate.rs asks every synthetic markup annotation (highlight, strike-out, underline, squiggly; 300+ per mode) as a locator query, with page, rect and the text the import read. Range (file, line, columns) and confidence equal the import's, with and without SyncTeX. Carets and sticky notes are excluded: they ask "where to insert" or "which line is this note beside", not "where does this text come from", so they have no locator query.
  • Native, WebAssembly and Node parity: cargo xtask sample now also writes 90 locator queries (rect + text, text only, rect only) and their native results. npm/test runs them through the Node (WebAssembly) build and requires deep equality; it passes locally. The CI pages.yml job already runs xtask sample before npm test.
  • Performance: tests/perf.rs now times 500 cold queries on the reference input (page text, SyncTeX and sources parsed from scratch) against the 1 s cold import budget. Not run locally: that test needs the 300-page fixture built with pdflatex, which this container lacks. CI's perf job runs it on this PR.
  • Fuzzing: new target locate_query for parse_queries (added to fuzz.yml), asserting every accepted query passes validation and the bounds.

Tests

  • PROOFBACK_REQUIRE_PDFIUM=1 cargo test --workspace passes, including cli/tests/locate.rs:
    • single query with --json;
    • rect-only query with human output;
    • --stdin with text-only, not-found and out-of-range queries;
    • exit codes 2 and 3;
    • no .proofback/ created.
  • npm test passes (import and locator parity). Clippy is clean apart from warnings that already exist on main. cargo check passes for the fuzz crate.

Notes


Generated by Claude Code

proofback_anchor::locate runs the import pipeline for stateless queries
(page, rect, text) and returns file, line, columns, confidence and reason.
Exposed as proofback locate (flags or JSON Lines on --stdin), in the
WebAssembly build and the Node package with TypeScript types. Schema in
site/schema/locate-v1.json (cargo xtask schema). PDF parsing stays in the
isolated child; queries are bounded; no .proofback/ is read or written.

Tests: the corpus asks every synthetic markup annotation as a query and
gets the import's range and confidence; Node matches native on 90 sample
queries; the perf test times 500 queries; a fuzz target covers the parser.

Refs #19

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xj9ekYmyESdZUsW8uWkzgv
…jan-4sc5w7-locator

# Conflicts:
#	CHANGELOG.md
@Amet13
Amet13 marked this pull request as ready for review December 1, 2026 01:00
…jan-4sc5w7-locator

# Conflicts:
#	CHANGELOG.md
#	docs/PLAN.md
Amet13 pushed a commit that referenced this pull request Dec 1, 2026
The real-world gate test moves from accuracy.rs to tests/real.rs, the
CHANGELOG section sits at its own place, and the website row gets its own
table body, so this PR and #31, #32 and #33 merge in any order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xj9ekYmyESdZUsW8uWkzgv
Amet13 pushed a commit that referenced this pull request Dec 1, 2026
The ink accuracy set moves from accuracy.rs to tests/ink.rs, the CHANGELOG
section sits at its own place, and the nightly fuzz workflow now runs
every [[bin]] of fuzz/Cargo.toml (so no target needs a workflow edit).
This PR and #30, #32 and #33 then merge in any order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xj9ekYmyESdZUsW8uWkzgv
The nightly fuzz workflow on main runs every [[bin]] of fuzz/Cargo.toml,
so locate_query needs no workflow edit. extract_pages fills the new
Extracted.skipped field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xj9ekYmyESdZUsW8uWkzgv
@Amet13
Amet13 merged commit e80cf1d into main Dec 1, 2026
13 of 18 checks passed
@Amet13
Amet13 deleted the claude/relaxed-ramanujan-4sc5w7-locator branch December 1, 2026 01: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.

Expose a locator API that maps a PDF position to a source range

2 participants