/** World paths and optional files shared by the core extensions. */ export async function optional(fs: any, path: string): Promise { try { return await fs.read(path) } catch (error) { if (error.code === 'not_found') return undefined; throw error } } export const parent = (path: string) => path.replace(/\/+$/, '').replace(/\/[^/]+$/, '') || '/' export async function repoRoot(fs: any, cwd: string): Promise { for (let at = cwd; ; at = parent(at)) { try { await fs.stat(`${at}/.git`); return at } catch (error) { if (error.code !== 'not_found') throw error } if (at === '/') return cwd } }