{"version":3,"file":"presets-CZml6U2q.mjs","names":[],"sources":["../src/services/presets/index.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport { isDeepStrictEqual } from 'node:util';\n\nimport {\n  BACKGROUND_CONTEXT,\n  getOrThrow,\n  readTextIfExists,\n  writeFileAtomic,\n  type FileSystem,\n} from '@agimon-ai/po-core/platform';\nimport { isMap, isScalar, isSeq, parseDocument } from 'yaml';\n\nimport type {\n  PresetCreateRequest,\n  PresetLayerRequest,\n  PresetOperation,\n  PresetReference,\n  PresetRenameRequest,\n  PresetWriteRequest,\n  SettingsPresetsView,\n  SettingsRepository,\n} from '../../types/settings';\nimport { globalPoConfigDirectory, readPoConfigLayers } from '../config';\nimport { retiredConfigError, retiredConfigSibling } from '../layeredConfig/core';\nimport {\n  composePresetsConfig,\n  parseLayer,\n  PRESETS_FILE,\n  type LayerPackage,\n  type PresetsConfig,\n  type PresetsDocument,\n} from '../presetConfig/core';\n\nconst io = BACKGROUND_CONTEXT;\n\n// Host-default fallback and workspace edits can reach the same file across mounts.\nlet writes: Promise<unknown> = Promise.resolve();\n\n/** Serialize settings writes and the marketplace's final clash check plus membership commit. */\nexport function withSettingsWrite<T>(action: () => Promise<T>): Promise<T> {\n  const result = writes.then(action);\n  // A rejected caller must not poison subsequent writes.\n  writes = result.catch(() => undefined);\n  return result;\n}\n\nfunction packageName(entry: string | LayerPackage): string {\n  return typeof entry === 'string' ? entry : entry.name;\n}\n\nfunction presetsFile(homeDirectory: string): string {\n  return path.join(globalPoConfigDirectory(homeDirectory, {}), PRESETS_FILE);\n}\n\n/** sha256 of the file's bytes, empty when absent, as `config/core` hashes `config.yaml`. */\nfunction hashOf(text: string | undefined): string {\n  return text === undefined ? '' : createHash('sha256').update(text, 'utf8').digest('hex');\n}\n\n/** Explicit file sources keep the preset API independent of ambient host configuration. */\nasync function presetsConfig(fs: FileSystem, home: string, environment: NodeJS.ProcessEnv, root?: string) {\n  const files = [presetsFile(home), ...(root ? [path.join(root, '.po', PRESETS_FILE)] : [])];\n  const sources = [];\n  for (const filePath of files) {\n    const retired = retiredConfigSibling(filePath);\n    if (retired !== undefined && (await readTextIfExists(fs, retired, io)) !== undefined)\n      throw retiredConfigError(retired);\n    const text = await readTextIfExists(fs, filePath, io);\n    if (text === undefined || !text.trim()) continue;\n    const document = parseDocument(text);\n    if (!document.errors.length && document.contents === null) continue;\n    if (document.errors.length || !isMap(document.contents)) throw new Error(`Invalid YAML in ${filePath}.`);\n    sources.push({\n      filePath,\n      baseDirectory: filePath === files[0] ? path.dirname(filePath) : root!,\n      text,\n      document: document.toJS() as PresetsDocument,\n    });\n  }\n  return composePresetsConfig(sources, root ?? home, environment, (specifier) =>\n    specifier\n      .replace(/@[^@/]+$/u, '')\n      .split('/')\n      .slice(0, specifier.startsWith('@') ? 2 : 1)\n      .join('/'),\n  );\n}\n\n/** Turning on in an inherited host default changes that preset at its source, not a shadow copy. */\nfunction defaultAddsToHost(config: PresetsConfig, home: string, file: string, root?: string): boolean {\n  const name = config.defaultPreset;\n  return (\n    !!root &&\n    config.presetSources?.[name]?.filePath === presetsFile(home) &&\n    config.defaultPresetSource?.filePath !== file\n  );\n}\n\n/** Effective presets, with the hash of the file owned by this mount. */\nexport async function readPresetsView(\n  fs: FileSystem,\n  homeDirectory: string,\n  environment: NodeJS.ProcessEnv,\n  root?: string,\n): Promise<SettingsPresetsView> {\n  const config = await presetsConfig(fs, homeDirectory, environment, root);\n  const file = root ? path.join(root, '.po', PRESETS_FILE) : presetsFile(homeDirectory);\n  const text = await readTextIfExists(fs, file, io);\n  const host = root ? await presetsConfig(fs, homeDirectory, environment) : undefined;\n  const view = {\n    defaultPreset: config.defaultPreset,\n    presets: Object.entries(config.preset).map(([name, definition]) => ({\n      name,\n      description: definition.description,\n      layers: definition.layers.map((layer) => ({\n        name: layer,\n        packages: (config.layers[layer]?.packages ?? []).map(packageName),\n      })),\n      ...(root ? { overridesHost: !!host?.preset[name] && config.presetSources?.[name]?.filePath === file } : {}),\n      ...(root && config.presetSources?.[name]?.filePath === presetsFile(homeDirectory) ? { inherited: true } : {}),\n    })),\n    alwaysIncluded: (config.default?.packages ?? []).map(packageName),\n    hash: hashOf(text),\n    ...(root ? { file, hostHash: hashOf(await readTextIfExists(fs, presetsFile(homeDirectory), io)) } : {}),\n  };\n  return { ...view, defaultHash: defaultAddsToHost(config, homeDirectory, file, root) ? view.hostHash! : view.hash };\n}\n\n/** Defaults and admitted repository selections that would break if a preset disappeared. */\nasync function referencesTo(\n  fs: FileSystem,\n  home: string,\n  environment: NodeJS.ProcessEnv,\n  file: string,\n  name: string,\n  repositories: readonly SettingsRepository[],\n  root?: string,\n): Promise<PresetReference[]> {\n  const references: PresetReference[] = [];\n  for (const repository of [\n    { path: undefined },\n    ...repositories,\n    ...(root && !repositories.some((repository) => repository.path === root) ? [{ path: root }] : []),\n  ]) {\n    const config = await presetsConfig(fs, home, environment, repository.path);\n    if (\n      config.presetSources?.[name]?.filePath !== file &&\n      !(root && repository.path === root && Object.hasOwn(config.preset, name))\n    )\n      continue;\n    if (config.defaultPreset === name && config.defaultPresetSource) {\n      const reference = { file: config.defaultPresetSource.filePath, key: 'defaultPreset' };\n      if (!references.some((entry) => entry.file === reference.file && entry.key === reference.key))\n        references.push(reference);\n    }\n    const layers = await readPoConfigLayers(fs, repository.path ?? home, io, { homeDirectory: home, environment });\n    if (layers.effective.selection?.preset === name) {\n      references.push({\n        file:\n          layers.originOf(['selection', 'preset']) === 'repository'\n            ? layers.repositoryFile.filePath\n            : layers.globalFile.filePath,\n        key: 'selection.preset',\n      });\n    }\n  }\n  return references.filter(\n    (entry, index) => references.findIndex((other) => other.file === entry.file && other.key === entry.key) === index,\n  );\n}\n\n/** One comment-preserving atomic edit, validated by the same composer as runtime loads. */\nexport async function writePreset(\n  fs: FileSystem,\n  home: string,\n  environment: NodeJS.ProcessEnv,\n  operation: PresetOperation,\n  input: PresetWriteRequest | PresetCreateRequest | PresetRenameRequest | PresetLayerRequest,\n  root?: string,\n  repositories: readonly SettingsRepository[] = [],\n): Promise<SettingsPresetsView | { error: string; conflict?: { hash: string }; references?: PresetReference[] }> {\n  let file = root ? path.join(root, '.po', PRESETS_FILE) : presetsFile(home);\n  let text = await readTextIfExists(fs, file, io);\n  const defaultAdd = operation === 'add-layer' && !input.name;\n  if (!defaultAdd && hashOf(text) !== input.expectedHash)\n    return { error: 'Your presets changed since this page loaded.', conflict: { hash: hashOf(text) } };\n  let config = await presetsConfig(fs, home, environment, root);\n  const name = input.name || config.defaultPreset;\n  // Turning on in an inherited host default changes that preset at its source, not a shadow copy.\n  if (operation === 'add-layer' && !input.name && defaultAddsToHost(config, home, file, root)) {\n    file = presetsFile(home);\n    text = await readTextIfExists(fs, file, io);\n    config = await presetsConfig(fs, home, environment);\n  }\n  const hash = hashOf(text);\n  if (hash !== input.expectedHash) return { error: 'Your presets changed since this page loaded.', conflict: { hash } };\n  // A missing file starts empty, not as `{}`: an empty flow map would make every later write one cramped line.\n  const document = parseDocument(text ?? '');\n  if (document.errors.length || (document.contents !== null && !isMap(document.contents)))\n    return { error: `Your ${PRESETS_FILE} could not be read as YAML.` };\n  // Deleting the last preset leaves `preset: {}`; the next preset should not inherit that flow style.\n  const emptied = document.get('preset', true);\n  if (isMap(emptied) && emptied.items.length === 0) emptied.flow = false;\n  const exists = Object.hasOwn(config.preset, name);\n  if (operation === 'create') {\n    if (document.getIn(['preset', name]) != null) return { error: `There is already a preset named ${name}.` };\n    const create = input as PresetCreateRequest;\n    document.setIn(['preset', name], { description: create.description, layers: create.layers ?? [] });\n  } else {\n    if (!exists) return { error: `There is no preset named ${name}.` };\n    if (operation === 'rename' || operation === 'delete') {\n      const references = await referencesTo(fs, home, environment, file, name, repositories, root);\n      if (references.length) return { error: `Preset ${name} is still referenced.`, references };\n      if (operation === 'rename') {\n        const newName = (input as PresetRenameRequest).newName;\n        if (Object.hasOwn(config.preset, newName) || document.hasIn(['preset', newName]))\n          return { error: `There is already a preset named ${newName}.` };\n        const modes = document.get('preset', true);\n        const pair = isMap(modes)\n          ? modes.items.find((entry) => isScalar(entry.key) && entry.key.value === name)\n          : undefined;\n        // Rename the key in place so its comments, anchors and position survive.\n        if (pair && isScalar(pair.key)) pair.key.value = newName;\n        else document.setIn(['preset', newName], config.preset[name]);\n      }\n      // A tombstone hides an inherited preset, and prevents a host preset from resurfacing.\n      if (root && (await presetsConfig(fs, home, environment)).preset[name]) document.setIn(['preset', name], null);\n      else if (operation === 'delete') document.deleteIn(['preset', name]);\n    } else if (operation === 'default') document.set('defaultPreset', name);\n    else {\n      const { layer, definition } = input as PresetLayerRequest;\n      if (operation === 'add-layer') {\n        const existing = config.layers[layer];\n        if (existing && definition) {\n          const { baseDirectory: _base, filePath: _file, ...value } = existing;\n          // The same packages are the same layer, whether listed by name or as mappings that carry options.\n          const named = (entry: typeof value) => ({ ...entry, packages: entry.packages?.map(packageName) });\n          if (!isDeepStrictEqual(named(value), named(parseLayer(layer, definition))))\n            return { error: `Layer ${layer} already has a conflicting definition.` };\n        }\n        if (!existing) {\n          if (!definition || document.hasIn(['layers', layer]))\n            return { error: `Layer ${layer} has no available definition.` };\n          document.setIn(['layers', layer], definition);\n        }\n      }\n      // The workspace's own copy of a host preset. As YAML nodes: a plain object set beside existing\n      // presets is not a node, so its layer list could not be found below.\n      if (!document.hasIn(['preset', name])) document.setIn(['preset', name], document.createNode(config.preset[name]));\n      const presetPath = ['preset', name];\n      const presetNode = document.getIn(presetPath, true);\n      const layersPath = isSeq(presetNode) ? presetPath : [...presetPath, 'layers'];\n      const layers = document.getIn(layersPath, true);\n      if (!isSeq(layers)) return { error: `Preset ${name} has no layer list.` };\n      const index = layers.items.findIndex((entry) => String(entry) === layer);\n      if (operation === 'add-layer' && index < 0) layers.add(layer);\n      if (operation === 'remove-layer') {\n        for (let index = layers.items.length - 1; index >= 0; index--) {\n          if (String(layers.items[index]) === layer) layers.delete(index);\n        }\n      }\n    }\n  }\n  await writeFileAtomic(fs, file, document.toString(), io);\n  try {\n    // Validate host edits against every admitted repository they might affect before accepting them.\n    await presetsConfig(fs, home, environment);\n    for (const repository of repositories) await presetsConfig(fs, home, environment, repository.path);\n    const view = await readPresetsView(fs, home, environment, root);\n    return { ...view, writtenFile: file };\n  } catch (error) {\n    if (text === undefined) getOrThrow(await fs.remove(file, { force: true }, io));\n    else await writeFileAtomic(fs, file, text, io);\n    return { error: `Po left ${PRESETS_FILE} as it was: ${error instanceof Error ? error.message : String(error)}` };\n  }\n}\n\n/** Backward-compatible host default write, using the same transaction as other preset edits. */\nexport async function writeDefaultPreset(\n  fs: FileSystem,\n  home: string,\n  environment: NodeJS.ProcessEnv,\n  name: string,\n  expectedHash: string,\n) {\n  return writePreset(fs, home, environment, 'default', { scope: 'host', name, expectedHash });\n}\n"],"mappings":";;;;;;;;;;AAkCA,MAAM,KAAK;AAGX,IAAI,SAA2B,QAAQ,QAAQ;;AAG/C,SAAgB,kBAAqB,QAAsC;CACzE,MAAM,SAAS,OAAO,KAAK,MAAM;CAEjC,SAAS,OAAO,YAAY,KAAA,CAAS;CACrC,OAAO;AACT;AAEA,SAAS,YAAY,OAAsC;CACzD,OAAO,OAAO,UAAU,WAAW,QAAQ,MAAM;AACnD;AAEA,SAAS,YAAY,eAA+B;CAClD,OAAO,KAAK,KAAK,wBAAwB,eAAe,CAAC,CAAC,GAAG,YAAY;AAC3E;;AAGA,SAAS,OAAO,MAAkC;CAChD,OAAO,SAAS,KAAA,IAAY,KAAK,WAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,MAAM,CAAC,CAAC,OAAO,KAAK;AACzF;;AAGA,eAAe,cAAc,IAAgB,MAAc,aAAgC,MAAe;CACxG,MAAM,QAAQ,CAAC,YAAY,IAAI,GAAG,GAAI,OAAO,CAAC,KAAK,KAAK,MAAM,OAAO,YAAY,CAAC,IAAI,CAAC,CAAE;CACzF,MAAM,UAAU,CAAC;CACjB,KAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,UAAU,qBAAqB,QAAQ;EAC7C,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