Skip to content

feat(cli): record bounded previews for oversized evidence artifacts - #78

Merged
ElbertePlinio merged 3 commits into
mainfrom
feat/64-evidence-compression
Sep 3, 2026
Merged

ElbertePlinio merged 3 commits into
mainfrom
feat/64-evidence-compression

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

Sixth and last PR of the #64 stack, on top of #70.

Why

Screenshots went into evidence at full capture resolution. That is what a vision model pays for: cost scales with pixel area, not file size, so a 4K capture costs about six times a 1568px one to read. It also makes plain evidence folders heavy.

Compression was measured and rejected

Against a 1280x800 and a 3840x2160 capture:

Encoder Size vs original
PNG re-encode (image crate) 112 to 113%
WebP lossless (image-webp, pure Rust) 111%
JPEG q82 (lossy) 99% and 123%
libwebp (C) about 50%, but needs a C toolchain and breaks cargo check for x86_64-pc-windows-msvc, which CI verifies

Nothing pure-Rust makes the files smaller, and the token cost would not have moved anyway.

What ships instead

The artifact stays byte-identical, and a bounded preview is derived beside it.

  • A source over 1568px on its longest edge is downscaled with Lanczos3 and stored next to the original. Nothing is generated below the cap.
  • The document records source dimensions and, when a preview exists, its path, dimensions, bytes and digest.
  • The report lists the full capture as the entry and nests the preview under it. A reader of the report alone can still reach and verify the primary evidence.
  • Previews count against the total image budget, so a run cannot evade the cap by producing many. An aliased source still yields one artifact and one preview.
  • Document version becomes 2. The input contract does not move: the new fields are derived, never submitted, so a v1 input still records and gets a v2 document back.

Verification

  • cargo test -p pickforge-cli: all green locally after rebasing onto main.
  • New tests cover the preview being produced once and bounded, source bytes untouched, previews counting toward the budget, v1 input accepted with v0 and v3 rejected, and the report linking both original and preview.
  • Vision-verified device pass on the Flutter alpha recorded evidence through this path; the report and the skill used for it live outside this repo.

Screenshots were going into evidence at full capture resolution, which is what
a vision model pays for: its cost scales with pixel area, not file size. A 4K
capture costs six times a 1568px one to read.

Compression is the wrong lever and measurement says so. Against a 1280x800 and
a 3840x2160 capture, re-encoding PNG through the image crate lands at 112-113%
of the original, image-webp lossless at 111%, and JPEG q82 at 99% and 123% while
also being lossy. libwebp does halve it, but it needs a C toolchain and breaks
cargo check for x86_64-pc-windows-msvc, which this crate verifies.

So keep the artifact byte-identical and derive a bounded preview instead. When a
source exceeds 1568px on its longest edge it is downscaled with Lanczos3 and
stored beside the original; the document records source dimensions and, when one
exists, the preview's path, dimensions, bytes and digest. The report prefers the
preview. Nothing is generated below the cap.

Previews count against the total image budget so a run cannot evade the cap by
producing many of them, and an aliased source still yields one artifact and one
preview.

The document version becomes 2, but the input contract does not move: the new
fields are derived here, never submitted, so a v1 document still records and
gets a v2 document back.
…view

The report listed the preview's path, dimensions and digest in place of the
original, so a reader of report.md alone could neither reach the primary
evidence nor verify its hash. A derivative standing in for the thing it derives
from defeats the point of an evidence document.

List the full capture as the entry and nest the preview under it. Both carry
their own dimensions, byte count and digest.
Rust 1.98 clippy flags `&a.sha256` inside format! as useless_borrows_in_formatting,
and CI runs with -D warnings.
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