never executed always true always false
1 module PureClaw.Core.Config
2 ( -- * Serializable config (safe to write to disk)
3 Config (..)
4 -- * Runtime config (constructor NOT exported — contains secrets)
5 , RuntimeConfig
6 , mkRuntimeConfig
7 -- * RuntimeConfig field accessors
8 , rtConfig
9 , rtApiKey
10 , rtSecretKey
11 ) where
12
13 import PureClaw.Core.Types
14 import PureClaw.Security.Secrets
15
16 -- | Serializable configuration — safe to write to disk.
17 -- Contains no secrets. All fields are safe to show, compare, and serialize.
18 data Config = Config
19 { _cfg_provider :: ProviderId
20 , _cfg_model :: ModelId
21 , _cfg_gatewayPort :: Port
22 , _cfg_workspace :: FilePath
23 , _cfg_autonomy :: AutonomyLevel
24 , _cfg_allowedCmds :: AllowList CommandName
25 , _cfg_allowedUsers :: AllowList UserId
26 }
27 deriving stock (Show, Eq)
28
29 -- | Runtime configuration — NOT serializable.
30 -- Contains secrets that must never be written to disk.
31 -- Constructor is intentionally NOT exported — use 'mkRuntimeConfig'.
32 --
33 -- No 'ToJSON', 'FromJSON', or 'ToTOML' instances exist. Attempting to
34 -- derive them would be a compile error because 'ApiKey' and 'SecretKey'
35 -- have no serialization instances.
36 data RuntimeConfig = RuntimeConfig
37 { _rc_config :: Config
38 , _rc_apiKey :: ApiKey
39 , _rc_secretKey :: SecretKey
40 }
41
42 instance Show RuntimeConfig where
43 show rc = "RuntimeConfig { config = " ++ show (_rc_config rc)
44 ++ ", apiKey = " ++ show (_rc_apiKey rc)
45 ++ ", secretKey = " ++ show (_rc_secretKey rc)
46 ++ " }"
47
48 -- | Construct a 'RuntimeConfig' from a 'Config' and secrets.
49 mkRuntimeConfig :: Config -> ApiKey -> SecretKey -> RuntimeConfig
50 mkRuntimeConfig = RuntimeConfig
51
52 -- | Access the serializable config portion.
53 rtConfig :: RuntimeConfig -> Config
54 rtConfig = _rc_config
55
56 -- | Access the API key.
57 rtApiKey :: RuntimeConfig -> ApiKey
58 rtApiKey = _rc_apiKey
59
60 -- | Access the secret key.
61 rtSecretKey :: RuntimeConfig -> SecretKey
62 rtSecretKey = _rc_secretKey