char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
0853dde
main
1import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context" ; 2import type { Environment } from "@berry/api" ; 3 4/** An interactive shell on the target, preferring PowerShell 7 to Windows PowerShell. */ 5export async function shell ( env :Environment ) :Promise < string []> { 6if ( env . platform !== "win32" ) return [ env . variables . SHELL || "/bin/sh" , "-l" ]; 7 8const variables = Object . fromEntries ( 9Object . entries ( env . variables ). map (([ key , value ]) => [ key . toUpperCase (), value ]), 10); 11const onPath = ( name :string ) => 12( variables . PATH ?? "" ). split ( ";" ). filter ( Boolean ). flatMap (( dir ) => 13( variables . PATHEXT ?? ".EXE" ). split ( ";" ). filter ( Boolean ). map (( ext ) => [ 14dir . replace ( / ^"(.*)"$ / , "$1" ), 15name + ext , 16]) 17); 18const candidates = [ 19 ...onPath ( "pwsh" ), 20 ...[ variables . PROGRAMFILES , variables . PROGRAMW6432 ]. filter ( Boolean ). map (( dir ) => [ 21dir , 22"PowerShell" , 23"7" , 24"pwsh.exe" , 25]), 26 ...onPath ( "powershell" ), 27 ...( variables . SYSTEMROOT 28 ?[[ variables . SYSTEMROOT , "System32" , "WindowsPowerShell" , "v1.0" , "powershell.exe" ]] 29 :[]), 30]; 31for ( const parts of candidates ) { 32const path = await env . joinPath ( parts , BACKGROUND_CONTEXT ); 33if ( ! path . ok ) continue ; 34const info = await env . fileInfo ( path . value , BACKGROUND_CONTEXT ); 35if ( info . ok && info . value . kind !== "directory" ) return [ path . value , "-NoLogo" ]; 36} 37throw new Error ( "PowerShell not found. Install PowerShell 7 or add it to PATH." ); 38}