Skip to content

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

648 B
Raw Blame
import * as Path from '@effect/platform/Path';
import { Effect } from 'effect';

/**
 * Walk up from a directory to the filesystem root, collecting all ancestor paths.
 * Returns an array starting with the resolved `cwd` and ending at the root.
 */
export const getAncestors = (cwd: string): Effect.Effect<string[], never, Path.Path> =>
  Effect.map(Path.Path, path => {
    const resolved = path.resolve(cwd);
    const dirs = [resolved];
    let current = resolved;

    while (true) {
      const parent = path.dirname(current);
      if (parent === current) break;
      dirs.push(parent);
      current = parent;
    }

    return dirs;
  });