char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
be80d8a
main
1// Extension roots on disk for the loader's tests, and a berry loading them. 2 3import { join } from "node:path" ; 4import { createModels } from "@earendil-works/pi-ai/models" ; 5import { MemoryStorage } from "@earendil-works/pi-durable" ; 6import { tempDir } from "@berry/util" ; 7import { openBerry } from "./berry.ts" ; 8import { extensionLoader } from "./loader.ts" ; 9import { extensionWeb } from "./web.ts" ; 10 11/** An extension's source, whose description is its `VERSION`. */ 12export const extension = ( 13name :string , 14description = `import { VERSION } from "./version.ts";` , 15sortOrder ?:number , 16) => 17`import { defineExtension } from "@berry/api"; 18${ description } 19export default defineExtension({ name: ${ JSON . stringify ( name )} , description: VERSION, ${ 20sortOrder === undefined ? "" : `sortOrder: ${ sortOrder } , ` 21} initial: () => null, setup() {} }); 22` ; 23 24/** Write these files under `directory`. */ 25export async function put ( directory :string , files :Record < string , string >) { 26for ( const [ path , text ] of Object . entries ( files )) { 27await Deno . mkdir ( join ( directory , path , ".." ), { recursive :true }); 28await Deno . writeTextFile ( join ( directory , path ), text ); 29} 30} 31 32/** A berry root with the given extension files, inside the repo so that `deno check` finds its deno.json. */ 33export async function fixture ( files :Record < string , string >, run :( root :string ) => Promise < void >) { 34await usingrootDir = await tempDir ({ dir :Deno . cwd (), prefix :".loader-test-" }); 35const root = rootDir . path ; 36await put ( join ( root , "extensions" ), files ); 37await run ( root ); 38} 39 40/** A berry whose loader reads `root`, or these `directories`. */ 41export async function open ( root :string , directories ?:readonly string [], web = extensionWeb ()) { 42const berry = await openBerry ( new MemoryStorage (), createModels ()); 43const loader = extensionLoader ({ berry, web, root, directories}); 44const close = async () => { 45await loader . close (); 46await berry . close (); 47}; 48const describe = ( name :string ) => berry . extensions (). find (( e ) => e . name === name )?. description ; 49return { berry, loader, close, describe}; 50}