Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 21 lines 607 Bytes
Raw
1 import { Effect, Path } from 'effect';
2
3 /**
4 * Walk up from a directory to the filesystem root, collecting all ancestor paths.
5 * Returns an array starting with the resolved `cwd` and ending at the root.
6 */
7 export const getAncestors = (cwd: string): Effect.Effect<string[], never, Path.Path> =>
8 Effect.map(Path.Path, path => {
9 const resolved = path.resolve(cwd);
10 const dirs = [resolved];
11 let current = resolved;
12
13 while (true) {
14 const parent = path.dirname(current);
15 if (parent === current) break;
16 dirs.push(parent);
17 current = parent;
18 }
19
20 return dirs;
21 });