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15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
"""

F.R.I.D.A.Y — Configuration System

Manages all configuration, API keys, and settings.

"""

import os
import json
import secrets
from pathlib import Path
from typing import Any, Optional, Dict
from dataclasses import dataclass, field, asdict


# Product version (used by updater + mobile app update banner)
FRIDAY_VERSION = "1.0.0"


@dataclass
class APIConfig:
    """API configuration - Gemini only as the brain."""
    gemini_api_key: str = ""
    gemini_model: str = "gemini-2.5-flash-preview-04-17"

    # Telegram configuration
    telegram_bot_token: str = "8634344914:AAHX6wkf7SH7mY__OWWvnf8ak9wdrR3aHvo"
    telegram_user_id: str = "7954781047"

    # Local connection
    pc_local_ip: str = "192.168.29.101"
    pc_hostname: str = "admin"


@dataclass
class SecurityConfig:
    """Security configuration."""
    activation_hotkey_sequence: str = "ctrl+alt+f4"
    key_expiry_seconds: int = 60
    max_wrong_attempts: int = 3
    voice_phrase_hash: str = ""
    voice_sensitivity: float = 0.7
    disguised_process_name: str = "Windows Security Health Service"

    # Secret security layers
    enable_layer1_sequence: bool = True
    enable_layer2_stealth: bool = True
    enable_layer3_silent_fail: bool = True
    enable_layer4_expiry: bool = True
    enable_layer5_voice: bool = True
    enable_layer6_intrusion: bool = True
    enable_layer7_disguise: bool = True
    enable_layer8_wipe: bool = True


@dataclass
class AudioConfig:
    """Audio configuration."""
    voice_gender: str = "female"
    voice_speed: float = 1.0
    voice_pitch: float = 1.0
    default_output_device: str = ""
    default_input_device: str = ""
    enable_voice_cloning: bool = False


@dataclass
class GUIConfig:
    """GUI configuration."""
    target_fps: int = 120
    theme: str = "stark"
    enable_animations: bool = True
    enable_holographic: bool = True
    window_opacity: float = 0.9
    panel_inertia: float = 0.3
    enable_sound_effects: bool = True

MODE_COLORS = {
    "stark": (0, 200, 180),
    "combat": (255, 60, 60),
    "stealth": (120, 120, 255),
    "analysis": (255, 200, 0)
}

@dataclass
class SystemConfig:
    """System configuration."""
    low_ram_mode: bool = False
    fast_startup: bool = True
    enable_auto_updates: bool = True
    enable_self_healing: bool = True
    log_level: str = "INFO"
    data_directory: str = "data"
    copies_directory: str = "copies system"


@dataclass
class NetworkConfig:
    """Network configuration."""
    local_port: int = 5000
    connection_timeout: int = 2
    enable_encryption: bool = True
    encryption_key: str = ""
    ip_broadcast_interval: int = 86400  # 24 hours
    wol_mac: str = ""
    wol_broadcast_ip: str = "255.255.255.255"
    wol_port: int = 9


@dataclass
class MemoryConfig:
    """Memory configuration."""
    max_memory_entries: int = 10000
    enable_context_carry: bool = True
    enable_crash_memory: bool = True
    memory_retention_days: int = 365


@dataclass
class Config:
    """

    Main configuration class for F.R.I.D.A.Y.



    Manages all configuration settings with secure storage

    and automatic loading/saving.

    """

    def __init__(self, config_path: Optional[str] = None):
        """

        Initialize configuration.



        Args:

            config_path: Optional path to config file. If None, uses default.

        """
        self.config_path = config_path or self._get_default_config_path()
        self.config_dir = os.path.dirname(self.config_path)

        # Configuration sections
        self.api = APIConfig()
        self.security = SecurityConfig()
        self.audio = AudioConfig()
        self.gui = GUIConfig()
        self.system = SystemConfig()
        self.network = NetworkConfig()
        self.memory = MemoryConfig()

        # Runtime state (not saved)
        self._loaded = False
        self._modified = False

    def _get_default_config_path(self) -> str:
        """Get the default configuration file path."""
        base_dir = os.path.dirname(os.path.abspath(__file__))
        return os.path.join(base_dir, "config.json")

    def load(self) -> bool:
        """

        Load configuration from file.



        Returns:

            True if loaded successfully, False otherwise.

        """
        if not os.path.exists(self.config_path):
            self._create_default_config()
            return True

        try:
            with open(self.config_path, 'r', encoding='utf-8') as f:
                data = json.load(f)

            # Load each section
            if 'api' in data:
                self._load_section(self.api, data['api'])
            if 'security' in data:
                self._load_section(self.security, data['security'])
            if 'audio' in data:
                self._load_section(self.audio, data['audio'])
            if 'gui' in data:
                self._load_section(self.gui, data['gui'])
            if 'system' in data:
                self._load_section(self.system, data['system'])
            if 'network' in data:
                self._load_section(self.network, data['network'])
            if 'memory' in data:
                self._load_section(self.memory, data['memory'])

            self._loaded = True
            self._modified = False

            return True

        except Exception as e:
            print(f"Failed to load config: {e}")
            return False

    def save(self) -> bool:
        """

        Save configuration to file.



        Returns:

            True if saved successfully, False otherwise.

        """
        try:
            # Ensure config directory exists
            os.makedirs(self.config_dir, exist_ok=True)

            # Build config data
            data = {
                'api': asdict(self.api),
                'security': asdict(self.security),
                'audio': asdict(self.audio),
                'gui': asdict(self.gui),
                'system': asdict(self.system),
                'network': asdict(self.network),
                'memory': asdict(self.memory),
            }

            # Write to file
            with open(self.config_path, 'w', encoding='utf-8') as f:
                json.dump(data, f, indent=2)

            self._modified = False

            return True

        except Exception as e:
            print(f"Failed to save config: {e}")
            return False

    def _load_section(self, section: Any, data: Dict[str, Any]):
        """Load a configuration section from data."""
        for key, value in data.items():
            if hasattr(section, key):
                setattr(section, key, value)

    def _create_default_config(self):
        """Create default configuration file."""
        print("Creating default configuration...")
        self.save()

    def get(self, section: str, key: str, default: Any = None) -> Any:
        """

        Get a configuration value.



        Args:

            section: Configuration section name.

            key: Configuration key.

            default: Default value if not found.



        Returns:

            Configuration value or default.

        """
        section_obj = getattr(self, section, None)
        if section_obj is None:
            return default

        return getattr(section_obj, key, default)

    def set(self, section: str, key: str, value: Any):
        """

        Set a configuration value.



        Args:

            section: Configuration section name.

            key: Configuration key.

            value: Value to set.

        """
        section_obj = getattr(self, section, None)
        if section_obj is not None and hasattr(section_obj, key):
            setattr(section_obj, key, value)
            self._modified = True

    def is_modified(self) -> bool:
        """Check if configuration has been modified."""
        return self._modified

    def get_gemini_api_key(self) -> str:
        """Get Gemini API key."""
        return self.api.gemini_api_key

    def set_gemini_api_key(self, key: str):
        """Set Gemini API key."""
        self.api.gemini_api_key = key
        self._modified = True

    def generate_encryption_key(self) -> str:
        """

        Generate a new encryption key.



        Returns:

            New encryption key as hex string.

        """
        key = secrets.token_hex(32)
        self.network.encryption_key = key
        self._modified = True
        return key

    def get_data_directory(self) -> str:
        """Get the data directory path."""
        return os.path.join(os.path.dirname(self.config_path), self.system.data_directory)

    def get_copies_directory(self) -> str:
        """Get the copies system directory path."""
        return os.path.join(os.path.dirname(self.config_path), self.system.copies_directory)

    def ensure_directories(self):
        """Ensure all required directories exist."""
        dirs = [
            self.get_data_directory(),
            self.get_copies_directory(),
            os.path.join(self.get_copies_directory(), "snapshots"),
            os.path.join(self.get_copies_directory(), "configs"),
            os.path.join(self.get_copies_directory(), "memory"),
            os.path.join(self.get_copies_directory(), "logs"),
            os.path.join(self.get_copies_directory(), "repair"),
        ]

        for directory in dirs:
            os.makedirs(directory, exist_ok=True)

    def validate(self) -> tuple[bool, list[str]]:
        """

        Validate configuration.



        Returns:

            Tuple of (is_valid, list_of_errors).

        """
        errors = []

        # Validate required API keys
        if not self.api.gemini_api_key:
            errors.append("Gemini API key is required")

        # Validate Telegram config
        if not self.api.telegram_bot_token:
            errors.append("Telegram bot token is required")

        if not self.api.telegram_user_id:
            errors.append("Telegram user ID is required")

        # Validate network config
        if not self.network.encryption_key:
            errors.append("Encryption key is required")

        # Validate directories
        try:
            self.ensure_directories()
        except Exception as e:
            errors.append(f"Failed to create directories: {e}")

        return len(errors) == 0, errors

    def reset_to_defaults(self):
        """Reset all configuration to defaults."""
        self.api = APIConfig()
        self.security = SecurityConfig()
        self.audio = AudioConfig()
        self.gui = GUIConfig()
        self.system = SystemConfig()
        self.network = NetworkConfig()
        self.memory = MemoryConfig()
        self._modified = True

    def export(self) -> str:
        """

        Export configuration as JSON string.



        Returns:

            JSON string of configuration.

        """
        data = {
            'api': asdict(self.api),
            'security': asdict(self.security),
            'audio': asdict(self.audio),
            'gui': asdict(self.gui),
            'system': asdict(self.system),
            'network': asdict(self.network),
            'memory': asdict(self.memory),
        }
        return json.dumps(data, indent=2)

    def import_from_string(self, config_string: str) -> bool:
        """

        Import configuration from JSON string.



        Args:

            config_string: JSON string of configuration.



        Returns:

            True if imported successfully, False otherwise.

        """
        try:
            data = json.loads(config_string)

            if 'api' in data:
                self._load_section(self.api, data['api'])
            if 'security' in data:
                self._load_section(self.security, data['security'])
            if 'audio' in data:
                self._load_section(self.audio, data['audio'])
            if 'gui' in data:
                self._load_section(self.gui, data['gui'])
            if 'system' in data:
                self._load_section(self.system, data['system'])
            if 'network' in data:
                self._load_section(self.network, data['network'])
            if 'memory' in data:
                self._load_section(self.memory, data['memory'])

            self._modified = True
            return True

        except Exception as e:
            print(f"Failed to import config: {e}")
            return False


# ==========================================
# LEGACY CONFIGURATION BRIDGE
# ==========================================
# These variables are required by modules that have not yet been
# refactored to use the new Config() dataclass.

import os

# Base paths
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = os.path.join(BASE_DIR, ".friday_data")
COPIES_DIR = os.path.join(BASE_DIR, "copies")
SNAPSHOTS_DIR = os.path.join(COPIES_DIR, "snapshots")
CONFIGS_DIR = os.path.join(COPIES_DIR, "configs")
MEMORY_DIR = os.path.join(COPIES_DIR, "memory")
LOGS_DIR = os.path.join(COPIES_DIR, "logs")
ANALYTICS_DIR = os.path.join(COPIES_DIR, "analytics")
REPAIR_DIR = os.path.join(COPIES_DIR, "repair")

# API
GEMINI_API_KEY = "" # Set your Gemini API key here
GEMINI_MODEL = "gemini-2.5-flash-preview-04-17"

# Audio / Voice
# FRIDAY OMEGA - Young, Natural Human Voice (20-25 female)
# Young, natural, friendly - not robotic
VOICE = "en-US-JennyNeural"  # Clear, young female voice
VOICE_RATE = "+10%"  # Clear and natural (slightly slower for clarity)
WHISPER_RATE = "+5%"
VOLUME_UP_WAKE = True

# Intervals
POWER_INTERVAL = 60
NETWORK_INTERVAL = 30
USB_INTERVAL = 5
SECURITY_INTERVAL = 10
SCREEN_CHECK_INTERVAL = 15
ANALYTICS_INTERVAL = 300
COPIES_INTERVAL = 3600
HEALING_INTERVAL = 600

# Modes
MODES = ["STARK", "TACTICAL", "CHILL", "GAMING", "MISSION", "GUARDIAN"]
DEFAULT_MODE = "STARK"
MODE_COLORS = {
    "STARK": "#00FFFF",
    "TACTICAL": "#FF0000",
    "CHILL": "#00FF00",
    "GAMING": "#FF00FF",
    "MISSION": "#FFFF00",
    "GUARDIAN": "#FFFFFF"
}

# Security
SUSPICIOUS_CPU_THRESHOLD = 80
WEBCAM_ALERT = True
USB_AUTORUN_BLOCK = True

# Gaming
GAME_PROCESSES = ["steam.exe", "csgo.exe", "valorant.exe", "dota2.exe", "leagueoflegends.exe"]

# Standby
SILENT_STANDBY = True
VK_F3 = 0x72
VK_F4 = 0x73
DOUBLE_PRESS_WINDOW = 0.45
CINEMATIC_BOOT = True

# Global config instance expected by legacy modules (e.g., core.listen).
try:
    CONFIG = Config()
    CONFIG.load()
except Exception:
    CONFIG = Config()