char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
2c01ad9
main
1import { assertEquals , assertStringIncludes } from "@std/assert" ; 2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context" ; 3import type { Message } from "@earendil-works/pi-ai" ; 4import { fauxAssistantMessage } from "@earendil-works/pi-ai/providers/faux" ; 5import { until } from "@berry/util" ; 6import misc from "../extensions/misc/mod.ts" ; 7import { setup , turn } from "./fixture.ts" ; 8 9const textOf = ( messages :readonly Message []) => 10messages . flatMap (( message ) => 11typeof message . content === "string" 12 ?[ message . content ] 13 :message . content . flatMap (( block ) => block . type === "text" ?[ block . text ] :[]) 14). join ( "\n" ); 15 16Deno . test ( "/compact compacts the conversation, guided by its arguments" , async () => { 17await usingharness = await setup (); 18const { berry, faux, model} = harness ; 19await berry . install ( misc ); 20const tid = await berry . create ({ extensions :{}, model}); 21const conversation = ( await berry . conversation ( tid )) ! ; 22await turn ( harness , tid , []); 23faux . setResponses ([ fauxAssistantMessage ( "done" )]); 24await ( await conversation . submit ({ type :"input" , content :"x" . repeat ( 100_000 ) }, context )) 25. wait ( context ); 26await conversation . waitForIdle ( context ); 27 28let summarized :readonly Message [] = []; 29faux . setResponses ([( request ) => { 30summarized = request . messages ; 31return fauxAssistantMessage ( "A summary" ); 32}]); 33assertEquals ( await berry . command ( tid , "compact" , "keep the long input" ), "Compacting context…" ); 34await until ( async () => 35( await conversation . entries ({ order :"ascending" }, 100 , undefined , context )). items 36. some (( entry ) => entry . kind === "pi.compaction" ) 37); 38assertStringIncludes ( textOf ( summarized ), "Additional focus: keep the long input" ); 39});