{"version":3,"file":"profiles-CXGWdK4E.cjs","names":["isRecord","parseYaml","PARENT_DIRECTORY","Buffer","path","PROFILE_ICON_MAX_DATA_URL_LENGTH","path","fs","path","getOrThrow","path","parseYaml","parseProfile","fs","readPersonaFrontMatter","readPersonaPresentation","containsPersonaFile","path","readSidecar","discoverProfile","discoverProfileRoot","readProfileLayers","readPoConfigSources","profilesFromLayers","os","getOrThrow","path","readTextIfExists","readPoConfigSourcesAsync","nodeHost"],"sources":["../src/services/personaFrontMatter/index.ts","../src/services/personaIcon/core.ts","../src/services/personaIcon/sync.ts","../src/services/personaIcon/index.ts","../src/services/profileBinding/index.ts","../src/services/profiles/core.ts","../src/services/profiles/sync.ts","../src/services/profiles/index.ts"],"sourcesContent":["import { parse as parseYaml } from 'yaml';\n\nimport type { PersonaDocument, PersonaFrontMatter, PersonaVoiceOverride } from '../../types/profiles';\n\n/**\n * Optional identity a persona declares at the top of its `profile.md`.\n *\n * A profile used to be prompt text only, so there was nowhere to say who the\n * persona is or how it should sound. Front-matter puts that beside the persona\n * text it describes, which is the only place that works for both explicit\n * `profiles.yaml` entries and folders found by root discovery.\n *\n * Recognition is deliberately narrow. Personas that exist today were written\n * without any of this, and one of them may legitimately open with a horizontal\n * rule, so a leading fence alone is not enough to claim the block. A block is\n * only treated as identity when it is fenced at the very first line, closed,\n * parses as a mapping, and declares at least one field this contract owns.\n * Anything else is passed through byte for byte.\n */\n\nconst FENCE = '---';\nconst OWNED_KEYS = ['name', 'icon', 'voice'] as const;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction readVoice(value: unknown): PersonaVoiceOverride | undefined {\n  if (!isRecord(value)) return undefined;\n  const voice = typeof value.voice === 'string' && value.voice.trim().length > 0 ? value.voice.trim() : undefined;\n  const rate = typeof value.rate === 'number' && Number.isFinite(value.rate) ? value.rate : undefined;\n  if (voice === undefined && rate === undefined) return undefined;\n  return { ...(voice === undefined ? {} : { voice }), ...(rate === undefined ? {} : { rate }) };\n}\n\nfunction readFrontMatter(parsed: Record<string, unknown>): PersonaFrontMatter | undefined {\n  const name = typeof parsed.name === 'string' && parsed.name.trim().length > 0 ? parsed.name.trim() : undefined;\n  const icon = typeof parsed.icon === 'string' && parsed.icon.trim().length > 0 ? parsed.icon.trim() : undefined;\n  const voice = readVoice(parsed.voice);\n  if (name === undefined && icon === undefined && voice === undefined) return undefined;\n  return {\n    ...(name === undefined ? {} : { name }),\n    ...(icon === undefined ? {} : { icon }),\n    ...(voice === undefined ? {} : { voice }),\n  };\n}\n\n/**\n * Splits a recognised identity block off a persona document.\n *\n * Never throws: a malformed avatar must not make a persona unloadable, so an\n * unparseable or unrecognised block leaves the document exactly as it arrived.\n */\nexport function parsePersonaFrontMatter(content: string): PersonaDocument {\n  const lines = content.split('\\n');\n  if (lines[0]?.trimEnd() !== FENCE) return { body: content };\n\n  const closingIndex = lines.findIndex((line, index) => index > 0 && line.trimEnd() === FENCE);\n  if (closingIndex === -1) return { body: content };\n\n  let parsed: unknown;\n  try {\n    parsed = parseYaml(lines.slice(1, closingIndex).join('\\n'));\n  } catch {\n    return { body: content };\n  }\n  if (!isRecord(parsed)) return { body: content };\n  if (!OWNED_KEYS.some((key) => Object.hasOwn(parsed, key))) return { body: content };\n\n  const frontMatter = readFrontMatter(parsed);\n  if (!frontMatter) return { body: content };\n  return { frontMatter, body: lines.slice(closingIndex + 1).join('\\n') };\n}\n","import { Buffer } from 'node:buffer';\nimport path from 'node:path';\n\nimport { PROFILE_ICON_MAX_DATA_URL_LENGTH, type ProfileIconMimeType } from '@agimon-ai/po-core/profileIdentity';\n\n/**\n * Pure half of persona icon loading: confinement and image sniffing. The\n * readers in `index.ts` (async, over a FileSystem) and `sync.ts` (Node shim)\n * only resolve paths and fetch bytes.\n */\nconst PARENT_DIRECTORY = '..';\n\n/**\n * Magic-byte signatures, checked instead of trusting the filename.\n *\n * `image/svg+xml` is absent on purpose: an SVG rendered same-origin executes\n * script, and the author of this path is whoever wrote the persona. Do not add\n * it to match the cockpit's broader media catalog.\n */\nconst SIGNATURES: readonly { readonly mime: ProfileIconMimeType; readonly test: (bytes: Buffer) => boolean }[] = [\n  {\n    mime: 'image/png',\n    test: (b) => b.length > 8 && b.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])),\n  },\n  { mime: 'image/jpeg', test: (b) => b.length > 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff },\n  { mime: 'image/gif', test: (b) => b.length > 6 && b.subarray(0, 6).toString('latin1').startsWith('GIF8') },\n  {\n    mime: 'image/webp',\n    test: (b) =>\n      b.length > 12 &&\n      b.subarray(0, 4).toString('latin1') === 'RIFF' &&\n      b.subarray(8, 12).toString('latin1') === 'WEBP',\n  },\n];\n\n/** True when `realIconPath` lies inside `realPersonaPath` (both already canonical). */\nexport function isInsidePersona(realPersonaPath: string, realIconPath: string): boolean {\n  const relative = path.relative(realPersonaPath, realIconPath);\n  return !(\n    relative === PARENT_DIRECTORY ||\n    relative.startsWith(`${PARENT_DIRECTORY}${path.sep}`) ||\n    path.isAbsolute(relative)\n  );\n}\n\n/** A bounded `data:` URL for an allowed image, or undefined. */\nexport function iconDataUrl(content: Uint8Array): string | undefined {\n  const bytes = Buffer.from(content.buffer, content.byteOffset, content.byteLength);\n  const mime = SIGNATURES.find((signature) => signature.test(bytes))?.mime;\n  if (!mime) return undefined;\n  const dataUrl = `data:${mime};base64,${bytes.toString('base64')}`;\n  return dataUrl.length > PROFILE_ICON_MAX_DATA_URL_LENGTH ? undefined : dataUrl;\n}\n","// sync: Preserve the exported Node-only readPersonaIcon signature until phase 2.\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { iconDataUrl, isInsidePersona } from './core';\n\n/**\n * Resolves an icon declared in persona front-matter, or undefined when it is\n * missing, unreadable, not an allowed image, escapes the persona directory, or\n * exceeds the data-URL ceiling.\n *\n * @deprecated Node-only sync shim; use readPersonaIconAsync. Removed in M2.\n */\nexport function readPersonaIcon(personaPath: string, iconRelative: string): string | undefined {\n  if (path.isAbsolute(iconRelative)) return undefined;\n\n  try {\n    const realPersonaPath = fs.realpathSync(personaPath);\n    const iconPath = path.resolve(realPersonaPath, iconRelative);\n    if (!fs.existsSync(iconPath)) return undefined;\n\n    const realIconPath = fs.realpathSync(iconPath);\n    if (!isInsidePersona(realPersonaPath, realIconPath)) return undefined;\n    if (!fs.statSync(realIconPath).isFile()) return undefined;\n\n    return iconDataUrl(fs.readFileSync(realIconPath));\n  } catch {\n    return undefined;\n  }\n}\n","import path from 'node:path';\n\nimport { getOrThrow, type FileSystem } from '@agimon-ai/po-core/platform';\n\nimport { iconDataUrl, isInsidePersona } from './core';\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\n/**\n * Reads a persona icon into a bounded `data:` URL.\n *\n * The icon travels inside the journalled identity entry rather than through an\n * HTTP route. A route would leave a request-time filesystem resolution reachable\n * from the browser for the life of a session, defended on every request forever;\n * this resolves the path once, server side, at the moment the profile loads.\n *\n * The path comes from user-authored front-matter, so it is confined the same way\n * `buildPersonaPrompt` confines persona files: a symlink must not read outside\n * the persona directory.\n *\n * Every failure is silent and returns undefined. An avatar is decoration, and a\n * broken one must never stop a persona from loading. That includes a host whose\n * filesystem lacks the persona entirely, such as the edge.\n */\nexport async function readPersonaIconAsync(\n  fs: FileSystem,\n  personaPath: string,\n  iconRelative: string,\n  context: IoContext,\n): Promise<string | undefined> {\n  if (path.isAbsolute(iconRelative)) return undefined;\n\n  try {\n    const realPersonaPath = getOrThrow(await fs.canonicalPath(personaPath, context));\n    const iconPath = path.resolve(realPersonaPath, iconRelative);\n    if (!getOrThrow(await fs.exists(iconPath, context))) return undefined;\n\n    const realIconPath = getOrThrow(await fs.canonicalPath(iconPath, context));\n    if (!isInsidePersona(realPersonaPath, realIconPath)) return undefined;\n    if (getOrThrow(await fs.fileInfo(realIconPath, context)).kind !== 'file') return undefined;\n\n    return iconDataUrl(getOrThrow(await fs.readBinaryFile(realIconPath, context)));\n  } catch {\n    return undefined;\n  }\n}\n\nexport { readPersonaIcon } from './sync';\n","import type {\n  ProfileBrowserBinding,\n  ProfileBrowserMode,\n  ProfileIntegrationBinding,\n  ProfileSecretPurpose,\n  ProfileSecretReference,\n} from './type';\n\nconst BINDING_KEYS = new Set(['provider', 'organizationId', 'mailboxId', 'credentialRef', 'secrets', 'browser']);\nconst SECRET_KEYS = new Set(['credentialId', 'field', 'purposes', 'allowedOrigins']);\nconst BROWSER_KEYS = new Set(['profileName', 'allowedOrigins', 'mode', 'proxySecret']);\nconst PURPOSES: ReadonlySet<string> = new Set<ProfileSecretPurpose>(['browser', 'proxy', 'env']);\nconst BROWSER_MODES: ReadonlySet<string> = new Set<ProfileBrowserMode>(['playwright', 'extension', 'stealth']);\nconst ALIAS_PATTERN = /^[A-Z][A-Z0-9_]{0,63}$/;\nconst FIELD_PATTERN = /^(?:[A-Za-z][A-Za-z0-9_.-]{0,63}|profileSecret:[A-Z][A-Z0-9_]{0,63})$/;\nconst BROWSER_PROFILE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;\n\nfunction record(value: unknown, location: string, keys?: ReadonlySet<string>): Record<string, unknown> {\n  if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n    throw new Error(`${location} must be a mapping`);\n  }\n  if (keys && Object.keys(value).some((key) => !keys.has(key))) {\n    // Never echo an unknown key or value, either of which might contain a misplaced secret.\n    throw new Error(`${location} contains unsupported metadata`);\n  }\n  return value as Record<string, unknown>;\n}\n\nfunction reference(value: unknown, location: string): string {\n  if (typeof value !== 'string' || value.length === 0 || value.length > 256 || /\\s/.test(value)) {\n    throw new Error(`${location} must be a non-empty reference without whitespace`);\n  }\n  return value;\n}\n\nfunction origins(value: unknown, location: string): readonly string[] {\n  if (!Array.isArray(value) || value.length === 0) throw new Error(`${location} must contain exact HTTP(S) origins`);\n  const result = value.map((entry: unknown) => {\n    if (typeof entry !== 'string') throw new Error(`${location} must contain exact HTTP(S) origins`);\n    let url: URL;\n    try {\n      url = new URL(entry);\n    } catch {\n      throw new Error(`${location} must contain exact HTTP(S) origins`);\n    }\n    if (\n      (url.protocol !== 'https:' && url.protocol !== 'http:') ||\n      url.origin !== entry ||\n      url.username ||\n      url.password\n    ) {\n      throw new Error(`${location} must contain exact HTTP(S) origins`);\n    }\n    return entry;\n  });\n  return Object.freeze([...new Set(result)]);\n}\n\nfunction purposes(value: unknown, location: string): readonly ProfileSecretPurpose[] {\n  if (value === undefined) return Object.freeze(['browser'] as const);\n  if (\n    !Array.isArray(value) ||\n    value.length === 0 ||\n    value.some((entry: unknown) => typeof entry !== 'string' || !PURPOSES.has(entry)) ||\n    new Set(value).size !== value.length\n  ) {\n    throw new Error(`${location} must list distinct purposes: browser, proxy or env`);\n  }\n  return Object.freeze([...(value as ProfileSecretPurpose[])]);\n}\n\nfunction browser(value: unknown, location: string): ProfileBrowserBinding {\n  const entry = record(value, location, BROWSER_KEYS);\n  if (typeof entry.profileName !== 'string' || !BROWSER_PROFILE_PATTERN.test(entry.profileName)) {\n    throw new Error(`${location}.profileName must be a safe browser profile name`);\n  }\n  if (entry.mode !== undefined && (typeof entry.mode !== 'string' || !BROWSER_MODES.has(entry.mode))) {\n    throw new Error(`${location}.mode must be playwright, extension or stealth`);\n  }\n  if (\n    entry.proxySecret !== undefined &&\n    (typeof entry.proxySecret !== 'string' || !ALIAS_PATTERN.test(entry.proxySecret))\n  ) {\n    throw new Error(`${location}.proxySecret must be an uppercase alias name`);\n  }\n  return Object.freeze({\n    profileName: entry.profileName,\n    allowedOrigins: origins(entry.allowedOrigins, `${location}.allowedOrigins`),\n    ...(entry.mode === undefined ? {} : { mode: entry.mode as ProfileBrowserMode }),\n    ...(entry.proxySecret === undefined ? {} : { proxySecret: entry.proxySecret }),\n  });\n}\n\n/** Validates and deeply freezes a detached metadata snapshot. No provider SDK or secret is loaded. */\nexport function parseProfileBinding(value: unknown, location = 'Profile integration'): ProfileIntegrationBinding {\n  const entry = record(value, location, BINDING_KEYS);\n  const sourceSecrets = record(entry.secrets, `${location}.secrets`);\n  const secrets: Record<string, ProfileSecretReference> = {};\n  for (const [alias, value] of Object.entries(sourceSecrets)) {\n    if (!ALIAS_PATTERN.test(alias)) throw new Error(`${location}.secrets requires uppercase alias names`);\n    const secret = record(value, `${location}.secrets.${alias}`, SECRET_KEYS);\n    if (typeof secret.field !== 'string' || !FIELD_PATTERN.test(secret.field)) {\n      throw new Error(`${location}.secrets.${alias}.field must be a credential field name`);\n    }\n    const secretPurposes = purposes(secret.purposes, `${location}.secrets.${alias}.purposes`);\n    const forBrowser = secretPurposes.includes('browser');\n    // An empty list is accepted so parsed output round-trips through this parser.\n    const emptyOrigins = Array.isArray(secret.allowedOrigins) && secret.allowedOrigins.length === 0;\n    if (!forBrowser && secret.allowedOrigins !== undefined && !emptyOrigins) {\n      throw new Error(`${location}.secrets.${alias}.allowedOrigins requires the browser purpose`);\n    }\n    secrets[alias] = Object.freeze({\n      credentialId: reference(secret.credentialId, `${location}.secrets.${alias}.credentialId`),\n      field: secret.field,\n      purposes: secretPurposes,\n      allowedOrigins: forBrowser\n        ? origins(secret.allowedOrigins, `${location}.secrets.${alias}.allowedOrigins`)\n        : Object.freeze([]),\n    });\n  }\n  const browserBinding = entry.browser === undefined ? undefined : browser(entry.browser, `${location}.browser`);\n  if (\n    browserBinding &&\n    Object.values(secrets).some((secret) =>\n      secret.allowedOrigins.some((origin) => !browserBinding.allowedOrigins.includes(origin)),\n    )\n  ) {\n    throw new Error(`${location} secret origins must be included in browser.allowedOrigins`);\n  }\n  if (browserBinding?.proxySecret !== undefined && !secrets[browserBinding.proxySecret]?.purposes.includes('proxy')) {\n    throw new Error(`${location}.browser.proxySecret must name a proxy-purpose secret`);\n  }\n  return Object.freeze({\n    provider: reference(entry.provider, `${location}.provider`),\n    organizationId: reference(entry.organizationId, `${location}.organizationId`),\n    mailboxId: reference(entry.mailboxId, `${location}.mailboxId`),\n    credentialRef: reference(entry.credentialRef, `${location}.credentialRef`),\n    secrets: Object.freeze(secrets),\n    ...(browserBinding === undefined ? {} : { browser: browserBinding }),\n  });\n}\n","import path from 'node:path';\n\nimport { parse as parseYaml } from 'yaml';\n\nimport type { PersonaFrontMatter, PersonaIdentity, PersonaVoiceOverride } from '../../types/profiles';\nimport { parsePersonaFrontMatter } from '../personaFrontMatter';\nimport { parseProfileBinding } from '../profileBinding';\nimport type { ProfileIntegrationBinding } from '../profileBinding/type';\n\n/** Files that make up one repository persona, concatenated in this order. */\nexport const PERSONA_FILES = ['profile.md', 'SOUL.md', 'AGENTS.md'];\n\n/** The persona file that may carry an identity block; the others are prose only. */\nexport const PERSONA_IDENTITY_FILE = 'profile.md';\n\nexport interface AgentProfile {\n  name: string;\n  /** Directory relative to personaRoot, which remains the persona source. */\n  persona: string;\n  /**\n   * Root the persona path resolves against: the repository root for a\n   * repository profile, the global `.po` directory for a global one.\n   */\n  personaRoot: string;\n  /** Environment defaults. Values already exported by the caller win. */\n  env: Record<string, string>;\n  /** Nonsecret integration metadata. Resolved secrets never enter profile environment. */\n  integration?: ProfileIntegrationBinding;\n  /** Display name and avatar declared in the persona's own front-matter. */\n  identity?: PersonaIdentity;\n  /** Narrowly scoped TTS override declared alongside the identity. */\n  voice?: PersonaVoiceOverride;\n  /** Persona prompt for a profile served from memory; directory profiles build theirs from disk. */\n  personaPrompt?: string;\n}\n\n/** A profile contributed from memory, validated with the directory profile rules. */\nexport interface InlineProfileInput {\n  name: string;\n  /** Stable origin label, shown in place of a persona directory. */\n  source: string;\n  /** Persona file text keyed by file name; only PERSONA_FILES are read. */\n  files: Readonly<Record<string, string>>;\n  env?: unknown;\n  integration?: unknown;\n}\n\nexport interface ProfileConfigLayer {\n  filePath: string;\n  baseDirectory: string;\n  roots: string[];\n  entries: Record<string, unknown>;\n  defaultProfile?: string;\n}\n\n/** An explicit entry that passed shape checks, before its persona is read from disk. */\nexport interface ProfileEntryDraft {\n  name: string;\n  persona: string;\n  personaPath: string;\n  /** Allowed roots that lexically contain the persona; the caller confirms one after resolving links. */\n  lexicalRoots: string[];\n  value: Record<string, unknown>;\n}\n\nexport type PersonaPresentation = { identity?: PersonaIdentity; voice?: PersonaVoiceOverride };\n\n/** A discovered profile that was skipped. Messages name keys and files, never values. */\nexport interface ProfileDiagnostic {\n  filePath: string;\n  profile: string;\n  message: string;\n}\n\nexport type ProfileSidecar = Pick<AgentProfile, 'env' | 'integration'>;\n\nconst PROFILE_KEYS = new Set(['persona', 'env', 'integration']);\nconst PROFILE_CATALOG_KEYS = new Set(['roots', 'entries', 'defaultProfile']);\nconst SIDECAR_KEYS = new Set(['version', 'env', 'integration']);\nconst SIDECAR_VERSION = 1;\nconst SIDECAR_MAX_BYTES = 64 * 1024;\nexport const PROFILES_FILE = 'profiles.yaml';\n/** Optional nonsecret sidecar beside a discovered persona, validated like an explicit entry. */\nexport const PROFILE_SIDECAR_FILE = 'profile.yaml';\nconst PROFILES_ROOT_KEY = 'profiles';\nconst AGENTS_DIRECTORY = 'agents';\nexport const PARENT_DIRECTORY = '..';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nexport function isPathInside(root: string, candidate: string): boolean {\n  const relative = path.relative(root, candidate);\n  return (\n    relative === '' ||\n    (!path.isAbsolute(relative) &&\n      relative !== PARENT_DIRECTORY &&\n      !relative.startsWith(`${PARENT_DIRECTORY}${path.sep}`))\n  );\n}\n\nfunction parseEnvironment(name: string, value: unknown): Record<string, string> {\n  if (value === undefined) return {};\n  if (!isRecord(value)) throw new Error(`Profile \"${name}\" env must be a string mapping`);\n\n  const environment: Record<string, string> = {};\n  for (const [key, entry] of Object.entries(value)) {\n    if (typeof entry !== 'string') throw new Error(`Profile \"${name}\" env.${key} must be a string`);\n    if (entry.includes('${secret.') || entry.includes('${secrets.')) {\n      throw new Error(`Profile \"${name}\" env cannot contain secret aliases`);\n    }\n    environment[key] = entry;\n  }\n  return environment;\n}\n\n/** Strict v1 sidecar parse. YAML errors are reported generically so source text never reaches a diagnostic. */\nexport function parseProfileSidecar(name: string, text: string): ProfileSidecar {\n  if (Buffer.byteLength(text) > SIDECAR_MAX_BYTES)\n    throw new Error(`Profile \"${name}\" ${PROFILE_SIDECAR_FILE} is too large`);\n  let document: unknown;\n  try {\n    document = parseYaml(text);\n  } catch {\n    throw new Error(`Profile \"${name}\" ${PROFILE_SIDECAR_FILE} is not valid YAML`);\n  }\n  if (!isRecord(document)) throw new Error(`Profile \"${name}\" ${PROFILE_SIDECAR_FILE} must be a mapping`);\n  if (Object.keys(document).some((key) => !SIDECAR_KEYS.has(key))) {\n    throw new Error(`Profile \"${name}\" ${PROFILE_SIDECAR_FILE} may only set version, env and integration`);\n  }\n  if (document.version !== SIDECAR_VERSION) {\n    throw new Error(`Profile \"${name}\" ${PROFILE_SIDECAR_FILE} must declare version: ${SIDECAR_VERSION}`);\n  }\n  return {\n    env: parseEnvironment(name, document.env),\n    ...(document.integration === undefined\n      ? {}\n      : { integration: parseProfileBinding(document.integration, `Profile \"${name}\" integration`) }),\n  };\n}\n\nexport function sidecarDiagnostic(filePath: string, profile: string, error: unknown): ProfileDiagnostic {\n  return { filePath, profile, message: error instanceof Error ? error.message : `Profile \"${profile}\" is invalid` };\n}\nfunction parseProfileRoots(value: unknown, filePath: string, baseDirectory: string): string[] {\n  if (value === undefined) return [];\n  if (!Array.isArray(value)) throw new Error(`profiles.roots in ${filePath} must be an array`);\n  return value.map((entry, index) => {\n    if (typeof entry !== 'string' || entry.trim().length === 0) {\n      throw new Error(`profiles.roots[${index}] in ${filePath} must be a non-empty string`);\n    }\n    return path.resolve(baseDirectory, entry.trim());\n  });\n}\n\nexport function parseProfileLayer(source: {\n  filePath: string;\n  baseDirectory: string;\n  document: unknown;\n}): ProfileConfigLayer {\n  if (!isRecord(source.document) || !isRecord(source.document[PROFILES_ROOT_KEY])) {\n    throw new Error(`${source.filePath} must contain a profiles mapping`);\n  }\n  const unsupportedDocumentKeys = Object.keys(source.document).filter((key) => key !== PROFILES_ROOT_KEY);\n  if (unsupportedDocumentKeys.length > 0) {\n    throw new Error(`${source.filePath} may only contain profiles; unsupported: ${unsupportedDocumentKeys.join(', ')}`);\n  }\n\n  const profiles = source.document[PROFILES_ROOT_KEY];\n  const usesCatalogShape = Object.hasOwn(profiles, 'roots') || Object.hasOwn(profiles, 'entries');\n  if (!usesCatalogShape) {\n    return { filePath: source.filePath, baseDirectory: source.baseDirectory, roots: [], entries: profiles };\n  }\n\n  const unsupportedCatalogKeys = Object.keys(profiles).filter((key) => !PROFILE_CATALOG_KEYS.has(key));\n  if (unsupportedCatalogKeys.length > 0) {\n    throw new Error(\n      `profiles in ${source.filePath} may only contain roots, entries and defaultProfile; unsupported: ${unsupportedCatalogKeys.join(', ')}`,\n    );\n  }\n  if (\n    profiles.defaultProfile !== undefined &&\n    (typeof profiles.defaultProfile !== 'string' || profiles.defaultProfile.trim().length === 0)\n  ) {\n    throw new Error(`profiles.defaultProfile in ${source.filePath} must be a non-empty string`);\n  }\n  if (profiles.entries !== undefined && !isRecord(profiles.entries)) {\n    throw new Error(`profiles.entries in ${source.filePath} must be a mapping`);\n  }\n  return {\n    filePath: source.filePath,\n    baseDirectory: source.baseDirectory,\n    roots: parseProfileRoots(profiles.roots, source.filePath, source.baseDirectory),\n    entries: profiles.entries ?? {},\n    ...(profiles.defaultProfile === undefined ? {} : { defaultProfile: String(profiles.defaultProfile).trim() }),\n  };\n}\n\n/**\n * Shape checks for one explicit entry. The caller checks the persona on disk,\n * then `profileFromDraft` parses env and integration, keeping the error order.\n */\nexport function draftProfileEntry(\n  personaRoot: string,\n  configuredRoots: readonly string[],\n  name: string,\n  value: unknown,\n): ProfileEntryDraft {\n  if (!isRecord(value)) throw new Error(`Profile \"${name}\" must be a mapping`);\n\n  const unsupported = Object.keys(value).filter((key) => !PROFILE_KEYS.has(key));\n  if (unsupported.length > 0) {\n    throw new Error(\n      `Profile \"${name}\" may only set persona, env and integration; unsupported: ${unsupported.join(', ')}`,\n    );\n  }\n  if (typeof value.persona !== 'string' || value.persona.trim().length === 0) {\n    throw new Error(`Profile \"${name}\" must set a persona`);\n  }\n  if (path.isAbsolute(value.persona)) {\n    throw new Error(`Profile \"${name}\" persona must be relative to the config that declares it`);\n  }\n\n  const persona = value.persona;\n  const personaPath = path.resolve(personaRoot, persona);\n  const lexicalRoots = [path.resolve(personaRoot, AGENTS_DIRECTORY), ...configuredRoots].filter((root) =>\n    isPathInside(root, personaPath),\n  );\n  if (lexicalRoots.length === 0) throw outsideAllowedRoot(name);\n  return {\n    name,\n    persona,\n    personaPath,\n    lexicalRoots,\n    value,\n  };\n}\n\nexport function outsideAllowedRoot(name: string): Error {\n  return new Error(`Profile \"${name}\" persona must stay inside agents/ or a configured profile root`);\n}\n\nexport function missingPersona(name: string, persona: string): Error {\n  return new Error(`Profile \"${name}\" references a missing persona: ${persona}`);\n}\n\n/**\n * An identity block is not persona text, so a profile.md holding nothing else\n * leaves the persona empty. Say that, rather than claiming the file is unreadable.\n */\nexport function emptyPersona(name: string, persona: string, declaresIdentity: boolean): Error {\n  return new Error(\n    declaresIdentity\n      ? `Profile \"${name}\" persona declares identity front-matter but no persona text: ${persona}`\n      : `Profile \"${name}\" persona has no readable persona files: ${persona}`,\n  );\n}\n\nexport function profileFromDraft(\n  draft: ProfileEntryDraft,\n  personaRoot: string,\n  presentation: PersonaPresentation,\n): AgentProfile {\n  const { name, value } = draft;\n  return {\n    name,\n    persona: draft.persona,\n    personaRoot,\n    env: parseEnvironment(name, value.env),\n    ...(value.integration === undefined\n      ? {}\n      : { integration: parseProfileBinding(value.integration, `Profile \"${name}\" integration`) }),\n    ...presentation,\n  };\n}\n\nexport function presentationFrom(frontMatter: PersonaFrontMatter, icon: string | undefined): PersonaPresentation {\n  const identity: PersonaIdentity = {\n    ...(frontMatter.name === undefined ? {} : { name: frontMatter.name }),\n    ...(icon === undefined ? {} : { icon }),\n  };\n  return {\n    ...(identity.name === undefined && identity.icon === undefined ? {} : { identity }),\n    ...(frontMatter.voice === undefined ? {} : { voice: frontMatter.voice }),\n  };\n}\n\n/** Rejects a persona file whose real path left the persona directory. */\nexport function assertPersonaFileInside(\n  personaPath: string,\n  realFilePath: string,\n  personaDirectory: string,\n  file: string,\n): void {\n  const relativeFilePath = path.relative(personaPath, realFilePath);\n  if (relativeFilePath === PARENT_DIRECTORY || relativeFilePath.startsWith(`${PARENT_DIRECTORY}${path.sep}`)) {\n    throw new Error(`Persona file must stay inside ${personaDirectory}: ${file}`);\n  }\n}\n\n/** The text one persona file contributes. Only profile.md may declare identity, so only profile.md is stripped. */\nexport function personaFileSection(file: string, raw: string): string {\n  return (file === PERSONA_IDENTITY_FILE ? parsePersonaFrontMatter(raw).body : raw).trim();\n}\n\nexport function personaPromptFromSections(personaDirectory: string, sections: readonly string[]): string | undefined {\n  if (sections.length === 0) return undefined;\n  return [`[PERSONA] You are operating as the person described below (source: ${personaDirectory}).`, ...sections].join(\n    '\\n\\n',\n  );\n}\n\n/** Builds a profile from in-memory persona text. Nothing is read from disk, so it has no persona root or icon. */\nexport function inlineProfile(input: InlineProfileInput): AgentProfile {\n  const { name, source, files } = input;\n  const read = (file: string): string | undefined => (Object.hasOwn(files, file) ? files[file] : undefined);\n  const sections = PERSONA_FILES.flatMap((file) => {\n    const raw = read(file);\n    const section = raw === undefined ? '' : personaFileSection(file, raw);\n    return section ? [section] : [];\n  });\n  const identityText = read(PERSONA_IDENTITY_FILE);\n  const frontMatter = identityText === undefined ? undefined : parsePersonaFrontMatter(identityText).frontMatter;\n  const personaPrompt = personaPromptFromSections(source, sections);\n  if (!personaPrompt) throw emptyPersona(name, source, frontMatter !== undefined);\n  return {\n    name,\n    persona: source,\n    personaRoot: '',\n    env: parseEnvironment(name, input.env),\n    ...(input.integration === undefined\n      ? {}\n      : { integration: parseProfileBinding(input.integration, `Profile \"${name}\" integration`) }),\n    ...(frontMatter === undefined ? {} : presentationFrom(frontMatter, undefined)),\n    personaPrompt,\n  };\n}\n\nexport function sortProfiles(byName: Map<string, AgentProfile>): AgentProfile[] {\n  return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));\n}\n\n/** A repository declaration replaces a personal one; an unknown name is an error, not a fallback. */\nexport function catalogDefaultProfile(\n  layers: readonly ProfileConfigLayer[],\n  profiles: readonly AgentProfile[],\n): string | undefined {\n  let defaultProfile: string | undefined;\n  for (const layer of layers) {\n    if (layer.defaultProfile !== undefined) defaultProfile = layer.defaultProfile;\n  }\n  if (defaultProfile !== undefined && !profiles.some((profile) => profile.name === defaultProfile)) {\n    throw new Error(`profiles.defaultProfile names an unknown profile: ${defaultProfile}`);\n  }\n  return defaultProfile;\n}\n\n/** Applies profile environment defaults and returns only the values it contributed. */\nexport function applyProfileEnvironment(\n  environment: NodeJS.ProcessEnv,\n  defaults: Record<string, string>,\n): Record<string, string> {\n  const applied: Record<string, string> = {};\n  for (const [key, value] of Object.entries(defaults)) {\n    if (environment[key] !== undefined) continue;\n    environment[key] = value;\n    applied[key] = value;\n  }\n  return applied;\n}\n\n/** Replaces environment defaults previously contributed by another profile. */\nexport function replaceProfileEnvironment(\n  environment: NodeJS.ProcessEnv,\n  previous: Record<string, string>,\n  next: Record<string, string>,\n): Record<string, string> {\n  for (const [key, value] of Object.entries(previous)) {\n    if (environment[key] === value) delete environment[key];\n  }\n  return applyProfileEnvironment(environment, next);\n}\n","// sync: These helpers implement exported Node-only synchronous profile and persona APIs.\nimport fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\nimport type { PersonaFrontMatter } from '../../types/profiles';\nimport { readPoConfigSources } from '../layeredConfig';\nimport { parsePersonaFrontMatter } from '../personaFrontMatter';\nimport { readPersonaIcon } from '../personaIcon';\nimport {\n  PERSONA_FILES,\n  PERSONA_IDENTITY_FILE,\n  PROFILE_SIDECAR_FILE,\n  PROFILES_FILE,\n  assertPersonaFileInside,\n  catalogDefaultProfile,\n  draftProfileEntry,\n  emptyPersona,\n  isPathInside,\n  missingPersona,\n  outsideAllowedRoot,\n  parseProfileLayer,\n  parseProfileSidecar,\n  personaFileSection,\n  personaPromptFromSections,\n  presentationFrom,\n  profileFromDraft,\n  sidecarDiagnostic,\n  sortProfiles,\n  type AgentProfile,\n  type PersonaPresentation,\n  type ProfileConfigLayer,\n  type ProfileDiagnostic,\n  type ProfileSidecar,\n} from './core';\n\nconst TEXT_ENCODING = 'utf8';\n\nfunction parseProfile(\n  personaRoot: string,\n  configuredRoots: readonly string[],\n  name: string,\n  value: unknown,\n): AgentProfile {\n  const draft = draftProfileEntry(personaRoot, configuredRoots, name, value);\n  if (!fs.existsSync(draft.personaPath) || !fs.statSync(draft.personaPath).isDirectory()) {\n    throw missingPersona(name, draft.persona);\n  }\n  const realPersonaPath = fs.realpathSync(draft.personaPath);\n  if (!draft.lexicalRoots.some((root) => isPathInside(fs.realpathSync(root), realPersonaPath))) {\n    throw outsideAllowedRoot(name);\n  }\n  if (!buildPersonaPrompt(personaRoot, draft.persona)) {\n    throw emptyPersona(name, draft.persona, readPersonaFrontMatter(personaRoot, draft.persona) !== undefined);\n  }\n  return profileFromDraft(draft, personaRoot, readPersonaPresentation(personaRoot, draft.persona));\n}\n\nfunction containsPersonaFile(directory: string): boolean {\n  return PERSONA_FILES.some((file) => {\n    try {\n      return fs.lstatSync(path.join(directory, file)).isFile();\n    } catch {\n      return false;\n    }\n  });\n}\n\n/** Reads the optional sidecar, which must be a regular file whose real path stays in the persona directory. */\nfunction readSidecar(name: string, realDirectory: string): ProfileSidecar {\n  const filePath = path.join(realDirectory, PROFILE_SIDECAR_FILE);\n  if (!fs.existsSync(filePath)) return { env: {} };\n  const realFilePath = fs.realpathSync(filePath);\n  if (!isPathInside(realDirectory, realFilePath) || !fs.statSync(realFilePath).isFile()) {\n    throw new Error(`Profile \"${name}\" ${PROFILE_SIDECAR_FILE} must be a file inside the persona directory`);\n  }\n  return parseProfileSidecar(name, fs.readFileSync(realFilePath, TEXT_ENCODING));\n}\n\nfunction discoverProfile(\n  directory: string,\n  configuredRoot: string,\n  personaRoot: string,\n  diagnostics: ProfileDiagnostic[],\n): AgentProfile | undefined {\n  if (!containsPersonaFile(directory)) return undefined;\n  const name = path.basename(directory);\n  try {\n    const realConfiguredRoot = fs.realpathSync(configuredRoot);\n    const realDirectory = fs.realpathSync(directory);\n    if (!isPathInside(realConfiguredRoot, realDirectory)) return undefined;\n    const persona = path.relative(personaRoot, directory) || '.';\n    if (!buildPersonaPrompt(personaRoot, persona)) return undefined;\n    let sidecar: ProfileSidecar;\n    try {\n      sidecar = readSidecar(name, realDirectory);\n    } catch (error) {\n      // A bad sidecar skips only this profile, visibly, rather than failing the catalog.\n      diagnostics.push(sidecarDiagnostic(path.join(directory, PROFILE_SIDECAR_FILE), name, error));\n      return undefined;\n    }\n    return {\n      name,\n      persona,\n      personaRoot,\n      ...sidecar,\n      ...readPersonaPresentation(personaRoot, persona),\n    };\n  } catch {\n    // Automatic discovery ignores unreadable or unsafe candidates; explicit entries remain fatal.\n    return undefined;\n  }\n}\n\nfunction discoverProfileRoot(root: string, personaRoot: string, diagnostics: ProfileDiagnostic[]): AgentProfile[] {\n  if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) {\n    throw new Error(`Configured profile root is not a directory: ${root}`);\n  }\n\n  const rootProfile = discoverProfile(root, root, personaRoot, diagnostics);\n  if (rootProfile) return [rootProfile];\n\n  return fs\n    .readdirSync(root, { withFileTypes: true })\n    .filter((entry) => entry.isDirectory())\n    .sort((left, right) => left.name.localeCompare(right.name))\n    .flatMap((entry) => {\n      const profile = discoverProfile(path.join(root, entry.name), root, personaRoot, diagnostics);\n      return profile ? [profile] : [];\n    });\n}\n\nfunction readProfileLayers(repoRoot: string, homeDirectory: string): ProfileConfigLayer[] {\n  return readPoConfigSources<unknown>(PROFILES_FILE, repoRoot, homeDirectory).map(parseProfileLayer);\n}\n\nfunction profilesFromLayers(\n  layers: readonly ProfileConfigLayer[],\n  diagnostics: ProfileDiagnostic[] = [],\n): AgentProfile[] {\n  const byName = new Map<string, AgentProfile>();\n  for (const layer of layers) {\n    for (const root of layer.roots) {\n      for (const profile of discoverProfileRoot(root, layer.baseDirectory, diagnostics)) {\n        byName.set(profile.name, profile);\n      }\n    }\n  }\n  for (const layer of layers) {\n    for (const [name, value] of Object.entries(layer.entries)) {\n      byName.set(name, parseProfile(layer.baseDirectory, layer.roots, name, value));\n    }\n  }\n  return sortProfiles(byName);\n}\n\n/**\n * Loads profiles from the global and repository configs, repository last.\n *\n * Configured roots accumulate and inspect themselves or their direct-child\n * directories for persona files. Later discoveries replace earlier names, and\n * explicit entries replace discoveries. Legacy flat profile mappings remain\n * accepted as explicit entries.\n *\n * @deprecated Node-only sync shim; use loadProfilesAsync. Removed in M2.\n */\nexport function loadProfiles(repoRoot: string, homeDirectory: string = os.homedir()): AgentProfile[] {\n  return profilesFromLayers(readProfileLayers(repoRoot, homeDirectory));\n}\n\n/**\n * The profile catalog: every resolved profile, plus the name a launch starts on\n * when the caller names none.\n *\n * `defaultProfile` mirrors `defaultMajorMode` in modes.yaml and `defaultDomains`\n * in domains.yaml, so each selection axis declares its default in its own\n * catalog. A repository declaration replaces a personal one. An unknown name is\n * an error rather than a silent fallback: a typo that quietly starts the session\n * with no persona is worse than a refused launch.\n *\n * @deprecated Node-only sync shim; use loadProfileCatalogAsync. Removed in M2.\n */\nexport function loadProfileCatalog(\n  repoRoot: string,\n  homeDirectory: string = os.homedir(),\n): { profiles: AgentProfile[]; defaultProfile?: string; diagnostics?: ProfileDiagnostic[] } {\n  const layers = readProfileLayers(repoRoot, homeDirectory);\n  const diagnostics: ProfileDiagnostic[] = [];\n  const profiles = profilesFromLayers(layers, diagnostics);\n  const defaultProfile = catalogDefaultProfile(layers, profiles);\n  return {\n    profiles,\n    ...(defaultProfile === undefined ? {} : { defaultProfile }),\n    ...(diagnostics.length === 0 ? {} : { diagnostics }),\n  };\n}\n\n/**\n * Resolves one selected profile and fails clearly when its name is unknown.\n *\n * @deprecated Node-only sync shim; use resolveProfileAsync. Removed in M2.\n */\nexport function resolveProfile(repoRoot: string, name: string, homeDirectory?: string): AgentProfile {\n  const profile = loadProfiles(repoRoot, homeDirectory).find((candidate) => candidate.name === name);\n  if (!profile) throw new Error(`Unknown profile: ${name}`);\n  return profile;\n}\n\n/** @deprecated Node-only sync shim; use listProfileNamesAsync. Removed in M2. */\nexport function listProfileNames(repoRoot: string, homeDirectory?: string): string[] {\n  return loadProfiles(repoRoot, homeDirectory).map((profile) => profile.name);\n}\n\nfunction readPersonaPresentation(personaRoot: string, personaDirectory: string): PersonaPresentation {\n  const frontMatter = readPersonaFrontMatter(personaRoot, personaDirectory);\n  if (!frontMatter) return {};\n  const icon =\n    frontMatter.icon === undefined\n      ? undefined\n      : readPersonaIcon(path.join(personaRoot, personaDirectory), frontMatter.icon);\n  return presentationFrom(frontMatter, icon);\n}\n\nfunction readPersonaFrontMatter(personaRoot: string, personaDirectory: string): PersonaFrontMatter | undefined {\n  try {\n    const personaPath = fs.realpathSync(path.join(personaRoot, personaDirectory));\n    const filePath = path.join(personaPath, PERSONA_IDENTITY_FILE);\n    if (!fs.existsSync(filePath)) return undefined;\n    return parsePersonaFrontMatter(fs.readFileSync(fs.realpathSync(filePath), TEXT_ENCODING)).frontMatter;\n  } catch {\n    return undefined;\n  }\n}\n\n/**\n * Builds the persona system-prompt block, or undefined when nothing is readable.\n *\n * @deprecated Node-only sync shim; use buildPersonaPromptAsync. Removed in M2.\n */\nexport function buildPersonaPrompt(personaRoot: string, personaDirectory: string): string | undefined {\n  const sections: string[] = [];\n  const personaPath = fs.realpathSync(path.join(personaRoot, personaDirectory));\n  for (const file of PERSONA_FILES) {\n    const filePath = path.join(personaPath, file);\n    if (!fs.existsSync(filePath)) continue;\n    const realFilePath = fs.realpathSync(filePath);\n    assertPersonaFileInside(personaPath, realFilePath, personaDirectory, file);\n    const content = personaFileSection(file, fs.readFileSync(realFilePath, TEXT_ENCODING));\n    if (content) sections.push(content);\n  }\n  return personaPromptFromSections(personaDirectory, sections);\n}\n","import path from 'node:path';\n\nimport { getOrThrow, nodeHost, readTextIfExists, type FileSystem } from '@agimon-ai/po-core/platform';\n\nimport type { PersonaFrontMatter } from '../../types/profiles';\nimport { readPoConfigSourcesAsync } from '../layeredConfig';\nimport { parsePersonaFrontMatter } from '../personaFrontMatter';\nimport { readPersonaIconAsync } from '../personaIcon';\nimport {\n  PERSONA_FILES,\n  PERSONA_IDENTITY_FILE,\n  PROFILE_SIDECAR_FILE,\n  PROFILES_FILE,\n  assertPersonaFileInside,\n  catalogDefaultProfile,\n  draftProfileEntry,\n  emptyPersona,\n  isPathInside,\n  missingPersona,\n  outsideAllowedRoot,\n  parseProfileLayer,\n  parseProfileSidecar,\n  personaFileSection,\n  personaPromptFromSections,\n  presentationFrom,\n  profileFromDraft,\n  sidecarDiagnostic,\n  sortProfiles,\n  type AgentProfile,\n  type PersonaPresentation,\n  type ProfileConfigLayer,\n  type ProfileDiagnostic,\n  type ProfileSidecar,\n} from './core';\n\ntype IoContext = Parameters<FileSystem['readTextFile']>[1];\n\n/** Profile reads over a FileSystem; the Node shims in `./sync` give the same answers from node:fs. */\n\nconst realPath = async (fs: FileSystem, target: string, context: IoContext): Promise<string> =>\n  getOrThrow(await fs.canonicalPath(target, context));\n\nconst exists = async (fs: FileSystem, target: string, context: IoContext): Promise<boolean> =>\n  getOrThrow(await fs.exists(target, context));\n\n/** Whether a path is a directory once links are followed, as `statSync().isDirectory()`. */\nasync function isDirectory(fs: FileSystem, target: string, context: IoContext): Promise<boolean> {\n  if (!(await exists(fs, target, context))) return false;\n  const info = getOrThrow(await fs.fileInfo(await realPath(fs, target, context), context));\n  return info.kind === 'directory';\n}\n\nasync function readPersonaFrontMatter(\n  fs: FileSystem,\n  personaRoot: string,\n  personaDirectory: string,\n  context: IoContext,\n): Promise<PersonaFrontMatter | undefined> {\n  try {\n    const personaPath = await realPath(fs, path.join(personaRoot, personaDirectory), context);\n    const filePath = path.join(personaPath, PERSONA_IDENTITY_FILE);\n    if (!(await exists(fs, filePath, context))) return undefined;\n    const text = await readTextIfExists(fs, await realPath(fs, filePath, context), context);\n    return text === undefined ? undefined : parsePersonaFrontMatter(text).frontMatter;\n  } catch {\n    return undefined;\n  }\n}\n\nasync function readPersonaPresentation(\n  fs: FileSystem,\n  personaRoot: string,\n  personaDirectory: string,\n  context: IoContext,\n): Promise<PersonaPresentation> {\n  const frontMatter = await readPersonaFrontMatter(fs, personaRoot, personaDirectory, context);\n  if (!frontMatter) return {};\n  const icon =\n    frontMatter.icon === undefined\n      ? undefined\n      : await readPersonaIconAsync(fs, path.join(personaRoot, personaDirectory), frontMatter.icon, context);\n  return presentationFrom(frontMatter, icon);\n}\n\n/** Builds the persona system-prompt block, or undefined when nothing is readable. */\nexport async function buildPersonaPromptAsync(\n  fs: FileSystem,\n  personaRoot: string,\n  personaDirectory: string,\n  context: IoContext,\n): Promise<string | undefined> {\n  const sections: string[] = [];\n  const personaPath = await realPath(fs, path.join(personaRoot, personaDirectory), context);\n  for (const file of PERSONA_FILES) {\n    const filePath = path.join(personaPath, file);\n    if (!(await exists(fs, filePath, context))) continue;\n    const realFilePath = await realPath(fs, filePath, context);\n    assertPersonaFileInside(personaPath, realFilePath, personaDirectory, file);\n    const content = personaFileSection(file, getOrThrow(await fs.readTextFile(realFilePath, context)));\n    if (content) sections.push(content);\n  }\n  return personaPromptFromSections(personaDirectory, sections);\n}\n\nasync function parseProfile(\n  fs: FileSystem,\n  personaRoot: string,\n  configuredRoots: readonly string[],\n  name: string,\n  value: unknown,\n  context: IoContext,\n): Promise<AgentProfile> {\n  const draft = draftProfileEntry(personaRoot, configuredRoots, name, value);\n  if (!(await isDirectory(fs, draft.personaPath, context))) throw missingPersona(name, draft.persona);\n  const realPersonaPath = await realPath(fs, draft.personaPath, context);\n  let allowed = false;\n  for (const root of draft.lexicalRoots) {\n    if (isPathInside(await realPath(fs, root, context), realPersonaPath)) {\n      allowed = true;\n      break;\n    }\n  }\n  if (!allowed) throw outsideAllowedRoot(name);\n  if (!(await buildPersonaPromptAsync(fs, personaRoot, draft.persona, context))) {\n    const declaresIdentity = (await readPersonaFrontMatter(fs, personaRoot, draft.persona, context)) !== undefined;\n    throw emptyPersona(name, draft.persona, declaresIdentity);\n  }\n  return profileFromDraft(draft, personaRoot, await readPersonaPresentation(fs, personaRoot, draft.persona, context));\n}\n\nasync function containsPersonaFile(fs: FileSystem, directory: string, context: IoContext): Promise<boolean> {\n  for (const file of PERSONA_FILES) {\n    const info = await fs.fileInfo(path.join(directory, file), context);\n    if (info.ok && info.value.kind === 'file') return true;\n  }\n  return false;\n}\n\n/** Reads the optional sidecar, which must be a regular file whose real path stays in the persona directory. */\nasync function readSidecar(\n  fs: FileSystem,\n  name: string,\n  realDirectory: string,\n  context: IoContext,\n): Promise<ProfileSidecar> {\n  const filePath = path.join(realDirectory, PROFILE_SIDECAR_FILE);\n  if (!(await exists(fs, filePath, context))) return { env: {} };\n  const realFilePath = await realPath(fs, filePath, context);\n  if (\n    !isPathInside(realDirectory, realFilePath) ||\n    getOrThrow(await fs.fileInfo(realFilePath, context)).kind !== 'file'\n  ) {\n    throw new Error(`Profile \"${name}\" ${PROFILE_SIDECAR_FILE} must be a file inside the persona directory`);\n  }\n  return parseProfileSidecar(name, getOrThrow(await fs.readTextFile(realFilePath, context)));\n}\n\nasync function discoverProfile(\n  fs: FileSystem,\n  directory: string,\n  configuredRoot: string,\n  personaRoot: string,\n  diagnostics: ProfileDiagnostic[],\n  context: IoContext,\n): Promise<AgentProfile | undefined> {\n  if (!(await containsPersonaFile(fs, directory, context))) return undefined;\n  const name = path.basename(directory);\n  try {\n    const realConfiguredRoot = await realPath(fs, configuredRoot, context);\n    const realDirectory = await realPath(fs, directory, context);\n    if (!isPathInside(realConfiguredRoot, realDirectory)) return undefined;\n    const persona = path.relative(personaRoot, directory) || '.';\n    if (!(await buildPersonaPromptAsync(fs, personaRoot, persona, context))) return undefined;\n    let sidecar: ProfileSidecar;\n    try {\n      sidecar = await readSidecar(fs, name, realDirectory, context);\n    } catch (error) {\n      // A bad sidecar skips only this profile, visibly, rather than failing the catalog.\n      diagnostics.push(sidecarDiagnostic(path.join(directory, PROFILE_SIDECAR_FILE), name, error));\n      return undefined;\n    }\n    return {\n      name,\n      persona,\n      personaRoot,\n      ...sidecar,\n      ...(await readPersonaPresentation(fs, personaRoot, persona, context)),\n    };\n  } catch {\n    // Automatic discovery ignores unreadable or unsafe candidates; explicit entries remain fatal.\n    return undefined;\n  }\n}\n\nasync function discoverProfileRoot(\n  fs: FileSystem,\n  root: string,\n  personaRoot: string,\n  diagnostics: ProfileDiagnostic[],\n  context: IoContext,\n): Promise<AgentProfile[]> {\n  if (!(await isDirectory(fs, root, context))) throw new Error(`Configured profile root is not a directory: ${root}`);\n\n  const rootProfile = await discoverProfile(fs, root, root, personaRoot, diagnostics, context);\n  if (rootProfile) return [rootProfile];\n\n  const directories = getOrThrow(await fs.listDir(root, context))\n    .filter((entry) => entry.kind === 'directory')\n    .sort((left, right) => left.name.localeCompare(right.name));\n  const profiles: AgentProfile[] = [];\n  for (const entry of directories) {\n    const profile = await discoverProfile(fs, path.join(root, entry.name), root, personaRoot, diagnostics, context);\n    if (profile) profiles.push(profile);\n  }\n  return profiles;\n}\n\nasync function readProfileLayers(\n  fs: FileSystem,\n  repoRoot: string,\n  context: IoContext,\n  homeDirectory: string,\n): Promise<ProfileConfigLayer[]> {\n  const sources = await readPoConfigSourcesAsync<unknown>(fs, PROFILES_FILE, repoRoot, context, homeDirectory);\n  return sources.map(parseProfileLayer);\n}\n\nasync function profilesFromLayers(\n  fs: FileSystem,\n  layers: readonly ProfileConfigLayer[],\n  context: IoContext,\n  diagnostics: ProfileDiagnostic[] = [],\n): Promise<AgentProfile[]> {\n  const byName = new Map<string, AgentProfile>();\n  for (const layer of layers) {\n    for (const root of layer.roots) {\n      for (const profile of await discoverProfileRoot(fs, root, layer.baseDirectory, diagnostics, context)) {\n        byName.set(profile.name, profile);\n      }\n    }\n  }\n  for (const layer of layers) {\n    for (const [name, value] of Object.entries(layer.entries)) {\n      byName.set(name, await parseProfile(fs, layer.baseDirectory, layer.roots, name, value, context));\n    }\n  }\n  return sortProfiles(byName);\n}\n\n/**\n * Loads profiles from the global and repository configs, repository last.\n *\n * Configured roots accumulate and inspect themselves or their direct-child\n * directories for persona files. Later discoveries replace earlier names, and\n * explicit entries replace discoveries. Legacy flat profile mappings remain\n * accepted as explicit entries.\n */\nexport async function loadProfilesAsync(\n  fs: FileSystem,\n  repoRoot: string,\n  context: IoContext,\n  homeDirectory: string = nodeHost.homeDirectory(),\n): Promise<AgentProfile[]> {\n  return profilesFromLayers(fs, await readProfileLayers(fs, repoRoot, context, homeDirectory), context);\n}\n\n/** The profile catalog plus the name a launch starts on when the caller names none. */\nexport async function loadProfileCatalogAsync(\n  fs: FileSystem,\n  repoRoot: string,\n  context: IoContext,\n  homeDirectory: string = nodeHost.homeDirectory(),\n): Promise<{ profiles: AgentProfile[]; defaultProfile?: string; diagnostics?: ProfileDiagnostic[] }> {\n  const layers = await readProfileLayers(fs, repoRoot, context, homeDirectory);\n  const diagnostics: ProfileDiagnostic[] = [];\n  const profiles = await profilesFromLayers(fs, layers, context, diagnostics);\n  const defaultProfile = catalogDefaultProfile(layers, profiles);\n  return {\n    profiles,\n    ...(defaultProfile === undefined ? {} : { defaultProfile }),\n    ...(diagnostics.length === 0 ? {} : { diagnostics }),\n  };\n}\n\n/** Resolves one selected profile and fails clearly when its name is unknown. */\nexport async function resolveProfileAsync(\n  fs: FileSystem,\n  repoRoot: string,\n  name: string,\n  context: IoContext,\n  homeDirectory?: string,\n): Promise<AgentProfile> {\n  const profiles = await loadProfilesAsync(fs, repoRoot, context, homeDirectory);\n  const profile = profiles.find((candidate) => candidate.name === name);\n  if (!profile) throw new Error(`Unknown profile: ${name}`);\n  return profile;\n}\n\nexport async function listProfileNamesAsync(\n  fs: FileSystem,\n  repoRoot: string,\n  context: IoContext,\n  homeDirectory?: string,\n): Promise<string[]> {\n  return (await loadProfilesAsync(fs, repoRoot, context, homeDirectory)).map((profile) => profile.name);\n}\n\nexport { PERSONA_FILES, applyProfileEnvironment, inlineProfile, replaceProfileEnvironment } from './core';\nexport type { AgentProfile, InlineProfileInput, ProfileDiagnostic } from './core';\nexport { buildPersonaPrompt, listProfileNames, loadProfileCatalog, loadProfiles, resolveProfile } from './sync';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,QAAQ;AACd,MAAM,aAAa;CAAC;CAAQ;CAAQ;AAAO;AAE3C,SAASA,WAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,UAAU,OAAkD;CACnE,IAAI,CAACA,WAAS,KAAK,GAAG,OAAO,KAAA;CAC7B,MAAM,QAAQ,OAAO,MAAM,UAAU,YAAY,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,IAAI,MAAM,MAAM,KAAK,IAAI,KAAA;CACtG,MAAM,OAAO,OAAO,MAAM,SAAS,YAAY,OAAO,SAAS,MAAM,IAAI,IAAI,MAAM,OAAO,KAAA;CAC1F,IAAI,UAAU,KAAA,KAAa,SAAS,KAAA,GAAW,OAAO,KAAA;CACtD,OAAO;EAAE,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM;EAAI,GAAI,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,KAAK;CAAG;AAC9F;AAEA,SAAS,gBAAgB,QAAiE;CACxF,MAAM,OAAO,OAAO,OAAO,SAAS,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,IAAI,OAAO,KAAK,KAAK,IAAI,KAAA;CACrG,MAAM,OAAO,OAAO,OAAO,SAAS,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,IAAI,OAAO,KAAK,KAAK,IAAI,KAAA;CACrG,MAAM,QAAQ,UAAU,OAAO,KAAK;CACpC,IAAI,SAAS,KAAA,KAAa,SAAS,KAAA,KAAa,UAAU,KAAA,GAAW,OAAO,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