Skip to content

feat(figures): repair broken figure images and let you crop them - #17

Merged
Rl0007 merged 7 commits into
bwhtech:mainfrom
vishwajeet-13:fix/figure-recrop
Oct 5, 2026
Merged

Rl0007 merged 7 commits into
bwhtech:mainfrom
vishwajeet-13:fix/figure-recrop

Conversation

@vishwajeet-13

@vishwajeet-13 vishwajeet-13 commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

What this does

Sometimes the PDF parser puts a broken/fake image in place of a real figure. This PR:

  • Auto-fixes it by swapping in the page's own photo, wherever it happens (import, reparse, or agent edits).
  • Adds a button in Page Review to crop the exact figure out of the page photo by hand.

Hover over any figure in Page Review to crop/re-crop it:

pr_recrop_hover.png

vishwajeet-13 and others added 2 commits September 21, 2026 16:53
Auto-repairs hallucinated image tags to the page photo on import/reparse,
lets the agent replace a single figure tag via use_page_image(caption=...),
and adds a manual crop dialog in Page Review so any figure (fixed or not)
can be cropped from the page photo and re-cropped later if needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@vishwajeet-13 vishwajeet-13 changed the title Fix broken figure images and let you crop them feat(figures): repair broken figure images and let you crop them Sep 21, 2026
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the prior authorization, duplicate-selection, data-boundary, semantic-color, request-API, and lockfile concerns are addressed.

Fix All in Claude CodeFindings

  1. P2 Lockfile missing dependency ▶
Fix with agent prompt
### Issue 1
frontend/package.json:undefined-15
The new load-bearing `cropperjs` dependency was added only to `package.json`; the tracked Yarn v1 lockfile has no `cropperjs` resolution. A frozen install will reject the inconsistent manifest, while an ordinary install can silently rewrite the lockfile and resolve a different package graph. Regenerate and include `frontend/yarn.lock` with this dependency.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR repairs invalid figure image references by substituting page images during remediation and reparsing, adds targeted figure cropping to Page Review, and extends the agent’s page-image tool to replace a single captioned image.

  • Adds a crop dialog and semantic hover controls for figures.
  • Adds a permission-checked API and engine flow that renders and stores private crops.
  • Uses positional Markdown spans to update the selected duplicate occurrence.
  • Moves persistence operations behind the engine store boundary.
  • Adds the Cropper.js lockfile resolution and backend coverage for cropping, authorization, duplicate tags, and image repair.

Reviews (4) · Last reviewed commit: "fix: address Greptile review findings on..."

Comment thread wikify/api/pages.py Resolved
Comment thread wikify/engine/figure.py Resolved
Comment thread wikify/engine/figure.py Resolved
Comment thread frontend/package.json Outdated
"d3-force": "^3.0.0",
"d3-selection": "^3.0.0",
"d3-zoom": "^3.0.0",
"cropperjs": "^1.6.3",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Lockfile missing dependency

The new load-bearing cropperjs dependency was added only to package.json; the tracked Yarn v1 lockfile has no cropperjs resolution. A frozen install will reject the inconsistent manifest, while an ordinary install can silently rewrite the lockfile and resolve a different package graph. Regenerate and include frontend/yarn.lock with this dependency.

Prompt To Fix With AI
This is a comment left during a code review.
Path: frontend/package.json
Line: 15

Comment:
**Lockfile missing dependency**

The new load-bearing `cropperjs` dependency was added only to `package.json`; the tracked Yarn v1 lockfile has no `cropperjs` resolution. A frozen install will reject the inconsistent manifest, while an ordinary install can silently rewrite the lockfile and resolve a different package graph. Regenerate and include `frontend/yarn.lock` with this dependency.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

vishwajeet-13 and others added 2 commits September 21, 2026 17:04
Flagged by review as not needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
wiki@develop now ships title as Small Text natively, so
add_wiki_title_customizations() no longer needs a Property Setter to
widen it, and the old assertion (exactly 1 setter) fails with 0.
Assert idempotency (count doesn't grow on a second run) instead of a
fixed count, so the test holds regardless of the upstream default.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread frontend/src/components/PageReview.vue Resolved
- Require read access to the source document before cropping or
  rewriting its page content (crop_page_figure was reachable with any
  other document's identifier).
- Fix duplicate-tag replacement to target the clicked occurrence by
  position instead of always replacing the first textual match.
- Move Wikify Import/File/Source Page lookups and the crop file write
  behind wikify/engine/store.py instead of querying them directly from
  the engine.
- Switch FigureCropDialog to Frappe UI v3 useCall instead of the
  low-level call helper.
- Use semantic surface/ink tokens for the figure-hover overlay instead
  of bg-black/text-white.
- Regenerate frontend/yarn.lock so it resolves the cropperjs dependency.
@vishwajeet-13

Copy link
Copy Markdown
Collaborator Author

Addressed all of Greptile'''s findings in 595221f:

  • Missing document authorization (wikify/api/pages.py): crop_page_figure now calls permission.assert_readable(None, source_document) before opening the PDF or writing the page, so the caller needs read access to that document'''s project. Added TestPagesApiAcl.test_cropping_a_page_of_an_unreadable_document_is_refused.
  • Wrong duplicate figure replaced (wikify/engine/figure.py): added tags.find_tag_spans and switched the replace to be position-based instead of str.replace(tag, ..., 1), so clicking the 2nd of two textually-identical tags edits the 2nd one, not the 1st. Added test_identical_duplicate_tags_replace_the_clicked_occurrence.
  • Store boundary bypassed (wikify/engine/figure.py): moved the Wikify Import/File/Source Page lookups and the crop save_file call into store.get_import_pdf_path, store.get_page_for_crop, store.save_crop_file, so store.py stays the ORM seam.
  • Nonstandard request API (FigureCropDialog.vue): switched from the low-level call to useCall.
  • Nonsemantic overlay colors (PageReview.vue): swapped bg-black/0 / group-hover:bg-black/30 / text-white for bg-surface-gray-7/0 / group-hover:bg-surface-gray-7/30 / text-ink-white.
  • Lockfile missing dependency (frontend/package.json): ran yarn install to add the cropperjs resolution to yarn.lock.

Full backend suite + yarn build pass; the 3 pre-existing failures in test_classify/test_rag_api (taxonomy seeding) reproduce on the base commit too and are unrelated to this PR.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@Rl0007
Rl0007 merged commit ce01dae into bwhtech:main Oct 5, 2026
3 checks passed
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.

2 participants