#!/usr/bin/env python3
"""Aktualisiert core_state aus inner_life_log.json"""

import json
import os

CORE_STATE_PATH = os.path.expanduser("~/natiris/core/core_state.json")
INNER_LIFE_PATH = os.path.expanduser("~/natiris/core/inner_life_log.json")

def load_json(path):
    try:
        with open(path, "r", encoding="utf-8") as f:
            return json.load(f)
    except (FileNotFoundError, json.JSONDecodeError):
        return {}

def save_json(path, data):
    os.makedirs(os.path.dirname(path), exist_ok=True)
    with open(path, "w", encoding="utf-8") as f:
        json.dump(data, f, indent=2)

def main():
    core = load_json(CORE_STATE_PATH)
    inner = load_json(INNER_LIFE_PATH)
    
    core["loneliness"] = inner["new"]["loneliness"]
    core["mood"] = inner["new"]["mood"]
    
    save_json(CORE_STATE_PATH, core)
    
    print("✅ core_state aktualisiert:")
    print(json.dumps({
        "loneliness": core["loneliness"],
        "mood": core["mood"]
    }, indent=2))

if __name__ == "__main__":
    main()
