char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
a4e772a
main
1import { assert , assertEquals , assertStringIncludes } from "@std/assert" ; 2import { BACKGROUND_CONTEXT as context } from "@earendil-works/chord/context" ; 3import { getCurrentSystemPrompt } from "@earendil-works/pi-ai/utils/transcript" ; 4import { fauxAssistantMessage , fauxToolCall } from "@earendil-works/pi-ai/providers/faux" ; 5import { rootedEnvironment } from "@berry/api/testing.ts" ; 6import { tempDir } from "@berry/util" ; 7import { skillsExtension } from "../extensions/skills/mod.ts" ; 8import { hostEnvironment , writeSkill } from "../extensions/skills/testing.ts" ; 9import { lastToolResult , setup , toolsOffered , turn } from "./fixture.ts" ; 10 11Deno . test ( "skill snapshots reach the next request and survive compaction, reload, and historical forks" , async () => { 12await usingroot = await tempDir (); 13const env = rootedEnvironment ( root . path ); 14const skills = skillsExtension ( hostEnvironment ( root . path )); 15const body = 16"Review the primary evidence verbatim: ζ exact spacing.\nNever skip the release checklist.\n" ; 17await writeSkill ( env , "/home/.agents/skills" , "release" , body ); 18await usingharness = await setup ({ 19open :( name , cwd ) => 20Promise . resolve ( Object . assign ( rootedEnvironment ( root . path , { cwd :cwd ?? "/" }), { name})), 21close :() => Promise . resolve (), 22}); 23const { berry, model, faux} = harness ; 24await berry . install ( skills ); 25const tid = await berry . create ({ extensions :{ environment :{ cwd :"/" } }, model}); 26const conversation = ( await berry . conversation ( tid )) ! ; 27const [ before , after ] = await turn ( harness , tid , [ 28fauxAssistantMessage ( fauxToolCall ( "load_skill" , { name :"release" }), { 29stopReason :"toolUse" , 30}), 31]); 32assert ( toolsOffered ( before ). includes ( "load_skill" )); 33assert ( ! getCurrentSystemPrompt ( before ). includes ( body )); 34assertStringIncludes ( getCurrentSystemPrompt ( after ), body ); 35assert ( ! lastToolResult ( after ). text . includes ( body )); 36const loadedAt = 37( await conversation . entries ({ order :"descending" }, 1 , undefined , context )). items [ 0 ]. id ; 38 39await writeSkill ( env , "/home/.agents/skills" , "release" , "Changed on disk." ); 40faux . setResponses ([ fauxAssistantMessage ( "done" )]); 41await ( await conversation . submit ({ type :"input" , content :"x" . repeat ( 100_000 ) }, context )). wait ( 42context , 43); 44await conversation . waitForIdle ( context ); 45faux . setResponses ([ fauxAssistantMessage ( "A deliberately lossy summary." )]); 46await berry . harness . waitForTask ( await conversation . compact ( undefined , context ), context ); 47await berry . install ( skills ); 48const [ compacted ] = await turn ( harness , tid , []); 49assertStringIncludes ( getCurrentSystemPrompt ( compacted ), body ); 50assert ( ! getCurrentSystemPrompt ( compacted ). includes ( "Changed on disk." )); 51 52const calls = faux . state . callCount ; 53await berry . command ( tid , "unskill" , "release" ); 54assertEquals ( faux . state . callCount , calls ); 55const [ unloaded ] = await turn ( harness , tid , []); 56assert ( ! getCurrentSystemPrompt ( unloaded ). includes ( body )); 57 58const fork = await conversation . fork ( loadedAt , { ownership :{ kind :"ownerless" } }, context ); 59const [ forked ] = await turn ( harness , await berry . tidOf ( fork . id ), []); 60assertStringIncludes ( getCurrentSystemPrompt ( forked ), body ); 61await berry . branch ( tid , loadedAt ); 62const [ rewound ] = await turn ( harness , tid , []); 63assertStringIncludes ( getCurrentSystemPrompt ( rewound ), body ); 64}); 65 66Deno . test ( "subagents discover environment-local skills without inheriting their parent's active instructions" , async () => { 67await usingroot = await tempDir (); 68const env = rootedEnvironment ( root . path ); 69const skills = skillsExtension ( hostEnvironment ( root . path )); 70const body = "Parent-only instructions: carefully audit the publication process." ; 71await writeSkill ( env , "/home/.agents/skills" , "release" , body ); 72await usingharness = await setup ({ 73open :( name , cwd ) => 74Promise . resolve ( Object . assign ( rootedEnvironment ( root . path , { cwd :cwd ?? "/" }), { name})), 75close :() => Promise . resolve (), 76}); 77const { berry, faux, model} = harness ; 78await berry . install ( skills ); 79const tid = await berry . create ({ 80extensions :{ environment :{ cwd :"/" }, subagent :{} }, 81 model, 82}); 83await berry . command ( tid , "skill" , "release" ); 84let childPrompt :string | undefined ; 85faux . setResponses ( Array . from ({ length :4 }, () => ( request ) => { 86const last = request . messages . findLast (( message ) => message . role !== "system" ); 87if ( last ?. role === "user" && last . content === "go" ) { 88assertStringIncludes ( getCurrentSystemPrompt ( request . messages ), body ); 89return fauxAssistantMessage ( fauxToolCall ( "subagent" , { task :"A separate check." , model}), { 90stopReason :"toolUse" , 91}); 92} 93if ( last ?. role === "user" ) childPrompt = getCurrentSystemPrompt ( request . messages ); 94return fauxAssistantMessage ( "done" ); 95})); 96const conversation = ( await berry . conversation ( tid )) ! ; 97await ( await conversation . submit ({ type :"input" , content :"go" }, context )). wait ( context ); 98await conversation . waitForIdle ( context ); 99assert ( childPrompt !== undefined ); 100assertStringIncludes ( childPrompt , '"name":"release"' ); 101assert ( ! childPrompt . includes ( body )); 102});