#! /usr/bin/env nix-shell #! nix-shell --keep --pure -i runghc #! nix-shell --keep --pure -p cabal-install cacert curl git #! nix-shell --keep --pure -p '(haskell.packages.ghc9103.extend (self: super: { agent = self.callHackageDirect { pkg = "A-gent"; ver = "0.11.0.21"; sha256 = "im7CYRUqS8JbxI5YIS5Gd1vLd6P4JyZ/gTcwICzEA58=";} {}; qcsil = self.callHackageDirect { pkg = "quickcheck-silent"; ver = "0.11.0.17"; sha256 = "+NZXy8hwf13WsQ6PbKzzpFHBP0yA6pcS7oZnfe5FmRc=";} { QuickCheck = haskell.packages.ghc9103.QuickCheck_2_18_0_0;};})).ghcWithPackages (ps: with ps; [ agent qcsil ])' {-# OPTIONS_GHC -Wall -Werror -fno-warn-orphans #-} {-# OPTIONS_GHC -frefinement-level-hole-fits=8 #-} {-# LANGUAGE NoGeneralizedNewtypeDeriving #-} {-# LANGUAGE Safe #-} {-# LANGUAGE LambdaCase #-} -------------------------------------------------------------------------------- -- -- Λ-gent, (c) 2026 SPISE MISU ApS, https://spdx.org/licenses/SSPL-1.0 -- -------------------------------------------------------------------------------- import Prelude hiding ( error, lines, mod ) import Data.Either ( partitionEithers ) import qualified Agent.IO.Effects as EFF import Agent.IO.Restricted ( RIO ) import qualified Agent.IO.Restricted as RIO import Agent.LLM ( Context (Context, mode) , Eval , Mode (Auto, Hone) , replWithMode ) import qualified Agent.LLM.Action as ACT import qualified Agent.LLM.Message as MSG eval :: Eval () eval ctx msg = case ctx of Context { mode = Auto } -> demo ctx msg Context { mode = Hone } -> demo ctx msg _______________________ -> return (ctx, ACT.text err) where mod = mode ctx err = show mod ++ " mode is not available for this agent" demo :: ( EFF.LlmRepoAtom rio -- , EFF.LlmRepoTail rio , EFF.LlmRepoDesc rio , EFF.LlmRepoDiff rio , EFF.LlmRepoDisp rio , EFF.LlmRepoMeld rio , EFF.LlmRepoPull rio -- , EFF.LlmSpecConf rio , EFF.LlmSpecTest rio -- , EFF.LlmHoneRead rio , EFF.LlmHoneSave rio , EFF.LlmHonePost rio ) => Context () -> MSG.Message -> rio (Context (), ACT.Action) demo ctx msg = case msg of MSG.Atom txt fs -> \ case Right o -> ( ctx , ACT.text o ) Left e -> ( ctx , ACT.text e ) <$> EFF.llmHonePut ctx txt fs MSG.Fill (Just afps) -> mapM EFF.llmHoneGet afps >>= \ ecfs -> case partitionEithers ecfs of ( [ ], cfs ) -> return ( ctx , ACT.files cfs ) ( errs, ___ ) -> return ( ctx , (ACT.text . unlines) errs ) MSG.List mfil -> EFF.llmHoneSeq mfil >>= \ case Right fps -> return ( ctx , ACT.paths fps ) Left errs -> return ( ctx , (ACT.text . unlines) errs ) MSG.Path _ Nothing -> return ( ctx , ACT.text "Index is out of bounds" ) MSG.Path _ (Just afp) -> EFF.llmHoneGet afp >>= \ case Right f -> return ( ctx , ACT.file f ) Left e -> return ( ctx , ACT.text e ) MSG.Repo -> EFF.llmRepoBrs >>= \ case Right bs -> return ( ctx , ACT.branches bs ) Left errs -> return ( ctx , (ACT.text . unlines) errs ) MSG.Root -> EFF.llmPathCWD >>= \ case Just root -> return ( ctx , ACT.root root ) Nothing -> return ( ctx , ACT.none ) MSG.Send jsons -> mapM EFF.llmHoneWeb jsons >>= \ eres -> case partitionEithers eres of ( [ ], res ) -> return ( ctx , (ACT.text . unlines) res ) ( errs, ___ ) -> return ( ctx , (ACT.text . unlines) errs ) MSG.Tail -> EFF.llmRepoGet >>= \ case Right b -> return ( ctx , ACT.branch b ) Left err -> return ( ctx , ACT.text err ) MSG.Desc uid lab -> EFF.llmRepoLab uid lab >>= \ case Right txt -> return ( ctx , ACT.text txt ) Left err -> return ( ctx , ACT.text err ) MSG.Diff uid -> EFF.llmRepoCmp uid >>= \ case Right ls -> return ( ctx , (ACT.text . unlines) ls ) Left err -> return ( ctx , ACT.text err ) MSG.Disp -> EFF.llmRepoRem Nothing >>= \ case Right ls -> return ( ctx , (ACT.text . unlines) ls ) Left err -> return ( ctx , ACT.text err ) MSG.Meld -> EFF.llmRepoAdd >>= \ case Right ls -> return ( ctx , (ACT.text . unlines) ls ) Left err -> return ( ctx , ACT.text err ) MSG.Push -> EFF.llmRepoReq >>= \ case Right ls -> return ( ctx , (ACT.text . unlines) ls ) Left err -> return ( ctx , ACT.text err ) MSG.Pull -> EFF.llmRepoTug >>= \ case Right ls -> return ( ctx , (ACT.text . unlines) ls ) Left err -> return ( ctx , ACT.text err ) MSG.Shed -> EFF.llmRepoDel >>= \ case Right ls -> return ( ctx , (ACT.text . unlines) ls ) Left err -> return ( ctx , ACT.text err ) MSG.Test uid -> EFF.llmSpecRun uid >>= \ case Right tcs -> return ( ctx , ACT.tests tcs ) Left err -> return ( ctx , ACT.text err ) ________ -> return ( ctx , ACT.text $ "The following message '" ++ show msg ++ "', is not supported" ) main :: IO () main = replWithMode Hone eval instance EFF.LlmConf RIO where llmPathCWD = RIO.llmPathCWD instance EFF.LlmRepoRoot RIO where llmRepoDir = RIO.llmRepoDir instance EFF.LlmRepoAtom RIO where llmRepoBrs = RIO.llmRepoBrs instance EFF.LlmRepoTail RIO where llmRepoGet = RIO.llmRepoGet instance EFF.LlmRepoDesc RIO where llmRepoLab = RIO.llmRepoLab instance EFF.LlmRepoDiff RIO where llmRepoCmp = RIO.llmRepoCmp instance EFF.LlmRepoDisp RIO where llmRepoRem = RIO.llmRepoRem instance EFF.LlmRepoMeld RIO where llmRepoAdd = RIO.llmRepoAdd instance EFF.LlmRepoPull RIO where llmRepoReq = RIO.llmRepoReq llmRepoTug = RIO.llmRepoTug llmRepoDel = RIO.llmRepoDel instance EFF.LlmCodeRoot RIO where llmCodeDir = RIO.llmCodeDir instance EFF.LlmCodeMask RIO where llmCodeMsk = RIO.llmCodeMsk instance EFF.LlmSpecConf RIO where llmSpecLib = pure "spec" llmSpecMod = pure "Spec" llmSpecFun = pure "suite" llmSpecDep = pure [ "fiblog" ] llmSpecOto = pure (Just 10) instance EFF.LlmSpecTest RIO where llmSpecRun = RIO.llmSpecRun instance EFF.LlmHoneRoot RIO where llmHoneDir = RIO.llmHoneDir instance EFF.LlmHoneMask RIO where llmHoneMsk = RIO.llmHoneMsk instance EFF.LlmHoneRead RIO where llmHoneSeq = RIO.llmHoneSeq llmHoneGet = RIO.llmHoneGet instance EFF.LlmHoneSave RIO where llmHonePut = RIO.llmHonePut instance EFF.LlmHoneConf RIO where llmHoneSOM = RIO.llmHoneSOM llmHoneKey = RIO.llmHoneKey instance EFF.LlmHonePost RIO where llmHoneWeb = RIO.llmHoneWeb