@agimon-ai/po-config 0.0.0-alpha.39 → 0.0.0-alpha.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/extensions/server.cjs +1 -1
  2. package/dist/extensions/server.mjs +1 -1
  3. package/dist/{index-CSnglMah.d.mts → index-BWne-gYh.d.mts} +16 -2
  4. package/dist/index-BWne-gYh.d.mts.map +1 -0
  5. package/dist/index.cjs +2 -2
  6. package/dist/index.d.mts +2 -2
  7. package/dist/index.mjs +2 -2
  8. package/dist/{profiles-Ca8Ughzf.cjs → profiles-DjZjfvzV.cjs} +30 -1
  9. package/dist/profiles-DjZjfvzV.cjs.map +1 -0
  10. package/dist/{profiles-DHW98Cn4.mjs → profiles-uZLR4_HJ.mjs} +25 -2
  11. package/dist/profiles-uZLR4_HJ.mjs.map +1 -0
  12. package/dist/profiles.cjs +2 -1
  13. package/dist/profiles.d.mts +3 -3
  14. package/dist/profiles.mjs +1 -1
  15. package/dist/selectionSwitch.cjs +7 -6
  16. package/dist/selectionSwitch.cjs.map +1 -1
  17. package/dist/selectionSwitch.d.mts +3 -2
  18. package/dist/selectionSwitch.d.mts.map +1 -1
  19. package/dist/selectionSwitch.mjs +7 -6
  20. package/dist/selectionSwitch.mjs.map +1 -1
  21. package/dist/{settingsApi-CkrwQkKU.cjs → settingsApi-BHq8b-3z.cjs} +2 -2
  22. package/dist/{settingsApi-CkrwQkKU.cjs.map → settingsApi-BHq8b-3z.cjs.map} +1 -1
  23. package/dist/{settingsApi-CRSCi4JR.mjs → settingsApi-rhlv9p4K.mjs} +2 -2
  24. package/dist/{settingsApi-CRSCi4JR.mjs.map → settingsApi-rhlv9p4K.mjs.map} +1 -1
  25. package/dist/{sync-BQzTh13f.d.mts → sync-C3p_NDH3.d.mts} +2 -2
  26. package/dist/{sync-BQzTh13f.d.mts.map → sync-C3p_NDH3.d.mts.map} +1 -1
  27. package/package.json +4 -4
  28. package/dist/index-CSnglMah.d.mts.map +0 -1
  29. package/dist/profiles-Ca8Ughzf.cjs.map +0 -1
  30. package/dist/profiles-DHW98Cn4.mjs.map +0 -1
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_settingsApi = require("../settingsApi-CkrwQkKU.cjs");
5
+ const require_settingsApi = require("../settingsApi-BHq8b-3z.cjs");
6
6
  const require_sessionConfig = require("../sessionConfig-CLFS1H8p.cjs");
7
7
  let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
8
8
  let _agimon_ai_po_core_mcpProjection = require("@agimon-ai/po-core/mcpProjection");
@@ -1,4 +1,4 @@
1
- import { t as createSettingsApi } from "../settingsApi-CRSCi4JR.mjs";
1
+ import { t as createSettingsApi } from "../settingsApi-rhlv9p4K.mjs";
2
2
  import { d as providePoConfigContext, o as createNativePoConfigContext } from "../sessionConfig-iUFOQJ8H.mjs";
3
3
  import { BACKGROUND_CONTEXT, requirePoFs, withAbortSignal } from "@agimon-ai/po-core/platform";
4
4
  import { PO_MCP_PROJECTION_SERVICE, createDisabledPoMcpProjection, createPoMcpProjectionService, isPoMcpProjection } from "@agimon-ai/po-core/mcpProjection";
@@ -52,6 +52,18 @@ interface AgentProfile {
52
52
  identity?: PersonaIdentity;
53
53
  /** Narrowly scoped TTS override declared alongside the identity. */
54
54
  voice?: PersonaVoiceOverride;
55
+ /** Persona prompt for a profile served from memory; directory profiles build theirs from disk. */
56
+ personaPrompt?: string;
57
+ }
58
+ /** A profile contributed from memory, validated with the directory profile rules. */
59
+ interface InlineProfileInput {
60
+ name: string;
61
+ /** Stable origin label, shown in place of a persona directory. */
62
+ source: string;
63
+ /** Persona file text keyed by file name; only PERSONA_FILES are read. */
64
+ files: Readonly<Record<string, string>>;
65
+ env?: unknown;
66
+ integration?: unknown;
55
67
  }
56
68
  /** A discovered profile that was skipped. Messages name keys and files, never values. */
57
69
  interface ProfileDiagnostic {
@@ -59,6 +71,8 @@ interface ProfileDiagnostic {
59
71
  profile: string;
60
72
  message: string;
61
73
  }
74
+ /** Builds a profile from in-memory persona text. Nothing is read from disk, so it has no persona root or icon. */
75
+ declare function inlineProfile(input: InlineProfileInput): AgentProfile;
62
76
  /** Applies profile environment defaults and returns only the values it contributed. */
63
77
  declare function applyProfileEnvironment(environment: NodeJS.ProcessEnv, defaults: Record<string, string>): Record<string, string>;
64
78
  /** Replaces environment defaults previously contributed by another profile. */
@@ -87,5 +101,5 @@ declare function loadProfileCatalogAsync(fs: FileSystem, repoRoot: string, conte
87
101
  declare function resolveProfileAsync(fs: FileSystem, repoRoot: string, name: string, context: IoContext, homeDirectory?: string): Promise<AgentProfile>;
88
102
  declare function listProfileNamesAsync(fs: FileSystem, repoRoot: string, context: IoContext, homeDirectory?: string): Promise<string[]>;
89
103
  //#endregion
90
- export { resolveProfileAsync as a, ProfileDiagnostic as c, ProfileBrowserBinding as d, ProfileBrowserMode as f, ProfileSecretReference as h, loadProfilesAsync as i, applyProfileEnvironment as l, ProfileSecretPurpose as m, listProfileNamesAsync as n, AgentProfile as o, ProfileIntegrationBinding as p, loadProfileCatalogAsync as r, PERSONA_FILES as s, buildPersonaPromptAsync as t, replaceProfileEnvironment as u };
91
- //# sourceMappingURL=index-CSnglMah.d.mts.map
104
+ export { ProfileSecretReference as _, resolveProfileAsync as a, PERSONA_FILES as c, inlineProfile as d, replaceProfileEnvironment as f, ProfileSecretPurpose as g, ProfileIntegrationBinding as h, loadProfilesAsync as i, ProfileDiagnostic as l, ProfileBrowserMode as m, listProfileNamesAsync as n, AgentProfile as o, ProfileBrowserBinding as p, loadProfileCatalogAsync as r, InlineProfileInput as s, buildPersonaPromptAsync as t, applyProfileEnvironment as u };
105
+ //# sourceMappingURL=index-BWne-gYh.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BWne-gYh.d.mts","names":[],"sources":["../src/services/profileBinding/type.ts","../src/services/profiles/core.ts","../src/services/profiles/index.ts"],"mappings":";;;;KACY;;KAGA;;UAGK;WACN;WACA;;WAEA,mBAAmB;;WAEnB;;UAGM;;WAEN;WACA;WACA,OAAO;;WAEP;;;UAIM;WACN;WACA;WACA;WACA;WACA,SAAS,SAAS,eAAe;WACjC,UAAU;;;;;cCtBR;UAKI;EACf;;EAEA;;;;;EAKA;;EAEA,KAAK;;EAEL,cAAc;;EAEd,WAAW;;EAEX,QAAQ;;EAER;;;UAIe;EACf;;EAEA;;EAEA,OAAO,SAAS;EAChB;EACA;;;UAwBe;EACf;EACA;EACA;;;iBAmPc,cAAc,OAAO,qBAAqB;;iBA6C1C,wBACd,aAAa,OAAO,YACpB,UAAU,yBACT;;iBAWa,0BACd,aAAa,OAAO,YACpB,UAAU,wBACV,MAAM,yBACL;;;KCtVE,YAAY,WAAW;;iBAkDN,wBACpB,IAAI,YACJ,qBACA,0BACA,SAAS,YACR;;;;;;;;;iBAuKmB,kBACpB,IAAI,YACJ,kBACA,SAAS,WACT,yBACC,QAAQ;;iBAKW,wBACpB,IAAI,YACJ,kBACA,SAAS,WACT,yBACC;EAAU,UAAU;EAAgB;EAAyB,cAAc;;;iBAaxD,oBACpB,IAAI,YACJ,kBACA,cACA,SAAS,WACT,yBACC,QAAQ;iBAOW,sBACpB,IAAI,YACJ,kBACA,SAAS,WACT,yBACC"}
package/dist/index.cjs CHANGED
@@ -9,10 +9,10 @@ const require_layeredConfig = require("./layeredConfig-Bvcuat-o.cjs");
9
9
  const require_domains = require("./domains-l6GiaShf.cjs");
10
10
  const require_harnessState = require("./harnessState-CQBNDL1D.cjs");
11
11
  const require_harnessStore = require("./harnessStore-Dgn3T4sR.cjs");
12
- const require_settingsApi = require("./settingsApi-CkrwQkKU.cjs");
12
+ const require_settingsApi = require("./settingsApi-BHq8b-3z.cjs");
13
13
  const require_piConfig = require("./piConfig-cluCie5i.cjs");
14
14
  const require_majorModes = require("./majorModes-Ck_usJaY.cjs");
15
- const require_profiles = require("./profiles-Ca8Ughzf.cjs");
15
+ const require_profiles = require("./profiles-DjZjfvzV.cjs");
16
16
  const require_init = require("./init-Dotk_UW-.cjs");
17
17
  require("./config-zZz80Mh5.cjs");
18
18
  const require_sessionConfig = require("./sessionConfig-CLFS1H8p.cjs");
package/dist/index.d.mts CHANGED
@@ -11,8 +11,8 @@ import { _ as HARNESS_STATE_POINTER, a as requireHarnessPaths, b as resetHarness
11
11
  import { a as loadPiConfigAsync, c as piConfigPaths, d as MIN_IMAGE_MAX_DIMENSION, f as PiImageSettings, h as parsePiImageSettings, i as loadPiConfig, l as piImageSettingsPath, m as clampImageMaxDimension, o as loadPiImageSettings, p as PiImageSettingsUpdate, s as savePiImageSettings, u as DEFAULT_IMAGE_MAX_DIMENSION } from "./index-7RuIAWX1.mjs";
12
12
  import { a as GLOBAL_PO_SEED_FILES, c as PO_CONFIG_TEMPLATES, d as RepositoryPoInitResult, i as initializeRepositoryPoConfig, l as REPOSITORY_PO_CONFIG_TEMPLATES, r as initializeGlobalPoConfig, s as GlobalPoInitResult, u as RepositoryPoInitOptions } from "./index-nVcEC1jO.mjs";
13
13
  import { _ as layerEntries, a as loadMajorModesConfig, c as LayerPackage, d as MajorModeDefinition, f as MajorModesConfig, g as isLocalPackageSpecifier, h as ResolvedPackageConfiguration, i as readPackageConfigurations, l as LayerPackageConfig, m as ResolvedLayerDefinition, o as loadMajorModesConfigLenient, p as PackageNameResolver, s as LayerDefinition, u as LayerResolvers, v as resolveLayers, y as resolvePackageConfigurations } from "./index-B2WH1kjo.mjs";
14
- import { l as applyProfileEnvironment, o as AgentProfile, s as PERSONA_FILES, u as replaceProfileEnvironment } from "./index-CSnglMah.mjs";
15
- import { a as resolveProfile, i as loadProfiles, n as listProfileNames, t as buildPersonaPrompt } from "./sync-BQzTh13f.mjs";
14
+ import { c as PERSONA_FILES, f as replaceProfileEnvironment, o as AgentProfile, u as applyProfileEnvironment } from "./index-BWne-gYh.mjs";
15
+ import { a as resolveProfile, i as loadProfiles, n as listProfileNames, t as buildPersonaPrompt } from "./sync-C3p_NDH3.mjs";
16
16
  import { _ as supersedePoConfigTransition, a as appendPoConfigSelection, c as createPoConfigContextAsync, d as providePoConfigContext, f as readPoConfigContextGeneration, g as requirePoConfigContext, h as replacePoConfigContext, i as acknowledgePoConfigTransition, l as freezePoConfigContext, m as readPoConfigSelection, n as PO_CONFIG_TRANSITION_ENTRY_TYPE, o as appendPoConfigTransition, p as readPoConfigPendingSelection, r as PoConfigSelection, s as createPoConfigContext, t as PO_CONFIG_ENTRY_TYPE } from "./index-SPak8lzb.mjs";
17
17
  import { FileSystem } from "@agimon-ai/po-core/platform";
18
18
  import { PoApi } from "@agimon-ai/po-core/packageApi";
package/dist/index.mjs CHANGED
@@ -8,10 +8,10 @@ import { r as PO_DIR } from "./layeredConfig-BgzntWIc.mjs";
8
8
  import { _ as findPluginManifestPathAsync, b as isRemotePluginSource, c as resolvePluginDirectories, g as expandDomainNames, h as domainCompletionPrefix, l as resolvePluginEntries, m as domainCompletionItems, o as listDomainNames, s as loadDomains, u as resolveSharedSkills, v as findPluginManifestPath, x as pluginDirectoryForSource, y as MARKETPLACE_MANIFEST_RELATIVE_PATHS } from "./domains-BGgj0mjd.mjs";
9
9
  import { i as readHarnessState, n as HARNESS_STATE_KEYS, r as projectHarnessEnvironment, t as FILE_ONLY_STATE_FIELDS } from "./harnessState-ufE-npBa.mjs";
10
10
  import { _ as HARNESS_STATE_POINTER, a as requireHarnessPaths, d as getHarnessState, f as getSessionHarnessState, g as updateHarnessState, h as snapshotHarnessState, l as createHarnessSession, m as restoreHarnessStateSnapshot, o as requireHarnessRoot, p as loadHarnessState, r as harnessRoot, u as disposeHarnessState, v as resetHarnessStore } from "./harnessStore-yqKUx-kP.mjs";
11
- import { t as createSettingsApi } from "./settingsApi-CRSCi4JR.mjs";
11
+ import { t as createSettingsApi } from "./settingsApi-rhlv9p4K.mjs";
12
12
  import { a as loadPiConfigAsync, c as piConfigPaths, d as MIN_IMAGE_MAX_DIMENSION, f as clampImageMaxDimension, i as loadPiConfig, l as piImageSettingsPath, o as loadPiImageSettings, p as parsePiImageSettings, s as savePiImageSettings, u as DEFAULT_IMAGE_MAX_DIMENSION } from "./piConfig-Bq36PQFF.mjs";
13
13
  import { a as loadMajorModesConfigLenient, c as resolveLayers, i as loadMajorModesConfig, l as resolvePackageConfigurations, o as isLocalPackageSpecifier, r as readPackageConfigurations, s as layerEntries } from "./majorModes-D-R9rBjJ.mjs";
14
- import { d as PERSONA_FILES, f as applyProfileEnvironment, l as loadProfiles, o as buildPersonaPrompt, p as replaceProfileEnvironment, s as listProfileNames, u as resolveProfile } from "./profiles-DHW98Cn4.mjs";
14
+ import { d as PERSONA_FILES, f as applyProfileEnvironment, l as loadProfiles, m as replaceProfileEnvironment, o as buildPersonaPrompt, s as listProfileNames, u as resolveProfile } from "./profiles-uZLR4_HJ.mjs";
15
15
  import { a as GLOBAL_PO_SEED_FILES, i as initializeRepositoryPoConfig, o as PO_CONFIG_TEMPLATES, r as initializeGlobalPoConfig, s as REPOSITORY_PO_CONFIG_TEMPLATES } from "./init-COTYNRQ9.mjs";
16
16
  import { t as PO_CONFIG_SERVICE } from "./config-BBvn_ZLP.mjs";
17
17
  import { _ as supersedePoConfigTransition, a as appendPoConfigTransition, c as createPoConfigContextAsync, d as providePoConfigContext, f as readPoConfigContextGeneration, g as requirePoConfigContext, h as replacePoConfigContext, i as appendPoConfigSelection, l as freezePoConfigContext, m as readPoConfigSelection, n as PO_CONFIG_TRANSITION_ENTRY_TYPE, p as readPoConfigPendingSelection, r as acknowledgePoConfigTransition, s as createPoConfigContext, t as PO_CONFIG_ENTRY_TYPE } from "./sessionConfig-iUFOQJ8H.mjs";
@@ -474,6 +474,29 @@ function personaPromptFromSections(personaDirectory, sections) {
474
474
  if (sections.length === 0) return void 0;
475
475
  return [`[PERSONA] You are operating as the person described below (source: ${personaDirectory}).`, ...sections].join("\n\n");
476
476
  }
477
+ /** Builds a profile from in-memory persona text. Nothing is read from disk, so it has no persona root or icon. */
478
+ function inlineProfile(input) {
479
+ const { name, source, files } = input;
480
+ const read = (file) => Object.hasOwn(files, file) ? files[file] : void 0;
481
+ const sections = PERSONA_FILES.flatMap((file) => {
482
+ const raw = read(file);
483
+ const section = raw === void 0 ? "" : personaFileSection(file, raw);
484
+ return section ? [section] : [];
485
+ });
486
+ const identityText = read(PERSONA_IDENTITY_FILE);
487
+ const frontMatter = identityText === void 0 ? void 0 : parsePersonaFrontMatter(identityText).frontMatter;
488
+ const personaPrompt = personaPromptFromSections(source, sections);
489
+ if (!personaPrompt) throw emptyPersona(name, source, frontMatter !== void 0);
490
+ return {
491
+ name,
492
+ persona: source,
493
+ personaRoot: "",
494
+ env: parseEnvironment(name, input.env),
495
+ ...input.integration === void 0 ? {} : { integration: parseProfileBinding(input.integration, `Profile "${name}" integration`) },
496
+ ...frontMatter === void 0 ? {} : presentationFrom(frontMatter, void 0),
497
+ personaPrompt
498
+ };
499
+ }
477
500
  function sortProfiles(byName) {
478
501
  return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));
479
502
  }
@@ -831,6 +854,12 @@ Object.defineProperty(exports, "buildPersonaPromptAsync", {
831
854
  return buildPersonaPromptAsync;
832
855
  }
833
856
  });
857
+ Object.defineProperty(exports, "inlineProfile", {
858
+ enumerable: true,
859
+ get: function() {
860
+ return inlineProfile;
861
+ }
862
+ });
834
863
  Object.defineProperty(exports, "listProfileNames", {
835
864
  enumerable: true,
836
865
  get: function() {
@@ -910,4 +939,4 @@ Object.defineProperty(exports, "resolveProfileAsync", {
910
939
  }
911
940
  });
912
941
 
913
- //# sourceMappingURL=profiles-Ca8Ughzf.cjs.map
942
+ //# sourceMappingURL=profiles-DjZjfvzV.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles-DjZjfvzV.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","import 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","import 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,UAA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B,kBACpB,IACA,UACA,SACA,gBAAwBC,4BAAAA,SAAS,cAAc,GACtB;CACzB,OAAO,mBAAmB,IAAI,MAAM,kBAAkB,IAAI,UAAU,SAAS,aAAa,GAAG,OAAO;AACtG;;AAGA,eAAsB,wBACpB,IACA,UACA,SACA,gBAAwBA,4BAAAA,SAAS,cAAc,GACoD;CACnG,MAAM,SAAS,MAAM,kBAAkB,IAAI,UAAU,SAAS,aAAa;CAC3E,MAAM,cAAmC,CAAC;CAC1C,MAAM,WAAW,MAAM,mBAAmB,IAAI,QAAQ,SAAS,WAAW;CAC1E,MAAM,iBAAiB,sBAAsB,QAAQ,QAAQ;CAC7D,OAAO;EACL;EACA,GAAI,mBAAmB,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe;EACzD,GAAI,YAAY,WAAW,IAAI,CAAC,IAAI,EAAE,YAAY;CACpD;AACF;;AAGA,eAAsB,oBACpB,IACA,UACA,MACA,SACA,eACuB;CAEvB,MAAM,WAAU,MADO,kBAAkB,IAAI,UAAU,SAAS,aAAa,EAAA,CACpD,MAAM,cAAc,UAAU,SAAS,IAAI;CACpE,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,oBAAoB,MAAM;CACxD,OAAO;AACT;AAEA,eAAsB,sBACpB,IACA,UACA,SACA,eACmB;CACnB,QAAQ,MAAM,kBAAkB,IAAI,UAAU,SAAS,aAAa,EAAA,CAAG,KAAK,YAAY,QAAQ,IAAI;AACtG"}
@@ -470,6 +470,29 @@ function personaPromptFromSections(personaDirectory, sections) {
470
470
  if (sections.length === 0) return void 0;
471
471
  return [`[PERSONA] You are operating as the person described below (source: ${personaDirectory}).`, ...sections].join("\n\n");
472
472
  }
473
+ /** Builds a profile from in-memory persona text. Nothing is read from disk, so it has no persona root or icon. */
474
+ function inlineProfile(input) {
475
+ const { name, source, files } = input;
476
+ const read = (file) => Object.hasOwn(files, file) ? files[file] : void 0;
477
+ const sections = PERSONA_FILES.flatMap((file) => {
478
+ const raw = read(file);
479
+ const section = raw === void 0 ? "" : personaFileSection(file, raw);
480
+ return section ? [section] : [];
481
+ });
482
+ const identityText = read(PERSONA_IDENTITY_FILE);
483
+ const frontMatter = identityText === void 0 ? void 0 : parsePersonaFrontMatter(identityText).frontMatter;
484
+ const personaPrompt = personaPromptFromSections(source, sections);
485
+ if (!personaPrompt) throw emptyPersona(name, source, frontMatter !== void 0);
486
+ return {
487
+ name,
488
+ persona: source,
489
+ personaRoot: "",
490
+ env: parseEnvironment(name, input.env),
491
+ ...input.integration === void 0 ? {} : { integration: parseProfileBinding(input.integration, `Profile "${name}" integration`) },
492
+ ...frontMatter === void 0 ? {} : presentationFrom(frontMatter, void 0),
493
+ personaPrompt
494
+ };
495
+ }
473
496
  function sortProfiles(byName) {
474
497
  return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));
475
498
  }
@@ -803,6 +826,6 @@ async function listProfileNamesAsync(fs, repoRoot, context, homeDirectory) {
803
826
  return (await loadProfilesAsync(fs, repoRoot, context, homeDirectory)).map((profile) => profile.name);
804
827
  }
805
828
  //#endregion
806
- export { parsePersonaFrontMatter as _, resolveProfileAsync as a, loadProfileCatalog as c, PERSONA_FILES as d, applyProfileEnvironment as f, readPersonaIcon as g, readPersonaIconAsync as h, loadProfilesAsync as i, loadProfiles as l, parseProfileBinding as m, listProfileNamesAsync as n, buildPersonaPrompt as o, replaceProfileEnvironment as p, loadProfileCatalogAsync as r, listProfileNames as s, buildPersonaPromptAsync as t, resolveProfile as u };
829
+ export { readPersonaIcon as _, resolveProfileAsync as a, loadProfileCatalog as c, PERSONA_FILES as d, applyProfileEnvironment as f, readPersonaIconAsync as g, parseProfileBinding as h, loadProfilesAsync as i, loadProfiles as l, replaceProfileEnvironment as m, listProfileNamesAsync as n, buildPersonaPrompt as o, inlineProfile as p, loadProfileCatalogAsync as r, listProfileNames as s, buildPersonaPromptAsync as t, resolveProfile as u, parsePersonaFrontMatter as v };
807
830
 
808
- //# sourceMappingURL=profiles-DHW98Cn4.mjs.map
831
+ //# sourceMappingURL=profiles-uZLR4_HJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles-uZLR4_HJ.mjs","names":["isRecord","parseYaml","PARENT_DIRECTORY","Buffer","parseYaml","parseProfile","readPersonaFrontMatter","readPersonaPresentation","containsPersonaFile","readSidecar","discoverProfile","discoverProfileRoot","readProfileLayers","profilesFromLayers"],"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","import 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","import 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,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AA,CAAG,KAAK,YAAY,QAAQ,IAAI;AACtG"}
package/dist/profiles.cjs CHANGED
@@ -1,9 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_profiles = require("./profiles-Ca8Ughzf.cjs");
2
+ const require_profiles = require("./profiles-DjZjfvzV.cjs");
3
3
  exports.PERSONA_FILES = require_profiles.PERSONA_FILES;
4
4
  exports.applyProfileEnvironment = require_profiles.applyProfileEnvironment;
5
5
  exports.buildPersonaPrompt = require_profiles.buildPersonaPrompt;
6
6
  exports.buildPersonaPromptAsync = require_profiles.buildPersonaPromptAsync;
7
+ exports.inlineProfile = require_profiles.inlineProfile;
7
8
  exports.listProfileNames = require_profiles.listProfileNames;
8
9
  exports.listProfileNamesAsync = require_profiles.listProfileNamesAsync;
9
10
  exports.loadProfileCatalog = require_profiles.loadProfileCatalog;