# Λ-gent with (Auto) Typed-Hole Development (ATHD) capabilities
#! /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 ])'
As we did in the previous examples from the chat, echo and code tabs, we add, on
the top of the file, the following header as that will allow us to run the code
as a script. Likewise, we also pin it (agent) to the latest version of
Λ-gent Hackage package.
To be able to execute a contextualized REPL for both retrieval of typed-holes related to a project as well as test of the hole replacements against a specification, we rely on cabal-install, the command-line interface for Cabal and Hackage.
Furthermore, we add a new pinned Hackage package (qcsil),
quickcheck-silent, a standalone library that allows us to
test as we normally do (QuickCheck), but without any I/O effects.
We add the exact code options and language features to ensure clean and
maintainable code as well as ensuring it ONLY executes safe-code, behaves nicely
and helps us define the script with Typed Holes Development (THD) in combination
with a LSP. We only add an extra LambdaCase pragma, as it will allows us to
simplify some pattern match cases:
> {-# OPTIONS_GHC -Wall -Werror -fno-warn-orphans #-}
>
> {-# OPTIONS_GHC -frefinement-level-hole-fits=1 #-}
>
> {-# LANGUAGE NoGeneralizedNewtypeDeriving #-}
> {-# LANGUAGE Safe #-}
>
> {-# LANGUAGE LambdaCase #-}
Licensing information as well as library imports:
> --------------------------------------------------------------------------------
> --
> -- Λ-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
You might notice that compared to the chat and code examples, we do not have
to define any (showable) data entities. As we have moved on from the traditional
(outdated/legacy?) LLM’s to System One Models (SOM) where the API is statically
fixed to our data representation of typed-holes.
We define and execute our logic. In this sample, we will ONLY handle the hone and auto modes and we will do so separately in order to limit effects:
> eval :: Eval ()
> eval ctx msg =
> case ctx of
> Context { mode = Auto } -> hone ctx msg
> Context { mode = Hone } -> hone ctx msg
> _______________________ -> return (ctx, ACT.text err)
> where
> mod = mode ctx
> err = show mod ++ " mode is not available for this agent"
For each message, with its corresponding action we are interested in supporting,
we will define their cases. We use a wildcard (_) for all the other we aren’t
going to use:
> hone
> ::
> ( 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)
> hone 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"
> )
We define the Λ-gent, to start in hone mode:
> main :: IO ()
> main =
> replWithMode Hone eval
And once again, we ONLY define effects (and dependencies) we are going to use.
> 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 = RIO.llmSpecLib
> llmSpecMod = RIO.llmSpecMod
> llmSpecFun = RIO.llmSpecFun
> llmSpecDep = RIO.llmSpecDep
> llmSpecOto = RIO.llmSpecOto
> 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
And that was it, as simple as that, you have created an Λ-gent that can help
you replace typed-holes in your code, in an automated way.
However, these modes (hone and auto) depend on scaffolding that MUST be provided
by the plan-mode (generate minimum code files with typed-holes aka “green”) as
well as the spec-mode (generating property-base test cases aka “red”) as in the
Test-Driven Development (TDD) mantra: “red/green/refactor”. These modes
(plan and spec) are not released yet as by doing so, they would be limited ONLY
to Haskell and hereby, lock-in Λ-gents to a single programming language, which
might not be ideal.
Note: Once again, by copying the text from above, except this note, and saving it to a
.lhsscript (*) file and converting it to an executable file withchmox +x hone.lhs, you now execute it like this:LLM_PATH_CWD="…" LLM_HONE_LOCALHOST_SOM="http://…:3000/v1" ./hone.lhsfrom a terminal.(*) - You MUST install the
nixpackage manager on your operating system for this script to work: https://nixos.org/download/
# Use case from executing the script
First refactoring step to make code files with typed-holes (“green”), so property-base test cases (“red”), become green as well:
# Exit Λ-gent with /e or /exit. For more commands, type /? or /help.
Λ-hone> /disc
0: src/Bar.hs:38:16
# Hole
(_ :: String)
# Description
- In an equation for ‘bar’: bar (Bar []) = _
1: src/Bar.hs:39:16
# Hole
(_ :: String)
# Description
- In an equation for ‘bar’: bar (Bar cs) = _
2: src/Foo.hs:38:15
# Hole
(_x :: Char Or perhaps ‘_x’ is mis-spelled, or not in scope)
# Description
- In an equation for ‘foo’: foo (Foo x) = _x
Λ-hone> /fill
# Fil/refine typed-holes
* Substitute the 'typed-hole' from src/Bar.hs at line 38 and column 16 with? (hint: 'mostLikely' value, if any)
- choice: []
- confidence: 0.9187
* Substitute the 'typed-hole' from src/Bar.hs at line 39 and column 16 with? (hint: 'mostLikely' value, if any)
- choice: cs
- confidence: 0.9153
> Used tokens: 790 and elapsed time (ms): 527.1
# Fil/refine typed-holes
* Substitute the 'typed-hole' from src/Foo.hs at line 38 and column 15 with? (hint: 'mostLikely' value, if any)
- choice: x
- confidence: 0.9801
> Used tokens: 446 and elapsed time (ms): 280.4
Λ-hone> /atom Substituted typed-holes in code
# Temporary worktree branch:
## Adding:
HEAD is now at 0ee89b0 TH
## Saving files:
* Ensuring folder exists:
src
* Writing file to folder:
src/Bar.hs
* Ensuring folder exists:
src
* Writing file to folder:
src/Foo.hs
## Adding files and committing :
[20261021-143554-353604535 3caa015] Substituted typed-holes in code
2 files changed, 3 insertions(+), 3 deletions(-)
## Removing:
Λ-hone> /repo
20261021-143554-353604535: [HONE] Substituted typed-holes in code
Λ-hone> /test 20261021-143554-353604535
# Test cases
* All succeeded .....: False
* All meldable ......: True
## Test.Foo.foo: wrap/unwrap
* Status ............: Success
* Result ............:
+++ OK, passed 100 tests.
## Test.Bar.bar: wrap/unwrap
* Status ............: Success
* Result ............:
+++ OK, passed 100 tests.
## Test.FooBar.foobar: wrap/unwrap
* Status ............: Failure
* Tests size ........: 1
* Tests performed ...: 0
* Result ............:
*** Failed! (after 1 test):
(Foo 'f',Bar "")
* Reason ............:
src/FooBar.hs:40:10: error: [GHC-88464]
• Found hole: _foo :: Char
Or perhaps ‘_foo’ is mis-spelled, or not in scope
• In the first argument of ‘FooBar’, namely ‘_foo’
In the expression: FooBar _foo _bar
In an equation for ‘foobar’: foobar f b = FooBar _foo _bar
• Relevant bindings include
b :: Bar
(bound at src/FooBar.hs:39:10)
f :: Foo
(bound at src/FooBar.hs:39:8)
foobar :: Foo -> Bar -> FooBar
(bound at src/FooBar.hs:39:1)
(deferred type error)
Λ-hone> /meld
Updating 0ee89b0..3caa015
Fast-forward
src/Bar.hs | 4 ++--
src/Foo.hs | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
Λ-hone> /disp
Deleted branch 20261021-143554-353604535 (was 3caa015).
Next refactoring step:
Λ-hone> /disc
0: src/FooBar.hs:40:10
# Hole
(_foo :: Char Or perhaps ‘_foo’ is mis-spelled, or not in scope)
# Description
- In the first argument of ‘FooBar’, namely ‘_foo’
- In the expression: FooBar _foo _bar
- In an equation for ‘foobar’: foobar f b = FooBar _foo _bar
1: src/FooBar.hs:40:15
# Hole
(_bar :: String Or perhaps ‘_bar’ is mis-spelled, or not in scope)
# Description
- In the second argument of ‘FooBar’, namely ‘_bar’
- In the expression: FooBar _foo _bar
- In an equation for ‘foobar’: foobar f b = FooBar _foo _bar
Λ-hone> /fill
# Fil/refine typed-holes
* Substitute the 'typed-hole' from src/FooBar.hs at line 40 and column 10 with? (hint: 'mostLikely' value, if any)
- choice: (foo (_ :: Foo))
- confidence: 0.9708
* Substitute the 'typed-hole' from src/FooBar.hs at line 40 and column 15 with? (hint: 'mostLikely' value, if any)
- choice: (bar (_ :: Bar))
- confidence: 0.9412
> Used tokens: 893 and elapsed time (ms): 568.3
Λ-hone> /atom Substituted typed-holes in code
# Temporary worktree branch:
## Adding:
HEAD is now at 3caa015 Substituted typed-holes in code
## Saving files:
* Ensuring folder exists:
src
* Writing file to folder:
src/FooBar.hs
## Adding files and committing :
[20261021-143842-248587828 83a12b9] Substituted typed-holes in code
1 file changed, 1 insertion(+), 1 deletion(-)
## Removing:
Λ-hone> /repo
20261021-143842-248587828: [HONE] Substituted typed-holes in code
Λ-hone> /test 20261021-143842-248587828
# Test cases
* All succeeded .....: False
* All meldable ......: True
## Test.FooBar.foobar: wrap/unwrap
* Status ............: Failure
* Tests size ........: 1
* Tests performed ...: 0
* Result ............:
*** Failed! (after 1 test):
(Foo 'f',Bar "")
* Reason ............:
src/FooBar.hs:40:16: error: [GHC-88464]
• Found hole: _ :: Foo
• In the first argument of ‘foo’, namely ‘(_ :: Foo)’
In the first argument of ‘FooBar’, namely ‘(foo (_ :: Foo))’
In the expression: FooBar (foo (_ :: Foo)) (bar (_ :: Bar))
• Relevant bindings include
b :: Bar
(bound at src/FooBar.hs:39:10)
f :: Foo
(bound at src/FooBar.hs:39:8)
foobar :: Foo -> Bar -> FooBar
(bound at src/FooBar.hs:39:1)
Valid hole fits include
f :: Foo
(bound at src/FooBar.hs:39:8)
(deferred type error)
Λ-hone> /meld
Updating 3caa015..83a12b9
Fast-forward
src/FooBar.hs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Λ-hone> /disp
Deleted branch 20261021-143842-248587828 (was 3caa015).
Last refactoring step:
Λ-hone> /disc
0: src/FooBar.hs:40:16
# Hole
(_ :: Foo)
# Description
- In the first argument of ‘foo’, namely ‘(_ :: Foo)’
- In the first argument of ‘FooBar’, namely ‘(foo (_ :: Foo))’
- In the expression: FooBar (foo (_ :: Foo)) (bar (_ :: Bar))
1: src/FooBar.hs:40:33
# Hole
(_ :: Bar)
# Description
- In the first argument of ‘bar’, namely ‘(_ :: Bar)’
- In the second argument of ‘FooBar’, namely ‘(bar (_ :: Bar))’
- In the expression: FooBar (foo (_ :: Foo)) (bar (_ :: Bar))
Λ-hone> /fill
# Fil/refine typed-holes
* Substitute the 'typed-hole' from src/FooBar.hs at line 40 and column 16 with? (hint: 'mostLikely' value, if any)
- choice: f
- confidence: 1.0
* Substitute the 'typed-hole' from src/FooBar.hs at line 40 and column 33 with? (hint: 'mostLikely' value, if any)
- choice: b
- confidence: 1.0
> Used tokens: 728 and elapsed time (ms): 481.0
Λ-hone> /atom Substituted typed-holes in code
# Temporary worktree branch:
## Adding:
HEAD is now at 83a12b9 Substituted typed-holes in code
## Saving files:
* Ensuring folder exists:
src
* Writing file to folder:
src/FooBar.hs
## Adding files and committing :
[20261021-144122-535222685 cc283e8] Substituted typed-holes in code
1 file changed, 1 insertion(+), 1 deletion(-)
## Removing:
Λ-hone> /repo
20261021-144122-535222685: [HONE] Substituted typed-holes in code
Λ-hone> /test 20261021-144122-535222685
# Test cases
* All succeeded .....: True
* All meldable ......: True
## Test.FooBar.foobar: wrap/unwrap
* Status ............: Success
* Result ............:
+++ OK, passed 1000 tests.
Λ-hone> /meld
Updating 83a12b9..cc283e8
Fast-forward
src/FooBar.hs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Λ-hone> /disp
Deleted branch 20261021-144122-535222685 (was cc283e8).
And now, we can see that all property-base test cases went from “red” to “green” as expected.
All the steps, and their repetitive substeps, could be automated by using the
/exec command in /mode auto. The automation can be stopped at any time by
typing the command /halt. If no more typed-holes are found in the code base
after several refactoring steps, the Λ-gent will /halt on it’s own:
…
Deleted branch 20261021-145957-607938268 (was 4151bca).
> NOTE: Type /halt to stop automated execution (timeout is: 3 seconds)
Λ-auto>
> Discover and fill/refine Typed-Holes
20261021-143259-174122_TL: [HONE] Local TAIL branch, based on origin/HEAD, as local storage
No files in pile
Request to wrap it up
Λ-auto>
Automation has successfully halted
Λ-auto>