char-slop/berry
multipurpose self-modifiable agentic harness
git clone https://git.t4t.associates/char-slop/berry
6276dba
main
1export type Workspace = { environment :string ; cwd :string ; platform :string }; 2export type Project = { name :string ; roots :Workspace []; defaultRoot :number }; 3export type ProjectInput = { 4name :string ; 5roots :{ environment :string ; cwd :string }[]; 6defaultRoot :number ; 7moveConversations ?:boolean ; 8}; 9export type ProjectIndex = Record < string , Project >; 10 11export function workspacePath ( path :string , platform :string ) :string { 12const normalized = platform === "win32" ?path . replaceAll ( "\\" , "/" ). toLowerCase () :path ; 13return normalized . replace ( / \/+$ / u , "" ) || "/" ; 14} 15 16/** The most specific workspace of this project containing the directory. */ 17export function workspaceFor ( 18project :Project , 19binding :{ environment :string ; cwd :string } | undefined , 20) :Workspace | null { 21if ( ! binding ) return null ; 22let match :Workspace | null = null ; 23let specificity = - 1 ; 24for ( const root of project . roots ) { 25if ( root . environment !== binding . environment ) continue ; 26const path = workspacePath ( binding . cwd , root . platform ); 27const base = workspacePath ( root . cwd , root . platform ); 28if ( 29( path === base || path . startsWith ( base === "/" ?"/" :base + "/" )) && 30base . length > specificity 31) { 32match = root ; 33specificity = base . length ; 34} 35} 36return match ; 37} 38 39/** The most specific workspace containing this directory, independent of fork ancestry. */ 40export function projectFor ( 41projects :ProjectIndex , 42binding :{ environment :string ; cwd :string } | undefined , 43) :string | null { 44if ( ! binding ) return null ; 45let match :string | null = null ; 46let specificity = - 1 ; 47for ( const [ id , project ] of Object . entries ( projects )) { 48const root = workspaceFor ( project , binding ); 49if ( ! root ) continue ; 50const length = workspacePath ( root . cwd , root . platform ). length ; 51if ( length > specificity ) { 52match = id ; 53specificity = length ; 54} 55} 56return match ; 57}