{"version":3,"file":"index.mjs","names":["loadDoomConfig","loadSharedDoomConfig","loadDoomConfigLenient","loadSharedDoomConfigLenient"],"sources":["../../../src/composition/projectTrust/index.ts"],"sourcesContent":["import {\n  loadDoomConfig as loadSharedDoomConfig,\n  loadDoomConfigLenient as loadSharedDoomConfigLenient,\n} from '@agimon-ai/doompi-config/config';\nimport type { ConfigDiagnostic, DoomSelectionConfig, ProjectTrust } from '@agimon-ai/doompi-config/types';\n\nconst APPROVE_OPTION = '--approve';\nconst APPROVE_SHORT_OPTION = '-a';\nconst NO_APPROVE_OPTION = '--no-approve';\nconst NO_APPROVE_SHORT_OPTION = '-na';\nconst PROJECT_TRUST_ALWAYS: ProjectTrust = 'always';\nconst PROJECT_TRUST_NEVER: ProjectTrust = 'never';\n\nexport type { ProjectTrust };\n\nexport interface DoomConfig {\n  projectTrust: ProjectTrust;\n  /** The matrix the repository declares by default, read by `doom-pi sync`. */\n  selection?: DoomSelectionConfig;\n}\n\nexport function loadDoomConfig(repoRoot: string): DoomConfig {\n  const config = loadSharedDoomConfig(repoRoot);\n  return { projectTrust: config.projectTrust, selection: config.selection };\n}\n\n/**\n * Reads the config the way `doompi sync` needs it: an unknown key is reported\n * rather than fatal, so a config written for a different version cannot break\n * a build. `doompi doctor` runs the strict read above.\n */\nexport function loadDoomConfigLenient(\n  repoRoot: string,\n  homeDirectory?: string,\n): { config: DoomConfig; diagnostics: ConfigDiagnostic[] } {\n  const { config, diagnostics } = loadSharedDoomConfigLenient(repoRoot, homeDirectory);\n  return { config: { projectTrust: config.projectTrust, selection: config.selection }, diagnostics };\n}\n\nexport function hasProjectTrustOption(piArgs: string[]): boolean {\n  return piArgs.some((argument) =>\n    [APPROVE_OPTION, APPROVE_SHORT_OPTION, NO_APPROVE_OPTION, NO_APPROVE_SHORT_OPTION].includes(argument),\n  );\n}\n\nexport function applyProjectTrust(piArgs: string[], config: DoomConfig): string[] {\n  if (hasProjectTrustOption(piArgs)) {\n    return [...piArgs];\n  }\n  if (config.projectTrust === PROJECT_TRUST_ALWAYS) return [APPROVE_OPTION, ...piArgs];\n  if (config.projectTrust === PROJECT_TRUST_NEVER) return [NO_APPROVE_OPTION, ...piArgs];\n  return [...piArgs];\n}\n"],"mappings":";;AAMA,MAAM,iBAAiB;AACvB,MAAM,uBAAuB;AAC7B,MAAM,oBAAoB;AAC1B,MAAM,0BAA0B;AAChC,MAAM,uBAAqC;AAC3C,MAAM,sBAAoC;AAU1C,SAAgBA,iBAAe,UAA8B;CAC3D,MAAM,SAASC,eAAqB,QAAQ;CAC5C,OAAO;EAAE,cAAc,OAAO;EAAc,WAAW,OAAO;CAAU;AAC1E;;;;;;AAOA,SAAgBC,wBACd,UACA,eACyD;CACzD,MAAM,EAAE,QAAQ,gBAAgBC,sBAA4B,UAAU,aAAa;CACnF,OAAO;EAAE,QAAQ;GAAE,cAAc,OAAO;GAAc,WAAW,OAAO;EAAU;EAAG;CAAY;AACnG;AAEA,SAAgB,sBAAsB,QAA2B;CAC/D,OAAO,OAAO,MAAM,aAClB;EAAC;EAAgB;EAAsB;EAAmB;CAAuB,CAAC,CAAC,SAAS,QAAQ,CACtG;AACF;AAEA,SAAgB,kBAAkB,QAAkB,QAA8B;CAChF,IAAI,sBAAsB,MAAM,GAC9B,OAAO,CAAC,GAAG,MAAM;CAEnB,IAAI,OAAO,iBAAiB,sBAAsB,OAAO,CAAC,gBAAgB,GAAG,MAAM;CACnF,IAAI,OAAO,iBAAiB,qBAAqB,OAAO,CAAC,mBAAmB,GAAG,MAAM;CACrF,OAAO,CAAC,GAAG,MAAM;AACnB"}