Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

1.3 KB
Raw Blame

export function normalizePath(p: string): string {
  return p.replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/+$/, '').replace(/^\.\//, '');
}

export function isDirectChild(filePath: string, folderPath: string): boolean {
  const normFile = normalizePath(filePath);
  const normFolder = normalizePath(folderPath);

  if (normFile.startsWith(normFolder + '/')) {
    const remainder = normFile.slice(normFolder.length + 1);
    return !remainder.includes('/');
  }

  const folderSegments = normFolder.split('/');
  const fileSegments = normFile.split('/');

  if (fileSegments.length < 2) {
    return normFolder === '' || normFolder === '.';
  }

  const fileDir = fileSegments.slice(0, -1).join('/'); 
  const fileName = fileSegments[fileSegments.length - 1]; 

  // Tool evidence may be absolute while the caller names a project-relative folder.
  const absolutePath = /^([A-Za-z]:)?\//;
  if (!absolutePath.test(normFolder) && absolutePath.test(normFile)
      && normFolder !== '' && fileDir.endsWith('/' + normFolder)) {
    return fileName !== '';
  }

  if (normFolder.endsWith('/' + fileDir) || normFolder === fileDir) {
    return !fileName.includes('/');
  }

  for (let i = 0; i < folderSegments.length; i++) {
    const folderSuffix = folderSegments.slice(i).join('/');
    if (folderSuffix === fileDir) {
      return true;
    }
  }

  return false;
}