never executed always true always false
    1 module PureClaw.Agent.Env
    2   ( -- * Agent environment
    3     AgentEnv (..)
    4     -- * Message target
    5   , MessageTarget (..)
    6   ) where
    7 
    8 import Data.IORef
    9 import Data.Map.Strict (Map)
   10 import Data.Text (Text)
   11 
   12 import PureClaw.Agent.AgentDef (AgentDef)
   13 import PureClaw.Core.Types
   14 import PureClaw.Handles.Channel
   15 import PureClaw.Handles.Harness
   16 import PureClaw.Handles.Log
   17 import PureClaw.Handles.Transcript
   18 import PureClaw.Providers.Class
   19 import PureClaw.Security.Policy
   20 import PureClaw.Security.Vault
   21 import PureClaw.Security.Vault.Plugin
   22 import PureClaw.Session.Handle (SessionHandle)
   23 import PureClaw.Tools.Registry
   24 
   25 -- | Where incoming user messages are routed.
   26 data MessageTarget
   27   = TargetProvider          -- ^ Send to the configured LLM provider + model
   28   | TargetHarness Text      -- ^ Send to a named running harness
   29   deriving stock (Show, Eq)
   30 
   31 -- | All runtime dependencies for the agent loop, gathered into a single record.
   32 -- This replaces the multi-parameter signature of 'runAgentLoop' and
   33 -- 'executeSlashCommand', making it easy to add new capabilities (e.g.
   34 -- 'VaultHandle') in later work units without touching call sites.
   35 data AgentEnv = AgentEnv
   36   { _env_provider     :: IORef (Maybe SomeProvider)
   37     -- ^ The LLM provider. 'Nothing' when no credentials are configured yet.
   38   , _env_model        :: IORef ModelId
   39     -- ^ The model to use for completions. Mutable so slash commands
   40     -- like @\/provider@ and @\/target@ can hot-swap it.
   41   , _env_channel      :: ChannelHandle
   42     -- ^ The channel to read messages from and write responses to.
   43   , _env_logger       :: LogHandle
   44     -- ^ Structured logger for diagnostic output.
   45   , _env_systemPrompt :: Maybe Text
   46     -- ^ Optional system prompt prepended to every conversation.
   47   , _env_registry     :: ToolRegistry
   48     -- ^ All registered tools available for the agent to call.
   49   , _env_vault        :: IORef (Maybe VaultHandle)
   50     -- ^ Optional secrets vault. 'Nothing' if no vault is configured.
   51   , _env_pluginHandle :: PluginHandle
   52     -- ^ Handle for detecting and generating age plugin identities.
   53   , _env_transcript :: IORef (Maybe TranscriptHandle)
   54     -- ^ Optional transcript handle. When 'Just', the provider is wrapped
   55     -- with 'mkTranscriptProvider' to log all completions.
   56   , _env_policy :: SecurityPolicy
   57     -- ^ Security policy for command authorization. Needed by harness management.
   58   , _env_harnesses :: IORef (Map Text HarnessHandle)
   59     -- ^ Running harness handles, keyed by name (e.g. "claude-code").
   60   , _env_target :: IORef MessageTarget
   61     -- ^ Where incoming user messages are routed. Mutable so @\/target@
   62     -- can hot-swap the destination.
   63   , _env_nextWindowIdx :: IORef Int
   64     -- ^ Monotonically increasing counter for assigning tmux window indices
   65     -- to new harnesses. Starts at 0.
   66   , _env_agentDef :: Maybe AgentDef
   67     -- ^ Currently-selected agent, if any. Populated by the @--agent@ flag
   68     -- or the @default_agent@ config field. Used by agent-aware slash
   69     -- commands; 'Nothing' in the backward-compat no-agent path.
   70   , _env_session :: SessionHandle
   71     -- ^ Current conversation session. In WU1 this is always a no-op
   72     -- placeholder; WU2 promotes it to a real on-disk session.
   73   }