---
description: Log diet and meal information
argument-hint: <time> <meal_type> <description> [--carbs low|medium|high] [--calories N]
allowed-tools: Bash(python:*), Read, Write
---

# Log Diet Entry

Record what you ate for tracking and analysis.

## Parse User Input

Input: $ARGUMENTS

Expected format: `<time> <meal_type> <description> [options]`

Examples:
- `12:30 lunch protein powder + 1 egg --carbs low`
- `19:00 dinner tuna salad with olive oil --carbs low --calories 600`
- `11:30 lunch 运动一小时后蛋白粉一勺再过二十分钟吃了半个咸鸭蛋、一个水煮蛋、半截玉米和一个红薯 --carbs medium`

## Execute

!`python3 << 'PYTHON_SCRIPT'
import re
from datetime import date
from health.services.manual_log_storage import ManualLogStorage
from health.models.manual_log import DietEntry

raw_input = """$ARGUMENTS"""

# Extract optional flags first
carbs_match = re.search(r'--carbs\s+(\w+)', raw_input)
calories_match = re.search(r'--calories\s+(\d+)', raw_input)
notes_match = re.search(r'--notes\s+"([^"]+)"', raw_input)

carbs = carbs_match.group(1) if carbs_match else None
calories = int(calories_match.group(1)) if calories_match else None
notes = notes_match.group(1) if notes_match else None

# Remove flags from input to get core content
clean_input = re.sub(r'--carbs\s+\w+', '', raw_input)
clean_input = re.sub(r'--calories\s+\d+', '', clean_input)
clean_input = re.sub(r'--notes\s+"[^"]+"', '', clean_input)
clean_input = clean_input.strip()

# Parse time and meal_type (first two tokens)
parts = clean_input.split(None, 2)  # Split on whitespace, max 3 parts

if len(parts) >= 3:
    time_str = parts[0]
    meal_type = parts[1]
    description = parts[2]
elif len(parts) == 2:
    time_str = parts[0]
    meal_type = "snack"
    description = parts[1]
elif len(parts) == 1:
    time_str = "12:00"
    meal_type = "snack"
    description = parts[0]
else:
    time_str = "12:00"
    meal_type = "snack"
    description = "No description"

entry = DietEntry(
    time=time_str,
    description=description,
    meal_type=meal_type,
    carbs=carbs,
    estimated_calories=calories,
    notes=notes
)

storage = ManualLogStorage()
log = storage.add_diet_entry(date.today(), entry)

print(f"✅ Diet entry logged for {log.log_date}")
print(f"   Time: {entry.time}")
print(f"   Meal: {entry.meal_type}")
print(f"   Description: {entry.description}")
if entry.carbs:
    print(f"   Carbs: {entry.carbs}")
if entry.estimated_calories:
    print(f"   Calories: ~{entry.estimated_calories}")
PYTHON_SCRIPT
`
