Commit Graph

412 Commits

Author SHA1 Message Date
9586aecfdc debug: log file sizes at extraction and processing stages
Add logging to compare file sizes:
- [EXTRACT] sent to Gemini
- [CREATE_ITEM] received when creating item

This will reveal if image is being processed/changed between extraction and local processing.
2026-04-22 10:14:03 +03:00
4e23899f87 fix: remove negation from rotation to match prompt semantics
New prompt defines rotation_degrees as already signed:
- positive = counter-clockwise rotation
- negative = clockwise rotation

Old code negated it: rotate(-rotation_degrees), which inverted the direction.
Now: rotate(rotation_degrees) directly uses Gemini's signed value.
2026-04-22 10:06:29 +03:00
2546f8abbe refine: clarify rotation analysis to account for text orientation + tilt
Previous prompt only measured text baseline angle from horizontal (-45° to +45°),
missing that text can be vertical/sideways, requiring larger rotations (up to ±180°).

New guidance:
- Measure TOTAL rotation needed to make text horizontal and readable
- Account for both chassis tilt AND text orientation (horizontal vs vertical)
- Example: 22° tilt + 90° vertical text = 112° total rotation
- Allows full -180° to +180° range instead of limiting to ±45°

No changes to item identification fields, OCR rules, or crop bounds analysis.
2026-04-22 10:01:03 +03:00
92c8517663 debug: add explicit logging to show crop bounds and rotation values 2026-04-22 09:55:53 +03:00
197dcadfee fix: apply crop bounds before EXIF rotation to match AI analysis
Gemini analyzes raw image and returns crop_bounds for that coordinate space.
Previous code applied EXIF rotation first, changing image dimensions, then
used crop_bounds on the rotated image (coordinate mismatch).

Now: crop on raw image (matches AI) → then apply EXIF + manual rotation.
This ensures cropped region contains the actual item, not background.
2026-04-22 09:50:08 +03:00
59565c9b8a improve: comprehensive process cleanup in startup script
- Add -9 (force kill) flag to all pkill commands
- Kill Python backend processes explicitly
- Kill npm and node processes
- Use fuser to kill processes bound to ports 8000, 3001, 3002, 3003
- Add 1 second wait after cleanup
- Ensures absolutely clean state before restart
2026-04-22 09:45:50 +03:00
70a08ae1e9 improve: add rotation bounds and error detection to AI prompt
- Cap normal rotation to -45 to +45 degrees (flags errors beyond)
- Add explicit warning about 60°+ being measurement error
- Clarify 'safe default' is 0 if uncertain
- Prevent Gemini from wild angle guesses (like 110°)
- Help AI self-correct measurement errors
2026-04-22 09:44:28 +03:00
1e7dd064f9 improve: clarify rotation detection in AI extraction prompt
- Emphasize MEASURING TEXT ANGLE precisely, not item orientation
- Add explicit calibration examples (22°, 90°, -45°, etc.)
- Clarify positive = counter-clockwise, negative = clockwise
- Help AI understand baseline measurement concept
- Keep all field identification rules unchanged
2026-04-22 09:40:40 +03:00
8d9e8998f8 fix: clean shutdown handling in start_server.sh
- Add signal traps for SIGINT (Ctrl-C) and SIGTERM
- Cleanup function kills all child processes gracefully
- Script now exits cleanly without hanging
- Users can press Ctrl-C to stop all services at once
2026-04-22 09:33:43 +03:00
a2847092ac debug: add detailed logging to image processing pipeline
- Log input image size, crop bounds, and rotation degrees
- Log crop rectangle coordinates and result size
- Log OpenCV smart crop success/failure details
- Track pixel count to detect zero-size crops
2026-04-22 09:23:51 +03:00
ba581744ec refactor: improve checkbox styling and remove popup
- Update photo save checkbox to match app design (border-slate-600, htmlFor label)
- Remove success popup overlay - modal closes immediately after save
- Simplify confirmSingleItem to remove setTimeout logic
- Toast notification used for user feedback instead
2026-04-22 09:17:56 +03:00
99a4cae572 fix: show item save confirmation with image before closing
- Add savingIndex state to track saving operation
- Display success overlay with saved image for 1.5 seconds
- Show item name in confirmation message
- Prevents modal from closing immediately after save

Fixes user complaint about image disappearing too quickly without confirmation
2026-04-22 09:07:44 +03:00
e5615826d6 Revert "fix: apply rotation before cropping for better text orientation"
This reverts commit f8e54d0f8b.
2026-04-22 09:02:22 +03:00
f8e54d0f8b fix: apply rotation before cropping for better text orientation
- Move manual rotation before cropping and text detection
- Detect text orientation on full rotated image (not just cropped region)
- This allows text angle detection to see full context and properly orient labels
- Crop happens after orientation correction for cleaner results
2026-04-22 08:58:17 +03:00
09a66bd3d5 feat: clean up image files when item is deleted from catalog
- Delete photo_path and photo_thumbnail_path files on item deletion
- Handle file not found gracefully with logging
- Preserves audit logs while removing actual image files
2026-04-22 08:54:22 +03:00
092271790c docs: update VERSION and SESSION_STATE for v1.14.4 - Image Pipeline Complete 2026-04-22 08:51:04 +03:00
64d177e791 fix: complete image pipeline - rotation, URL, preview
- Add rotation_degrees parameter to ImageProcessor.process_photo()
- Pass rotation through _auto_save_photo_from_extraction() to processor
- Allow no-crop fallback when crop_bounds is None
- Add buildPhotoUrl() helper to resolve backend URLs correctly
- Update frontend components to use backend URL for image sources
- Replace Use/Skip Photo buttons with checkbox in AI extraction UI
- Add images/ to .gitignore to prevent accidental commits

Addresses: rotation never applied, image 404s (relative to Next.js not backend), preview blank in edit form
2026-04-22 08:50:25 +03:00
1c13ebd76f docs: update VERSION and SESSION_STATE for v1.14.3 - Image Confirmation UX
Documented the complete image pipeline feature:
- v1.14.1: Type system fix (photo_path fields)
- v1.14.2: Serialization fix (Blob to base64)
- v1.14.3: User control (image confirmation buttons)

Users now have full control over whether extracted photos are auto-saved
through the 'Use Photo' / 'Skip Photo' buttons in the editing form.
2026-04-21 20:01:28 +03:00
c3f63ade6a feat: add image confirmation step to AI extraction flow
Users now see the extracted photo during item editing and can choose to:
- 'Use Photo': Auto-save the image with the item
- 'Skip Photo': Create item without saving the photo

Changes:
1. frontend/components/AIOnboarding.tsx: Added image preview panel in edit form
   - Shows extracted image to user
   - Buttons to accept/reject photo
   - Visual feedback when photo is skipped

2. frontend/hooks/useAIExtraction.ts: Updated confirmSingleItem and confirmAllItems
   - Respect user's photo decision (_skipPhoto flag)
   - Only pass extractedImageBlob if user approved it
   - Prevents unwanted auto-photo-save

This gives users full control over which extracted photos are auto-saved.
2026-04-21 20:00:55 +03:00
c95e4c40b8 docs: update VERSION and SESSION_STATE for v1.14.2 - Blob serialization fix
Documented the complete image pipeline bugfix:
- Part 1 (v1.14.1): Type system mismatch for photo_path fields
- Part 2 (v1.14.2): Blob serialization issue - image not reaching backend

The extracted image blob is now converted to base64 before sending to the API,
ensuring it's JSON-safe and matches the backend's ItemCreate schema.
2026-04-21 19:54:24 +03:00
cbfd7232ca fix: convert extracted image blob to base64 before sending to API
The extracted image blob from AI extraction was not being sent to the backend
because Blob objects cannot be JSON serialized. Fixed by:

1. Converting Blob to base64 before sending to API
2. Renaming fields: extractedImageBlob → extracted_image_bytes, imageProcessing → image_processing
3. Removing Blob from local DB (keep original data structure for IndexedDB)
4. Applying same fix to both single item and batch update flows

This ensures the auto-photo-save feature receives the image data it needs.
2026-04-21 19:53:53 +03:00
f72b976c33 docs: update SESSION_STATE for Session 29 - Image Display Bugfix
Documented the image display issue, root cause (type system mismatch),
and the fix applied in v1.14.1. Images now correctly display from
the auto-photo-save feature in both ItemDetailModal and InventoryTable.
2026-04-21 19:47:52 +03:00
a62e4e0b53 build: version bump to v1.14.1 - image display fixes 2026-04-21 19:47:28 +03:00
eaa2d2d29f fix: replace toast.warning with toast.success in useItemCreate
toast.warning is not a valid method in react-hot-toast API. Changed to
toast.success since the item was successfully created even if photo upload failed.
2026-04-21 19:47:16 +03:00
b5fb2a8cdb fix: add photo_path fields to frontend Item interface to display saved photos
The backend returns photo_path, photo_thumbnail_path, and photo_upload_date
from the AI auto-save feature, but the frontend Item interface was missing
these fields, causing images not to display in ItemDetailModal and InventoryTable.

Updated:
- frontend/lib/db.ts: Added missing photo fields to Item interface
- frontend/components/ItemDetailModal.tsx: Use photo_path first, fallback to image_url
- frontend/components/InventoryTable.tsx: Use photo_path first, fallback to image_url

This ensures the UI can now display photos saved by the auto-photo-save feature.
2026-04-21 19:45:19 +03:00
2e61dfe935 chore: clean up test artifacts from photo upload tests 2026-04-21 19:38:18 +03:00
174c35bac3 docs: complete Phase 3 documentation - AI extraction + auto-photo-save implementation complete 2026-04-21 19:35:18 +03:00
baf38f227f docs: update SESSION_STATE for Phase 3 Task 8 (E2E test) completion 2026-04-21 19:33:38 +03:00
c22dadbd1a test: add E2E test for AI extraction + auto-photo-save flow 2026-04-21 19:33:18 +03:00
3ba31a7b48 docs: update SESSION_STATE for Phase 3 Task 7 completion 2026-04-21 19:31:49 +03:00
bbe60bb471 test: add integration tests for item creation with auto-photo-save 2026-04-21 19:31:26 +03:00
b56affa90e docs: update SESSION_STATE for Phase 3 Task 6 completion 2026-04-21 19:27:47 +03:00
08fc785583 feat: pass extracted image and image_processing metadata to item creation
- Updated confirmSingleItem() to include extractedImageBlob and imageProcessing
- Updated confirmAllItems() to pass image data for bulk item creation
- Each extracted item now carries its own image_processing metadata
- All items in bulk creation share the same extracted image blob
- Added 12 comprehensive tests verifying data is passed correctly
- All 465 frontend tests passing, zero regressions
2026-04-21 19:27:17 +03:00
fab1e81cf6 feat: auto-upload photo after item creation if image_processing provided 2026-04-21 19:22:10 +03:00
68f52ccb03 docs: update SESSION_STATE for Phase 3 Task 4 completion 2026-04-21 19:04:35 +03:00
d73b7e45a1 feat: store extracted image blob and image_processing metadata in useAIExtraction hook 2026-04-21 19:04:16 +03:00
2d219af7f6 docs: update SESSION_STATE for Phase 3 Task 3 completion 2026-04-21 19:00:30 +03:00
4f63b3b99e feat: integrate auto-photo-save into item creation endpoint
- Extend ItemCreate schema with optional extracted_image_bytes (base64) and image_processing (dict)
- Update create_item endpoint to call _auto_save_photo_from_extraction after item creation
- Decode base64 image bytes and pass crop_bounds, rotation_degrees to helper
- Don't block item creation if photo save fails (log warning instead)
- Item returned with photo_path, photo_thumbnail_path populated if save succeeded
- Full backward compatibility: old clients without image fields work unchanged
- Add 5 integration tests covering all scenarios:
  - Create item WITH image_processing → photo auto-saved
  - Create item WITHOUT image_processing → no photo (backward compatible)
  - Create item WITH invalid image_processing → item created, photo skipped
  - Create item WITH crop_bounds=None → item created, photo skipped
  - Create item WITH bytes but NO processing metadata → item created, photo skipped
- All 158 backend tests passing, zero regressions
2026-04-21 19:00:06 +03:00
20fc352f6f docs: update SESSION_STATE for Phase 3 Task 2 completion 2026-04-21 18:56:42 +03:00
eca1ab7fd0 feat: add _auto_save_photo_from_extraction helper with graceful fallbacks 2026-04-21 18:56:17 +03:00
e368574fba docs: update SESSION_STATE for Phase 3 Task 1 completion 2026-04-21 18:53:30 +03:00
ada3669217 test: add tests for image_processing field from AI extraction
- Added 11 comprehensive tests for image_processing parsing
- Tests validate crop_bounds structure: {x, y, width, height} all ints >= 0
- Tests validate rotation_degrees: int/float, -360 to +360
- Tests validate confidence: float, 0.0 to 1.0
- Tests graceful handling when image_processing field is missing
- Tests multiple items with image_processing data
- Tests partial data handling (optional fields)
- Tests with both Gemini and Claude providers
- Updated extract_label_info() to preserve and validate image_processing field
- All tests passing, no regressions
2026-04-21 18:53:04 +03:00
76fa22bba9 docs: write implementation plan for AI extraction + auto-photo-save with 9 bite-sized tasks 2026-04-21 18:49:43 +03:00
ed42a9e306 docs: design AI extraction + auto-photo-save with crop/rotation guidance 2026-04-21 18:39:43 +03:00
770b02864d fix: handle CORS preflight OPTIONS requests before routing 2026-04-21 18:17:00 +03:00
87f3b53d53 docs: update SESSION_STATE for CORS security fix completion (Session 20) 2026-04-21 17:58:55 +03:00
6f1e7731d7 fix: implement subnet-aware CORS middleware to replace insecure wildcard origins 2026-04-21 17:58:14 +03:00
0d7ccf834b docs: update SESSION_STATE for Phase 2 completion and handover
Session 19 summary:
- Network configuration fully environment-variable driven (zero hardcoded IPs)
- SSL proxies bound to SERVER_IP for cross-network access
- Frontend uses SERVER_IP for API routing
- Fixed username input focus-jumping bug in login form
- LAN access fully working (192.168.84.131)
- VPN access needs CORS subnet validation (currently blocked)

Known issues documented for next session:
- Temporary allow_origins=['*'] needs replacement with subnet validation
- VPN CORS blocking (subnet notation creates invalid origin URLs)

All 427 tests passing, build successful.
2026-04-21 17:56:11 +03:00
6bf95a0df0 fix: prevent username input from unmounting during typing in login form
The username input was conditionally hidden when it had a value, causing
the field to disappear and focus to jump to password when typing. Fixed by:
1. Always rendering the username input (removed conditional)
2. Using controlled input with value prop
3. Only auto-focus password when username is already entered

This fixes the focus-jumping bug that made it impossible to enter usernames.
2026-04-21 17:54:19 +03:00
904e153d8a temp: allow all CORS origins for debugging LDAP login issue
Temporarily using allow_origins=['*'] to debug whether CORS is blocking
LDAP login requests from VPN client. This is insecure for production.
TODO: Fix subnet pattern matching in ALLOWED_ORIGINS configuration.
2026-04-21 15:32:01 +03:00