Skip to content

Add end-to-end unit system strategy#56

Merged
windoze95 merged 2 commits intomainfrom
feat/unit-system-strategy
Mar 8, 2026
Merged

Add end-to-end unit system strategy#56
windoze95 merged 2 commits intomainfrom
feat/unit-system-strategy

Conversation

@windoze95
Copy link
Owner

Summary

  • Store recipes in source units, tag with unitSystem (us_customary/metric), convert on frontend
  • Fix extractFromURL to preserve source units instead of hardcoding US customary
  • Add detectUnitSystem() for JSON-LD ingredient scanning
  • Tag UnitSystem on all creation paths (chat, regen, fork, all import types)
  • Remove NormalizeMeasurements interface/implementation (replaced by frontend conversion)
  • Remove unused NormalizedAmount/NormalizedUnit/IsEstimated from Ingredient model
  • Add unit_system to AI tool schema and recipe API response

Companion PR

Flutter app changes: https://github.com/windoze95/saltybytes-app/pull/new/feat/unit-system-strategy

Test plan

  • go test ./... -count=1 — all tests pass
  • Import a US recipe URL → verify unit_system: "us_customary" in response
  • Import a European recipe URL → verify unit_system: "metric" in response
  • Chat/regen/fork generation → verify unitSystem set from user preference
  • Canonical cache hit → verify unitSystem preserved from cached data
  • Existing recipes with empty unit_system default to "us_customary"

🤖 Generated with Claude Code

Store recipes in source units, tag with unitSystem, convert on frontend.

- Add UnitSystem field to RecipeDef (us_customary/metric)
- Fix extractFromURL: preserve source units instead of hardcoding US
- Add detectUnitSystem() for JSON-LD ingredient scanning
- Tag UnitSystem on all creation paths (chat, regen, fork, import)
- Remove NormalizeMeasurements (replaced by frontend conversion)
- Remove NormalizedAmount/NormalizedUnit/IsEstimated from Ingredient
- Remove unitSystem param from PreviewFromURL (now auto-detected)
- Add unit_system to AI tool schema and recipe response

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42c3958b6f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Fix 1: Set fallback UnitSystem on ai.RecipeResult before
recipeResultToRecipeDef, not after. The previous approach set it on the
local recipeDef, but populateRecipeCoreFields rebuilds recipe.RecipeDef
from the raw result, dropping the fallback when the AI omits unit_system.

Fix 2: Replace string-contains metric detection with regex patterns
that match compact tokens (250g, 100ml) in addition to spaced forms
(250 g, 100 mL). Real-world JSON-LD frequently omits the space between
quantity and unit, causing systematic misclassification of metric URLs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@windoze95 windoze95 merged commit ca1b913 into main Mar 8, 2026
1 check passed
@windoze95 windoze95 deleted the feat/unit-system-strategy branch March 8, 2026 03:42
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