pass-7b-implementation

star 1

Implement the NutriAI Pass 7B meal planning engine redesign. Phase 1 is deterministic portioning where USDA resolves all macros and the LLM never sees calorie numbers. Phase 2 adds an AI overlay for ingredient naming only. This is the top engineering priority and the primary App Store release blocker.

Rahulsanecdote By Rahulsanecdote schedule Updated 6/6/2026

name: pass-7b-implementation description: Implement the NutriAI Pass 7B meal planning engine redesign. Phase 1 is deterministic portioning where USDA resolves all macros and the LLM never sees calorie numbers. Phase 2 adds an AI overlay for ingredient naming only. This is the top engineering priority and the primary App Store release blocker.

The non-negotiable architectural constraint for this entire skill: the LLM never computes or receives final macro values. USDA FoodData Central resolves everything server-side.

Pre-flight reads — mandatory before any code change

Read each file fully before proposing any change:

  1. api/_lib/food-intelligence.js — understand the USDA resolution pipeline
  2. The meal plan generation endpoint — trace from api/food.js via ?action= routing to find the handler file
  3. supabase/migrations/ — understand meal_plans and meal_plan_items schema
  4. src/context/AppContext.tsx — understand plan state management
  5. Every file that currently assigns macro values to plan items

Before writing: list every location where macro values are currently assigned. Flag any location where an LLM response currently sets calories, protein, carbs, or fat.

Phase 1 — Deterministic portioning

Goal: every macro value comes from USDA. Zero exceptions.

  1. Deterministic portioning module: Input: ingredient concept (name + quantity descriptor) Output: resolved macros from USDA FoodData Central Constraint: no calorie or macro numbers in any LLM prompt or response

  2. Slot-level isolation using Promise.all: Each meal slot resolves independently. A failed slot retries in isolation — other slots unaffected. After retry failure: mark that slot with an error state. Coverage gate: surface a user-visible warning when fewer than 50% of slots have resolved. Do not treat it as a hard failure.

  3. Double-normalization guard: After USDA resolution assert: abs(raw_calories - usda_resolved_calories) / raw_calories < 0.05 If guard fires: log with ingredient name, raw value, and resolved value. Alert. Never silently use the wrong value. Critical test case: banana input 312 cal → output must be 312 cal. It must never resolve to 975 cal/100g.

  4. Feature flag and versioning: USE_AI_ORCHESTRATOR=false → deterministic path USE_AI_ORCHESTRATOR=true → AI-orchestrated path engine_version: 'behavioral-v1' vs 'ai-orchestrated-v1'

Phase 1 verification — required before starting Phase 2

□ pnpm build: PASS □ pnpm test: all meal planning tests pass □ Banana test: 312 cal in → 312 cal out □ Slot isolation: force one slot to fail → others complete □ Coverage gate: 4 of 8 slots resolved → warning displayed, no crash □ Grep LLM prompts for calorie patterns → 0 matches □ Grep LLM responses for numeric calorie patterns → 0 matches

Phase 2 — AI overlay (only after Phase 1 verified)

Goal: variety and natural ingredient naming via LLM, no macro computation.

  1. LLM prompt contains:

    • User dietary preferences and restrictions
    • Meal slot context (breakfast / lunch / dinner / snack)
    • Target food categories only — no calorie targets, no macro targets Expected output: ingredient names + approximate natural-language quantities e.g. "one medium banana", "150g grilled chicken breast" No numbers representing calories or macros.
  2. After every LLM response — grep for: \d+\s*(cal|kcal|calories|g protein|g carb|g fat) If any match: reject the response, log the violation, fall back to the deterministic path for that slot.

  3. USDA resolves all macros from the ingredient concept list — same pipeline as Phase 1.

Implementation output format (per pass)

Pass: [Phase 1 or Phase 2, step number]

Files changed

Change description

Tests added

Build gate: pnpm build — expected: PASS

Verification: [which checklist items confirmed]

Install via CLI
npx skills add https://github.com/Rahulsanecdote/AICalorietrackermain --skill pass-7b-implementation
Repository Details
star Stars 1
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator
Rahulsanecdote
Rahulsanecdote Explore all skills →