{"version":3,"file":"index.cjs","names":["path","fs","globalDoomConfigDirectory"],"sources":["../../../src/composition/repository/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { globalDoomConfigDirectory } from '@agimon-ai/doompi-config/config';\n\n/** Doom's own repository configuration directory. */\nconst DOOM_DIRECTORY = '.doom';\n/** Git's root marker, which may be a directory or a worktree pointer file. */\nconst GIT_DIRECTORY = '.git';\n/** A Pi project that has been configured, rather than any stray `.pi` folder. */\nconst PI_SETTINGS = path.join('.pi', 'settings.json');\n\nfunction isDirectory(target: string): boolean {\n  try {\n    return fs.statSync(target).isDirectory();\n  } catch {\n    return false;\n  }\n}\n\nfunction isFile(target: string): boolean {\n  try {\n    return fs.statSync(target).isFile();\n  } catch {\n    return false;\n  }\n}\n\n/**\n * True when a directory carries a marker Doom Pi is willing to treat as a root.\n *\n * Doom and Pi markers identify configured projects. A Git marker also counts so\n * personal configuration can be synchronized into a new checkout before it has\n * repository-local configuration. Build-tooling markers remain deliberately\n * excluded because they do not establish a repository boundary.\n */\nexport function isRepositoryRoot(directory: string): boolean {\n  const gitMarker = path.join(directory, GIT_DIRECTORY);\n  return (\n    isDirectory(path.join(directory, DOOM_DIRECTORY)) ||\n    isFile(path.join(directory, PI_SETTINGS)) ||\n    isDirectory(gitMarker) ||\n    isFile(gitMarker)\n  );\n}\n\n/**\n * Walks up from `start` looking for the repository root.\n *\n * The nearest marked ancestor wins, so a session started in a subdirectory\n * resolves to the repository that configured Doom rather than to a parent\n * checkout that happens to sit above it.\n */\nexport function findRepositoryRoot(start: string): string {\n  let directory = path.resolve(start);\n  while (true) {\n    if (isRepositoryRoot(directory)) return directory;\n    const parent = path.dirname(directory);\n    if (parent === directory) throw new Error(`Could not find repository root from ${start}`);\n    directory = parent;\n  }\n}\n\n/** Uses the nearest repository when one exists, otherwise the user's global Doom composition. */\nexport function resolveDoomConfigurationRoot(start: string, homeDirectory: string): string {\n  try {\n    return findRepositoryRoot(start);\n  } catch {\n    return globalDoomConfigDirectory(homeDirectory);\n  }\n}\n"],"mappings":";;;;;;;;AAMA,MAAM,iBAAiB;;AAEvB,MAAM,gBAAgB;;AAEtB,MAAM,cAAcA,UAAAA,QAAK,KAAK,OAAO,eAAe;AAEpD,SAAS,YAAY,QAAyB;CAC5C,IAAI;EACF,OAAOC,QAAAA,QAAG,SAAS,MAAM,CAAC,CAAC,YAAY;CACzC,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,OAAO,QAAyB;CACvC,IAAI;EACF,OAAOA,QAAAA,QAAG,SAAS,MAAM,CAAC,CAAC,OAAO;CACpC,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;;AAUA,SAAgB,iBAAiB,WAA4B;CAC3D,MAAM,YAAYD,UAAAA,QAAK,KAAK,WAAW,aAAa;CACpD,OACE,YAAYA,UAAAA,QAAK,KAAK,WAAW,cAAc,CAAC,KAChD,OAAOA,UAAAA,QAAK,KAAK,WAAW,WAAW,CAAC,KACxC,YAAY,SAAS,KACrB,OAAO,SAAS;AAEpB;;;;;;;;AASA,SAAgB,mBAAmB,OAAuB;CACxD,IAAI,YAAYA,UAAAA,QAAK,QAAQ,KAAK;CAClC,OAAO,MAAM;EACX,IAAI,iBAAiB,SAAS,GAAG,OAAO;EACxC,MAAM,SAASA,UAAAA,QAAK,QAAQ,SAAS;EACrC,IAAI,WAAW,WAAW,MAAM,IAAI,MAAM,uCAAuC,OAAO;EACxF,YAAY;CACd;AACF;;AAGA,SAAgB,6BAA6B,OAAe,eAA+B;CACzF,IAAI;EACF,OAAO,mBAAmB,KAAK;CACjC,QAAQ;EACN,QAAA,GAAOE,gCAAAA,0BAAAA,CAA0B,aAAa;CAChD;AACF"}