never executed always true always false
1 module PureClaw.Core.Types
2 ( -- * Identity types
3 ProviderId (..)
4 , ModelId (..)
5 , Port (..)
6 , UserId (..)
7 , CommandName (..)
8 , ToolCallId (..)
9 , MemoryId (..)
10 -- * Workspace
11 , WorkspaceRoot (..)
12 -- * Autonomy
13 , AutonomyLevel (..)
14 -- * Allow-lists
15 , AllowList (..)
16 , isAllowed
17 ) where
18
19 import Data.Set (Set)
20 import Data.Set qualified as Set
21 import Data.Text (Text)
22 import GHC.Generics (Generic)
23
24 -- | Provider identifier (e.g. "anthropic", "openai")
25 newtype ProviderId = ProviderId { unProviderId :: Text }
26 deriving stock (Show, Eq, Ord, Generic)
27
28 -- | Model identifier (e.g. "claude-3-opus")
29 newtype ModelId = ModelId { unModelId :: Text }
30 deriving stock (Show, Eq, Ord, Generic)
31
32 -- | Network port number
33 newtype Port = Port { unPort :: Int }
34 deriving stock (Show, Eq, Ord, Generic)
35
36 -- | User identifier for allow-list matching
37 newtype UserId = UserId { unUserId :: Text }
38 deriving stock (Show, Eq, Ord, Generic)
39
40 -- | Command name for policy evaluation (e.g. "git", "ls")
41 newtype CommandName = CommandName { unCommandName :: Text }
42 deriving stock (Show, Eq, Ord, Generic)
43
44 -- | Tool call identifier from provider responses
45 newtype ToolCallId = ToolCallId { unToolCallId :: Text }
46 deriving stock (Show, Eq, Ord, Generic)
47
48 -- | Memory entry identifier
49 newtype MemoryId = MemoryId { unMemoryId :: Text }
50 deriving stock (Show, Eq, Ord, Generic)
51
52 -- | Workspace root directory — anchors all SafePath resolution
53 newtype WorkspaceRoot = WorkspaceRoot { unWorkspaceRoot :: FilePath }
54 deriving stock (Show, Eq, Ord, Generic)
55
56 -- | Agent autonomy level
57 data AutonomyLevel
58 = Full -- ^ Agent can act without confirmation
59 | Supervised -- ^ Agent must confirm before acting
60 | Deny -- ^ Agent cannot act at all
61 deriving stock (Show, Eq, Ord, Generic)
62
63 -- | Typed allow-list. @AllowAll@ explicitly opts in to allowing everything.
64 -- @AllowList s@ restricts to the given set.
65 data AllowList a
66 = AllowAll
67 | AllowList (Set a)
68 deriving stock (Show, Eq, Generic)
69
70 -- | Check whether a value is permitted by the allow-list.
71 isAllowed :: Ord a => AllowList a -> a -> Bool
72 isAllowed AllowAll _ = True
73 isAllowed (AllowList s) x = Set.member x s