{"version":3,"file":"presetConfig-D7f96RMV.cjs","names":["path","localPackageName","splitPackageSpecifier","os","readPoConfigSources","path","getOrThrow","readTextIfExists","nodeHost","readPoConfigSourcesAsync"],"sources":["../src/services/presetConfig/core.ts","../src/services/presetConfig/sync.ts","../src/services/presetConfig/index.ts"],"sourcesContent":["import path from 'node:path';\n\nimport type { ConfigDiagnostic } from '../../types/config';\nimport { PO_DIR, type PoConfigProvenance, type PoConfigSource } from '../layeredConfig';\n\nexport type LayerPackageConfig = Record<string, unknown>;\n\n/** One package selected by a layer, plus configuration owned by that package. */\nexport interface LayerPackage {\n  name: string;\n  optional?: boolean;\n  config?: LayerPackageConfig;\n}\n\n/** One configured package found while walking selected layers in order. */\nexport interface ResolvedPackageConfiguration {\n  layer: string;\n  specifier: string;\n  config: LayerPackageConfig;\n  baseDirectory: string;\n  filePath?: string;\n}\n\nexport interface LayerDefinition {\n  /**\n   * Po built-in names, or Pi-compatible local extension paths.\n   * Bare names resolve from Po's own extension entries. Paths beginning\n   * with `./` or `../`, plus absolute paths, resolve against the config that\n   * declares the layer and may name a script file or extension directory.\n   */\n  extensions?: string[];\n  /**\n   * npm specifiers, or local package paths retained for compatibility.\n   * Relative paths resolve against the repository root for `.po/presets.yaml`\n   * and against the global `.po` directory for\n   * `~/.po/presets.yaml`.\n   */\n  packages?: Array<string | LayerPackage>;\n  /** Legacy configuration accepted for compatibility, with no runtime effect. */\n  hookGroups?: string[];\n}\n\n/** A layer plus the root its relative extension and package paths resolve against. */\nexport interface ResolvedLayerDefinition extends LayerDefinition {\n  baseDirectory: string;\n  /** Absolute path of the presets file that declared this layer. */\n  filePath?: string;\n}\n\nexport interface PresetDefinition {\n  /** Human-readable purpose used by pickers and agent-facing catalogs. */\n  description: string;\n  /** Ordered layer names activated by this preset. */\n  layers: string[];\n}\n\nexport interface PresetsConfig {\n  /** Unconditional package bundle loaded before packages from selected named layers. */\n  default?: ResolvedLayerDefinition;\n  layers: Record<string, ResolvedLayerDefinition>;\n  /** The preset selected when neither a flag nor the environment names one. */\n  defaultPreset: string;\n  /** Source that last declared the default, absent for the built-in fallback. */\n  defaultPresetSource?: PoConfigProvenance;\n  /** Named presets, including their purpose and ordered layers. */\n  preset: Record<string, PresetDefinition>;\n  /** Declaring source for each surviving named preset. */\n  presetSources?: Record<string, PoConfigProvenance>;\n}\n\nexport interface LayerResolvers {\n  ownEntry: (name: string) => string;\n  packageEntry: (name: string) => string;\n  optionalPackageEntry: (name: string) => string | undefined;\n  /** Resolves every standard package.json pi.extensions entry for a package root. */\n  packageEntries?: (name: string) => string[];\n  /** Optional counterpart to packageEntries. */\n  optionalPackageEntries?: (name: string) => string[] | undefined;\n  /** Resolves one path-style layer entry against the config that declared it. */\n  localEntry: (specifier: string, baseDirectory: string) => string | undefined;\n  /** Resolves every Pi extension entry contributed by a local file or directory. */\n  localEntries?: (specifier: string, baseDirectory: string) => string[] | undefined;\n}\n\n/**\n * The npm package name a layer package specifier stands for, or undefined when\n * it names none. Injected because answering it for a local path reads that\n * directory's package.json, which `moduleResolution` does on Node and a\n * precomputed composition answers on the edge.\n */\nexport type PackageNameResolver = (specifier: string, baseDirectory: string) => string | undefined;\n\nexport interface PresetsDocument {\n  default?: unknown;\n  layers?: unknown;\n  defaultPreset?: unknown;\n  preset?: unknown;\n}\n\nexport const PRESETS_FILE = 'presets.yaml';\nconst FALLBACK_PRESET = 'copilot';\nconst PRESETS_RELATIVE_PATH = path.join(PO_DIR, PRESETS_FILE);\nconst RELATIVE_PREFIXES = ['./', '../'] as const;\nconst DEFAULT_KEYS = ['packages'] as const;\n/** Keys the presets file used before the rename, refused even by a lenient load. */\nconst RETIRED_PRESET_KEYS = [\n  'majorMode', // retired-name\n  'defaultMajorMode', // retired-name\n] as const;\n\nfunction assertNoRetiredPresetKeys(source: PoConfigSource<PresetsDocument>): void {\n  if (!RETIRED_PRESET_KEYS.some((key) => Object.hasOwn(source.document, key))) return;\n  throw new Error(\n    `${source.filePath}: majorMode was renamed to preset (defaultMajorMode to defaultPreset).`, // retired-name\n  );\n}\n\n/**\n * Whether a layer value names a path rather than a built-in or installed package.\n *\n * The same rule Node applies to import specifiers, so a bare name is always a\n * logical name and a path always looks like one.\n */\nexport function isLocalPackageSpecifier(specifier: string): boolean {\n  return path.isAbsolute(specifier) || RELATIVE_PREFIXES.some((prefix) => specifier.startsWith(prefix));\n}\nconst LAYER_PACKAGE_KEYS = ['name', 'optional', 'config'] as const;\nconst PRESET_KEYS = ['description', 'layers'] as const;\nconst LAYER_KEYS = ['extensions', 'packages', 'hookGroups'] as const;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Where a lenient load collects unknown keys instead of throwing.\n *\n * Same shape as the sink in configPolicy, for the same reason: `assertKnownKeys`\n * is the only reader and the whole composition is synchronous.\n */\nlet unknownKeySink: ConfigDiagnostic[] | undefined;\n\nfunction assertKnownKeys(value: Record<string, unknown>, keys: readonly string[], location: string): void {\n  const unsupported = Object.keys(value).filter((key) => !keys.includes(key));\n  if (unsupported.length === 0) return;\n  if (unknownKeySink !== undefined) {\n    for (const key of unsupported) {\n      unknownKeySink.push({\n        filePath: PRESETS_RELATIVE_PATH,\n        path: key,\n        message: `${location} has unsupported field`,\n      });\n    }\n    return;\n  }\n  throw new Error(`${location} has unsupported field(s): ${unsupported.join(', ')}`);\n}\n\n/** Retired package names and what replaces each. */\nconst RETIRED_PACKAGES: Readonly<Record<string, string>> = {\n  '@agimon-ai/po-loop': '@agimon-ai/po-calendar',\n  '@agimon-ai/po-major-mode': // retired-name\n    '@agimon-ai/po-preset',\n  '@agimon-ai/po-minor-mode': // retired-name\n    '@agimon-ai/po-mode',\n  '@agimon-ai/po-vibe-lint': // retired-name\n    '@agimon-ai/po-lint',\n};\nconst RETIRED_LOOP_PACKAGE = '@agimon-ai/po-loop';\n\nfunction assertNotRetired(name: string, location: string): void {\n  const retired = Object.keys(RETIRED_PACKAGES).find((key) => name === key || name.startsWith(`${key}@`));\n  if (retired === undefined) return;\n  const loopNote =\n    retired === RETIRED_LOOP_PACKAGE\n      ? ' Loops from the old package are not migrated; recreate them as Calendar events.'\n      : '';\n  throw new Error(`${location} uses the retired ${retired}. Replace it with ${RETIRED_PACKAGES[retired]}.${loopNote}`);\n}\n\nfunction parseLayerPackage(layerName: string, value: unknown, index: number): string | LayerPackage {\n  const location = `Layer \"${layerName}\" package[${index}] in ${PRESETS_RELATIVE_PATH}`;\n  if (typeof value === 'string') {\n    if (!value.trim()) throw new Error(`${location} must be a non-empty string or mapping`);\n    assertNotRetired(value.trim(), location);\n    return value.trim();\n  }\n  if (!isRecord(value)) throw new Error(`${location} must be a non-empty string or mapping`);\n  assertKnownKeys(value, LAYER_PACKAGE_KEYS, location);\n  if (typeof value.name !== 'string' || !value.name.trim()) {\n    throw new Error(`${location}.name must be a non-empty string`);\n  }\n  if (value.optional !== undefined && typeof value.optional !== 'boolean') {\n    throw new Error(`${location}.optional must be a boolean`);\n  }\n  if (value.config !== undefined && !isRecord(value.config)) {\n    throw new Error(`${location}.config must be a mapping`);\n  }\n  assertNotRetired(value.name.trim(), location);\n  return {\n    name: value.name.trim(),\n    ...(value.optional === true ? { optional: true } : {}),\n    ...(value.config ? { config: { ...value.config } } : {}),\n  };\n}\n\nfunction parseLayerExtensions(layerName: string, value: unknown): string[] | undefined {\n  if (value === undefined) return undefined;\n  const location = `Layer \"${layerName}\" extensions in ${PRESETS_RELATIVE_PATH}`;\n  if (!Array.isArray(value)) throw new Error(`${location} must be an array`);\n  return value.map((entry, index) => {\n    if (typeof entry !== 'string' || !entry.trim()) {\n      throw new Error(`${location}[${index}] must be a non-empty string`);\n    }\n    return entry.trim();\n  });\n}\n\nfunction parseLayerPackages(layerName: string, value: unknown): Array<string | LayerPackage> | undefined {\n  if (value === undefined) return undefined;\n  if (!Array.isArray(value)) {\n    throw new Error(`Layer \"${layerName}\" packages in ${PRESETS_RELATIVE_PATH} must be an array`);\n  }\n  return value.map((entry, index) => parseLayerPackage(layerName, entry, index));\n}\n\nfunction parseDefaultPreset(value: unknown): string {\n  if (typeof value !== 'string' || !value.trim()) {\n    throw new Error(`defaultPreset in ${PRESETS_RELATIVE_PATH} must be a non-empty string`);\n  }\n  return value.trim();\n}\n\nfunction parsePresetLayers(presetName: string, value: unknown): string[] {\n  const location = `Preset \"${presetName}\" layers in ${PRESETS_RELATIVE_PATH}`;\n  if (!Array.isArray(value)) throw new Error(`${location} must be an array`);\n  return value.map((layerName, index) => {\n    if (typeof layerName !== 'string' || !layerName.trim()) {\n      throw new Error(`${location}[${index}] must be a non-empty string`);\n    }\n    return layerName.trim();\n  });\n}\n\nfunction legacyPresetDescription(layers: readonly string[]): string {\n  return layers.length > 0 ? `Uses layers: ${layers.join(', ')}.` : 'Uses Po Pi core extensions only.';\n}\n\nfunction parsePreset(name: string, value: unknown): PresetDefinition {\n  if (Array.isArray(value)) {\n    const layers = parsePresetLayers(name, value);\n    return { description: legacyPresetDescription(layers), layers };\n  }\n\n  const location = `Preset \"${name}\" in ${PRESETS_RELATIVE_PATH}`;\n  if (!isRecord(value)) throw new Error(`${location} must be a mapping with description and layers`);\n  assertKnownKeys(value, PRESET_KEYS, location);\n  if (typeof value.description !== 'string' || !value.description.trim()) {\n    throw new Error(`${location}.description must be a non-empty string`);\n  }\n  return {\n    description: value.description.trim(),\n    layers: parsePresetLayers(name, value.layers),\n  };\n}\n\nfunction parsePresets(value: unknown): Record<string, PresetDefinition | null> {\n  if (value === undefined) return {};\n  if (!isRecord(value)) throw new Error(`preset in ${PRESETS_RELATIVE_PATH} must be a mapping`);\n  return Object.fromEntries(\n    Object.entries(value).map(([name, definition]) => [\n      name,\n      definition === null ? null : parsePreset(name, definition),\n    ]),\n  );\n}\n\nexport function parseLayer(name: string, definition: unknown): LayerDefinition {\n  if (!isRecord(definition)) throw new Error(`Layer \"${name}\" in ${PRESETS_RELATIVE_PATH} must be a mapping`);\n  if ('targets' in definition) {\n    throw new Error(\n      `Layer \"${name}\" in ${PRESETS_RELATIVE_PATH} uses removed field \"targets\"; select availability through presets`,\n    );\n  }\n  if ('config' in definition) {\n    throw new Error(\n      `Layer \"${name}\" in ${PRESETS_RELATIVE_PATH} uses unsupported field \"config\"; move it under the package entry that owns it`,\n    );\n  }\n  assertKnownKeys(definition, LAYER_KEYS, `Layer \"${name}\" in ${PRESETS_RELATIVE_PATH}`);\n  const extensions = parseLayerExtensions(name, definition.extensions);\n  const packages = parseLayerPackages(name, definition.packages);\n  return {\n    ...definition,\n    ...(extensions === undefined ? {} : { extensions }),\n    ...(packages === undefined ? {} : { packages }),\n  } as LayerDefinition;\n}\n\nfunction parseLayers(value: unknown): Record<string, LayerDefinition | null> {\n  if (value === undefined) return {};\n  if (!isRecord(value)) throw new Error(`layers in ${PRESETS_RELATIVE_PATH} must be a mapping`);\n  return Object.fromEntries(\n    Object.entries(value).map(([name, definition]) => [\n      name,\n      definition === null ? null : parseLayer(name, definition),\n    ]),\n  );\n}\n\nfunction parseDefault(value: unknown): LayerDefinition {\n  const location = `default in ${PRESETS_RELATIVE_PATH}`;\n  if (!isRecord(value)) throw new Error(`${location} must be a mapping with packages`);\n  assertKnownKeys(value, DEFAULT_KEYS, location);\n  if (!Object.hasOwn(value, 'packages')) {\n    throw new Error(`Layer \"default\" packages in ${PRESETS_RELATIVE_PATH} must be an array`);\n  }\n  const packages = parseLayerPackages('default', value.packages);\n  return { packages };\n}\n\n/**\n * Folds the global and repository presets documents, lowest precedence first.\n *\n * The repository is read last, so it replaces a global layer or preset of\n * the same name. Layers keep the root they were declared under so that a\n * global layer naming `./extensions/x` still points beside the global config\n * once it is loaded from inside some other repository.\n */\nexport function composePresetsConfig(\n  sources: ReadonlyArray<PoConfigSource<PresetsDocument>>,\n  repoRoot: string,\n  environment: NodeJS.ProcessEnv,\n  resolvePackageName: PackageNameResolver,\n): PresetsConfig {\n  let defaultDefinition: ResolvedLayerDefinition | undefined;\n  const layers: Record<string, ResolvedLayerDefinition> = {};\n  const preset: Record<string, PresetDefinition> = {};\n  const presetSources: Record<string, PoConfigProvenance> = {};\n  let defaultPreset = FALLBACK_PRESET;\n  let defaultPresetSource: PoConfigProvenance | undefined;\n  let hasConfiguredDefault = false;\n  for (const source of sources) {\n    assertNoRetiredPresetKeys(source);\n    if (Object.hasOwn(source.document, 'default')) {\n      defaultDefinition = {\n        ...parseDefault(source.document.default),\n        baseDirectory: source.baseDirectory,\n        filePath: source.filePath,\n      };\n    }\n    for (const [name, definition] of Object.entries(parseLayers(source.document.layers))) {\n      if (definition === null) {\n        delete layers[name];\n        continue;\n      }\n      layers[name] = {\n        ...definition,\n        baseDirectory: source.baseDirectory,\n        filePath: source.filePath,\n      };\n    }\n    if (Object.hasOwn(source.document, 'defaultPreset')) {\n      defaultPreset = parseDefaultPreset(source.document.defaultPreset);\n      defaultPresetSource = { filePath: source.filePath, baseDirectory: source.baseDirectory };\n      hasConfiguredDefault = true;\n    }\n    for (const [name, definition] of Object.entries(parsePresets(source.document.preset))) {\n      if (definition === null) {\n        delete preset[name];\n        delete presetSources[name];\n        continue;\n      }\n      preset[name] = definition;\n      presetSources[name] = { filePath: source.filePath, baseDirectory: source.baseDirectory };\n    }\n  }\n\n  for (const [presetName, definition] of Object.entries(preset)) {\n    for (const name of definition.layers) {\n      if (!layers[name]) {\n        throw new Error(`Unknown layer \"${name}\" in preset.${presetName} of ${PRESETS_RELATIVE_PATH}`);\n      }\n    }\n  }\n  if (hasConfiguredDefault && !Object.hasOwn(preset, defaultPreset)) {\n    throw new Error(`Unknown default preset \"${defaultPreset}\" in ${PRESETS_RELATIVE_PATH}`);\n  }\n  if (environment.PO_DISTRIBUTION === 'desktop') {\n    const computerUsePackage = '@agimon-ai/po-computer-use';\n    const packages = defaultDefinition?.packages ?? [];\n    const hasComputerUse = packages.some((entry) => {\n      const specifier = typeof entry === 'string' ? entry : entry.name;\n      return resolvePackageName(specifier, defaultDefinition?.baseDirectory ?? repoRoot) === computerUsePackage;\n    });\n    if (!hasComputerUse) {\n      defaultDefinition = {\n        ...(defaultDefinition ?? { baseDirectory: repoRoot }),\n        packages: [...packages, computerUsePackage],\n      };\n    }\n  }\n  return {\n    ...(defaultDefinition ? { default: defaultDefinition } : {}),\n    layers,\n    defaultPreset,\n    ...(defaultPresetSource ? { defaultPresetSource } : {}),\n    preset,\n    presetSources,\n  };\n}\n\n/**\n * Finds configuration owned by one package while preserving layer and package order.\n * Pass a resolver to match local package paths by name without changing their specifiers.\n */\nexport function resolvePackageConfigurations(\n  config: PresetsConfig,\n  names: string[],\n  packageName: string,\n  resolvePackageName?: PackageNameResolver,\n): ResolvedPackageConfiguration[] {\n  const normalizedPackageName = packageName.trim();\n  if (!normalizedPackageName) throw new Error('Package name must be a non-empty string');\n  const configurations: ResolvedPackageConfiguration[] = [];\n  const definitions: Array<{ name: string; definition: ResolvedLayerDefinition }> = [];\n  if (config.default) definitions.push({ name: 'default', definition: config.default });\n  for (const name of names) {\n    const definition = config.layers[name];\n    if (!definition) throw new Error(`Unknown layer: ${name}`);\n    definitions.push({ name, definition });\n  }\n  for (const { name, definition } of definitions) {\n    for (const entry of definition.packages ?? []) {\n      if (typeof entry === 'string' || entry.config === undefined) continue;\n      const resolvedName = resolvePackageName?.(entry.name, definition.baseDirectory) ?? entry.name;\n      if (resolvedName !== normalizedPackageName && !resolvedName.startsWith(`${normalizedPackageName}/`)) continue;\n      configurations.push({\n        layer: name,\n        specifier: entry.name,\n        config: { ...entry.config },\n        baseDirectory: definition.baseDirectory,\n        ...(definition.filePath ? { filePath: definition.filePath } : {}),\n      });\n    }\n  }\n  return configurations;\n}\n\n/** Resolves one named preset into its configured layer components. */\nexport function resolveLayers(config: PresetsConfig, preset: string): string[] {\n  if (!Object.hasOwn(config.preset, preset)) {\n    throw new Error(`Unknown preset: ${preset}. Known presets: ${Object.keys(config.preset).sort().join(', ')}`);\n  }\n  return [...config.preset[preset]!.layers];\n}\n\nfunction resolveLocalEntries(\n  resolvers: LayerResolvers,\n  specifier: string,\n  baseDirectory: string,\n): string[] | undefined {\n  const resolved = resolvers.localEntries?.(specifier, baseDirectory);\n  if (resolved !== undefined) return resolved;\n  const single = resolvers.localEntry(specifier, baseDirectory);\n  return single ? [single] : undefined;\n}\n\n/** Resolves one layer's extension and package entries to absolute paths. */\nexport function layerEntries(config: PresetsConfig, name: string, resolvers: LayerResolvers): string[] {\n  const layer = config.layers[name];\n  if (!layer) throw new Error(`Unknown layer: ${name}`);\n  const entries: string[] = [];\n  for (const entry of layer.extensions ?? []) {\n    if (!isLocalPackageSpecifier(entry)) {\n      entries.push(resolvers.ownEntry(entry));\n      continue;\n    }\n    const resolved = resolveLocalEntries(resolvers, entry, layer.baseDirectory);\n    if (!resolved?.length) {\n      throw new Error(\n        `Layer \"${name}\" extension \"${entry}\" does not resolve under ${layer.baseDirectory}. ` +\n          'Point it at a Pi extension file or directory.',\n      );\n    }\n    entries.push(...resolved);\n  }\n  for (const entry of layer.packages ?? []) {\n    const specifier = typeof entry === 'string' ? entry : entry.name;\n    const optional = typeof entry === 'string' ? false : entry.optional === true;\n    if (isLocalPackageSpecifier(specifier)) {\n      const resolved = resolveLocalEntries(resolvers, specifier, layer.baseDirectory);\n      if (resolved?.length) entries.push(...resolved);\n      else if (!optional) {\n        throw new Error(\n          `Layer \"${name}\" package \"${specifier}\" does not resolve under ${layer.baseDirectory}. ` +\n            'Point it at an extension file, or a directory whose package.json declares pi.extensions.',\n        );\n      }\n      continue;\n    }\n    if (optional) {\n      let resolved = resolvers.optionalPackageEntries?.(specifier);\n      if (resolved === undefined) {\n        const single = resolvers.optionalPackageEntry(specifier);\n        resolved = single ? [single] : undefined;\n      }\n      if (resolved) entries.push(...resolved);\n      continue;\n    }\n    const resolved = resolvers.packageEntries?.(specifier) ?? [resolvers.packageEntry(specifier)];\n    if (resolved.length === 0) {\n      throw new Error(`Layer \"${name}\" package \"${specifier}\" declares no Pi extensions.`);\n    }\n    entries.push(...resolved);\n  }\n  return entries;\n}\n\n/** As `composePresetsConfig`, collecting unknown keys as diagnostics instead of throwing. */\nexport function composePresetsConfigLenient(\n  sources: ReadonlyArray<PoConfigSource<PresetsDocument>>,\n  repoRoot: string,\n  environment: NodeJS.ProcessEnv,\n  resolvePackageName: PackageNameResolver,\n): { config: PresetsConfig; diagnostics: ConfigDiagnostic[] } {\n  const diagnostics: ConfigDiagnostic[] = [];\n  const previous = unknownKeySink;\n  unknownKeySink = diagnostics;\n  try {\n    return { config: composePresetsConfig(sources, repoRoot, environment, resolvePackageName), diagnostics };\n  } finally {\n    unknownKeySink = previous;\n  }\n}\n","import os from 'node:os';\n\nimport { localPackageName, splitPackageSpecifier } from '@agimon-ai/po-core/moduleResolution';\n\nimport type { ConfigDiagnostic } from '../../types/config';\nimport { readPoConfigSources } from '../layeredConfig';\nimport {\n  PRESETS_FILE,\n  composePresetsConfig,\n  composePresetsConfigLenient,\n  isLocalPackageSpecifier,\n  type PresetsConfig,\n  type PresetsDocument,\n} from './core';\n\n/** Node's answer: a local path names the package its package.json declares. */\nfunction nodePackageName(specifier: string, baseDirectory: string): string | undefined {\n  return isLocalPackageSpecifier(specifier)\n    ? localPackageName(specifier, baseDirectory)\n    : splitPackageSpecifier(specifier).name;\n}\n\n/**\n * Reads layers and presets from the global and repository configs.\n *\n * The repository is read last, so it replaces a global layer or preset of\n * the same name. Layers keep the root they were declared under so that a\n * global layer naming `./extensions/x` still points beside the global config\n * once it is loaded from inside some other repository.\n *\n * @deprecated Node-only sync shim; use readPresetsConfig. Removed in M2.\n */\nexport function loadPresetsConfig(\n  repoRoot: string,\n  homeDirectory: string = os.homedir(),\n  environment: NodeJS.ProcessEnv = process.env,\n): PresetsConfig {\n  const sources = readPoConfigSources<PresetsDocument>(PRESETS_FILE, repoRoot, homeDirectory);\n  return composePresetsConfig(sources, repoRoot, environment, nodePackageName);\n}\n\n/**\n * Reads layers and presets, tolerating unknown keys.\n *\n * `po sync` uses this so a presets.yaml written against a different set of\n * layer packages cannot break a build. Every other caller keeps the strict\n * `loadPresetsConfig`, and `po doctor` still reports what was tolerated.\n *\n * @deprecated Node-only sync shim; use readPresetsConfigLenient. Removed in M2.\n */\nexport function loadPresetsConfigLenient(\n  repoRoot: string,\n  homeDirectory: string = os.homedir(),\n  environment: NodeJS.ProcessEnv = process.env,\n): { config: PresetsConfig; diagnostics: ConfigDiagnostic[] } {\n  const sources = readPoConfigSources<PresetsDocument>(PRESETS_FILE, repoRoot, homeDirectory);\n  return composePresetsConfigLenient(sources, repoRoot, environment, nodePackageName);\n}\n","import path from 'node:path';\n\nimport { getOrThrow, nodeHost, readTextIfExists, type FileSystem } from '@agimon-ai/po-core/platform';\n\nimport type { ConfigDiagnostic } from '../../types/config';\nimport { readPoConfigSourcesAsync, type PoConfigSource } from '../layeredConfig';\nimport {\n  PRESETS_FILE,\n  composePresetsConfig,\n  composePresetsConfigLenient,\n  isLocalPackageSpecifier,\n  resolvePackageConfigurations,\n  type PresetsConfig,\n  type PresetsDocument,\n  type PackageNameResolver,\n  type ResolvedPackageConfiguration,\n} from './core';\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\nconst PACKAGE_MANIFEST = 'package.json';\nconst SCOPE_PREFIX = '@';\n\nexport interface ReadPresetsConfigOptions {\n  /** Defaults to the host's home directory. */\n  readonly homeDirectory?: string;\n  /** Admitted environment for locating Po home and distribution overrides. Defaults to empty. */\n  readonly environment?: NodeJS.ProcessEnv;\n  /**\n   * Names the package a layer specifier stands for. Pass one built from a\n   * precomputed composition on the edge; by default local paths are answered\n   * from their package.json over `fs`.\n   */\n  readonly resolvePackageName?: PackageNameResolver;\n}\n\n/** `@scope/name/sub` to `@scope/name`, `name/sub` to `name`. */\nfunction bareSpecifierName(specifier: string): string {\n  const segments = specifier.split('/');\n  return segments.slice(0, specifier.startsWith(SCOPE_PREFIX) ? 2 : 1).join('/');\n}\n\nasync function localPackageNameAsync(\n  fs: FileSystem,\n  specifier: string,\n  baseDirectory: string,\n  context: IoContext,\n): Promise<string | undefined> {\n  const target = path.resolve(baseDirectory, specifier);\n  try {\n    const real = getOrThrow(await fs.canonicalPath(target, context));\n    if (getOrThrow(await fs.fileInfo(real, context)).kind !== 'directory') return undefined;\n    const text = await readTextIfExists(fs, path.join(target, PACKAGE_MANIFEST), context);\n    if (text === undefined) return undefined;\n    const manifest = JSON.parse(text) as { name?: unknown };\n    return typeof manifest.name === 'string' && manifest.name.trim() ? manifest.name.trim() : undefined;\n  } catch {\n    return undefined;\n  }\n}\n\n/**\n * Only the desktop distribution asks for package names, and only of the\n * `default` packages, so those are the local paths read ahead of the\n * synchronous composition.\n */\nasync function precomputedPackageNames(\n  fs: FileSystem,\n  sources: ReadonlyArray<PoConfigSource<PresetsDocument>>,\n  environment: NodeJS.ProcessEnv,\n  context: IoContext,\n): Promise<PackageNameResolver> {\n  const names = new Map<string, string | undefined>();\n  const key = (specifier: string, baseDirectory: string) => `${baseDirectory}\\0${specifier}`;\n  if (environment.PO_DISTRIBUTION === 'desktop') {\n    for (const source of sources) {\n      const packages = (source.document.default as { packages?: unknown } | undefined)?.packages;\n      if (!Array.isArray(packages)) continue;\n      for (const entry of packages) {\n        const raw = typeof entry === 'string' ? entry : (entry as { name?: unknown } | null)?.name;\n        if (typeof raw !== 'string' || !isLocalPackageSpecifier(raw.trim())) continue;\n        const specifier = raw.trim();\n        names.set(\n          key(specifier, source.baseDirectory),\n          await localPackageNameAsync(fs, specifier, source.baseDirectory, context),\n        );\n      }\n    }\n  }\n  return (specifier, baseDirectory) =>\n    isLocalPackageSpecifier(specifier) ? names.get(key(specifier, baseDirectory)) : bareSpecifierName(specifier);\n}\n\nasync function readPresetSources(\n  fs: FileSystem,\n  repoRoot: string,\n  context: IoContext,\n  options: ReadPresetsConfigOptions,\n): Promise<{\n  sources: Array<PoConfigSource<PresetsDocument>>;\n  environment: NodeJS.ProcessEnv;\n  resolvePackageName: PackageNameResolver;\n}> {\n  const homeDirectory = options.homeDirectory ?? nodeHost.homeDirectory();\n  const environment = options.environment ?? {};\n  const sources = await readPoConfigSourcesAsync<PresetsDocument>(\n    fs,\n    PRESETS_FILE,\n    repoRoot,\n    context,\n    homeDirectory,\n    environment,\n  );\n  const resolvePackageName =\n    options.resolvePackageName ?? (await precomputedPackageNames(fs, sources, environment, context));\n  return { sources, environment, resolvePackageName };\n}\n\n/** Reads layers and presets over a FileSystem; the same answer as `loadPresetsConfig`. */\nexport async function readPresetsConfig(\n  fs: FileSystem,\n  repoRoot: string,\n  context: IoContext,\n  options: ReadPresetsConfigOptions = {},\n): Promise<PresetsConfig> {\n  const { sources, environment, resolvePackageName } = await readPresetSources(fs, repoRoot, context, options);\n  return composePresetsConfig(sources, repoRoot, environment, resolvePackageName);\n}\n\n/** As `readPresetsConfig`, tolerating unknown keys and reporting them. */\nexport async function readPresetsConfigLenient(\n  fs: FileSystem,\n  repoRoot: string,\n  context: IoContext,\n  options: ReadPresetsConfigOptions = {},\n): Promise<{ config: PresetsConfig; diagnostics: ConfigDiagnostic[] }> {\n  const { sources, environment, resolvePackageName } = await readPresetSources(fs, repoRoot, context, options);\n  return composePresetsConfigLenient(sources, repoRoot, environment, resolvePackageName);\n}\n\n/**\n * Reads local package names over a FileSystem, then finds package-owned config.\n * Keeps the original specifiers, source directories, and default/selected-layer order.\n * Missing or invalid local manifests do not match a package name.\n */\nexport async function readPackageConfigurations(\n  fs: FileSystem,\n  config: PresetsConfig,\n  names: string[],\n  packageName: string,\n  context: IoContext,\n): Promise<ResolvedPackageConfiguration[]> {\n  const packageNames = new Map<string, string | undefined>();\n  const key = (specifier: string, baseDirectory: string) => `${baseDirectory}\\0${specifier}`;\n  for (const definition of [config.default, ...names.map((name) => config.layers[name])]) {\n    if (!definition) continue;\n    for (const entry of definition.packages ?? []) {\n      if (typeof entry === 'string' || entry.config === undefined || !isLocalPackageSpecifier(entry.name)) {\n        continue;\n      }\n      const entryKey = key(entry.name, definition.baseDirectory);\n      if (!packageNames.has(entryKey)) {\n        packageNames.set(entryKey, await localPackageNameAsync(fs, entry.name, definition.baseDirectory, context));\n      }\n    }\n  }\n  return resolvePackageConfigurations(config, names, packageName, (specifier, baseDirectory) =>\n    packageNames.get(key(specifier, baseDirectory)),\n  );\n}\n\nexport { isLocalPackageSpecifier, layerEntries, resolveLayers, resolvePackageConfigurations } from './core';\nexport type {\n  LayerDefinition,\n  LayerPackage,\n  LayerPackageConfig,\n  LayerResolvers,\n  PresetDefinition,\n  PresetsConfig,\n  PackageNameResolver,\n  ResolvedLayerDefinition,\n  ResolvedPackageConfiguration,\n} from './core';\nexport { loadPresetsConfig, loadPresetsConfigLenient } from './sync';\n"],"mappings":";;;;;;;;;AAmGA,MAAa,eAAe;AAC5B,MAAM,kBAAkB;AACxB,MAAM,wBAAwBA,UAAAA,QAAK,KAAA,OAAa,YAAY;AAC5D,MAAM,oBAAoB,CAAC,MAAM,KAAK;AACtC,MAAM,eAAe,CAAC,UAAU;;AAEhC,MAAM,sBAAsB,CAC1B,aACA,kBACF;AAEA,SAAS,0BAA0B,QAA+C;CAChF,IAAI,CAAC,oBAAoB,MAAM,QAAQ,OAAO,OAAO,OAAO,UAAU,GAAG,CAAC,GAAG;CAC7E,MAAM,IAAI,MACR,GAAG,OAAO,SAAS,uEACrB;AACF;;;;;;;AAQA,SAAgB,wBAAwB,WAA4B;CAClE,OAAOA,UAAAA,QAAK,WAAW,SAAS,KAAK,kBAAkB,MAAM,WAAW,UAAU,WAAW,MAAM,CAAC;AACtG;AACA,MAAM,qBAAqB;CAAC;CAAQ;CAAY;AAAQ;AACxD,MAAM,cAAc,CAAC,eAAe,QAAQ;AAC5C,MAAM,aAAa;CAAC;CAAc;CAAY;AAAY;AAE1D,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;;;;;;AAQA,IAAI;AAEJ,SAAS,gBAAgB,OAAgC,MAAyB,UAAwB;CACxG,MAAM,cAAc,OAAO,KAAK,KAAK,CAAC,CAAC,QAAQ,QAAQ,CAAC,KAAK,SAAS,GAAG,CAAC;C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