"""
World Model - Track state and predict consequences
"""

from datetime import datetime

class WorldModel:
    def __init__(self):
        self.state = {
            "project_phase": "Phase 1",
            "capabilities": ["tools", "memory", "autonomy"],
            "last_updated": datetime.now().isoformat()
        }
        self.history = []
    
    def update_state(self, key, value):
        """Update world state"""
        old_value = self.state.get(key)
        self.state[key] = value
        self.state["last_updated"] = datetime.now().isoformat()
        
        self.history.append({
            "key": key,
            "old": old_value,
            "new": value,
            "timestamp": self.state["last_updated"]
        })
        
        return True
    
    def predict_consequence(self, action):
        """Predict what will happen"""
        predictions = {
            "add_capability": "Increase autonomy, require safety review",
            "complete_phase": "Move to next phase, unlock new abilities",
            "create_file": "Add to project, logged in git"
        }
        return predictions.get(action, "Unknown consequence")
    
    def get_state(self):
        return self.state

if __name__ == "__main__":
    wm = WorldModel()
    print("Current state:", wm.get_state())
    wm.update_state("project_phase", "Phase 2")
    print("Updated state:", wm.get_state())
    print("Prediction:", wm.predict_consequence("complete_phase"))
