@agimon-ai/po-config 0.0.0-alpha.2 → 0.0.0-alpha.21
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.
- package/LICENSE +149 -21
- package/README.md +11 -11
- package/dist/agentPluginMcp.cjs +313 -134
- package/dist/agentPluginMcp.cjs.map +1 -1
- package/dist/agentPluginMcp.d.mts +22 -4
- package/dist/agentPluginMcp.d.mts.map +1 -1
- package/dist/agentPluginMcp.mjs +312 -134
- package/dist/agentPluginMcp.mjs.map +1 -1
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/atomicJson-D3MHqnLW.cjs +59 -0
- package/dist/atomicJson-D3MHqnLW.cjs.map +1 -0
- package/dist/atomicJson-Dj3rlZbD.mjs +40 -0
- package/dist/atomicJson-Dj3rlZbD.mjs.map +1 -0
- package/dist/atomicJson.cjs +4 -2
- package/dist/atomicJson.d.mts +2 -2
- package/dist/atomicJson.mjs +3 -2
- package/dist/{index-BT29GZx5.d.mts → completion-Ba0TiBHa.d.mts} +58 -27
- package/dist/completion-Ba0TiBHa.d.mts.map +1 -0
- package/dist/config-BBvn_ZLP.mjs +1 -0
- package/dist/config-Cdybp9rT.cjs +155 -0
- package/dist/config-Cdybp9rT.cjs.map +1 -0
- package/dist/config-Cxc2xw54.mjs +112 -0
- package/dist/config-Cxc2xw54.mjs.map +1 -0
- package/dist/{config-D2HbBLzo.d.mts → config-pxC7FyUJ.d.mts} +33 -33
- package/dist/config-pxC7FyUJ.d.mts.map +1 -0
- package/dist/config.cjs +21 -17
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +4 -3
- package/dist/{configPolicy-Ce1QKDxa.cjs → configPolicy-CowlLhK1.cjs} +99 -99
- package/dist/configPolicy-CowlLhK1.cjs.map +1 -0
- package/dist/{configPolicy-DCQgF5-f.mjs → configPolicy-DueX0k6i.mjs} +84 -84
- package/dist/configPolicy-DueX0k6i.mjs.map +1 -0
- package/dist/configSchema.d.mts +2 -2
- package/dist/configWriter-DCASRzr-.mjs +180 -0
- package/dist/configWriter-DCASRzr-.mjs.map +1 -0
- package/dist/configWriter-DGO0gmXo.cjs +218 -0
- package/dist/configWriter-DGO0gmXo.cjs.map +1 -0
- package/dist/configWriter.cjs +7 -4
- package/dist/configWriter.d.mts +2 -2
- package/dist/configWriter.mjs +1 -2
- package/dist/core-B0Qg0Qq2.cjs +224 -0
- package/dist/core-B0Qg0Qq2.cjs.map +1 -0
- package/dist/core-DKWW9gkh.mjs +139 -0
- package/dist/core-DKWW9gkh.mjs.map +1 -0
- package/dist/{domains-DGCb7uMC.cjs → domains-CiDUsRiX.cjs} +473 -171
- package/dist/domains-CiDUsRiX.cjs.map +1 -0
- package/dist/{domains-BroCVHrS.mjs → domains-IlieGHaY.mjs} +437 -170
- package/dist/domains-IlieGHaY.mjs.map +1 -0
- package/dist/domains.cjs +9 -3
- package/dist/domains.d.mts +3 -3
- package/dist/domains.mjs +3 -3
- package/dist/extensions/mcp-ui.mjs +1 -1
- package/dist/extensions/mcp-ui.mjs.map +1 -1
- package/dist/extensions/mcp.cjs +3 -3
- package/dist/extensions/mcp.cjs.map +1 -1
- package/dist/extensions/mcp.d.mts +1 -1
- package/dist/extensions/mcp.mjs +2 -2
- package/dist/extensions/mcp.mjs.map +1 -1
- package/dist/extensions/server.cjs +55 -47
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts +2 -2
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +56 -48
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/{harnessState-Dn_S7fB9.mjs → harnessState-8lZda_8r.mjs} +2 -2
- package/dist/{harnessState-Dn_S7fB9.mjs.map → harnessState-8lZda_8r.mjs.map} +1 -1
- package/dist/{harnessState-CCyBeutB.cjs → harnessState-BrmH0lG5.cjs} +2 -2
- package/dist/{harnessState-CCyBeutB.cjs.map → harnessState-BrmH0lG5.cjs.map} +1 -1
- package/dist/harnessState.cjs +1 -1
- package/dist/harnessState.d.mts +1 -1
- package/dist/harnessState.mjs +1 -2
- package/dist/{harnessStore-CJSxdSkV.cjs → harnessStore-BinxGITh.cjs} +189 -81
- package/dist/harnessStore-BinxGITh.cjs.map +1 -0
- package/dist/{harnessStore-CltwLB7M.mjs → harnessStore-w8zHmJ_H.mjs} +160 -82
- package/dist/harnessStore-w8zHmJ_H.mjs.map +1 -0
- package/dist/harnessStore.cjs +6 -1
- package/dist/harnessStore.d.mts +2 -2
- package/dist/harnessStore.mjs +1 -2
- package/dist/index-7RuIAWX1.d.mts +63 -0
- package/dist/index-7RuIAWX1.d.mts.map +1 -0
- package/dist/{index-CkDDvVQt.d.mts → index-BNcG0voG.d.mts} +61 -16
- package/dist/index-BNcG0voG.d.mts.map +1 -0
- package/dist/{index-Dy_-m7gx.d.mts → index-BTOU4XiI.d.mts} +3 -3
- package/dist/{index-Dy_-m7gx.d.mts.map → index-BTOU4XiI.d.mts.map} +1 -1
- package/dist/index-COokUToB.d.mts +83 -0
- package/dist/index-COokUToB.d.mts.map +1 -0
- package/dist/index-D3vGEYup.d.mts +135 -0
- package/dist/index-D3vGEYup.d.mts.map +1 -0
- package/dist/{index-Ch7ptOkW.d.mts → index-DNEK9W6n.d.mts} +26 -16
- package/dist/index-DNEK9W6n.d.mts.map +1 -0
- package/dist/index-D_OtYtsl.d.mts +37 -0
- package/dist/index-D_OtYtsl.d.mts.map +1 -0
- package/dist/{index-DNk4q0Qm.d.mts → index-Nbj2iQWw.d.mts} +19 -25
- package/dist/index-Nbj2iQWw.d.mts.map +1 -0
- package/dist/{index-CEUc7m16.d.mts → index-dYgF03lE.d.mts} +82 -32
- package/dist/index-dYgF03lE.d.mts.map +1 -0
- package/dist/index-fTuf8tVH.d.mts +34 -0
- package/dist/index-fTuf8tVH.d.mts.map +1 -0
- package/dist/index-nVcEC1jO.d.mts +62 -0
- package/dist/index-nVcEC1jO.d.mts.map +1 -0
- package/dist/index.cjs +81 -59
- package/dist/index.d.mts +16 -15
- package/dist/index.mjs +17 -15
- package/dist/{init-Cd3Ki6Ub.cjs → init-BdZ-gqqk.cjs} +209 -59
- package/dist/init-BdZ-gqqk.cjs.map +1 -0
- package/dist/{init-DVzhiCUE.mjs → init-DG7MxGxC.mjs} +187 -48
- package/dist/init-DG7MxGxC.mjs.map +1 -0
- package/dist/init.cjs +8 -6
- package/dist/init.d.mts +2 -2
- package/dist/init.mjs +1 -2
- package/dist/layeredConfig-BbkoIEfM.mjs +95 -0
- package/dist/layeredConfig-BbkoIEfM.mjs.map +1 -0
- package/dist/layeredConfig-Bs18dXQG.cjs +127 -0
- package/dist/layeredConfig-Bs18dXQG.cjs.map +1 -0
- package/dist/layeredConfig.cjs +5 -4
- package/dist/layeredConfig.d.mts +7 -2
- package/dist/layeredConfig.d.mts.map +1 -0
- package/dist/layeredConfig.mjs +1 -2
- package/dist/{majorModes-D1Itd8SN.mjs → majorModes-B8Km83e1.mjs} +130 -23
- package/dist/majorModes-B8Km83e1.mjs.map +1 -0
- package/dist/{majorModes-DnNSH9ZK.cjs → majorModes-CLccNMZt.cjs} +147 -22
- package/dist/majorModes-CLccNMZt.cjs.map +1 -0
- package/dist/majorModes.cjs +4 -1
- package/dist/majorModes.d.mts +2 -2
- package/dist/majorModes.mjs +1 -2
- package/dist/{piConfig-qGyCbcVj.mjs → piConfig-Bq36PQFF.mjs} +104 -69
- package/dist/piConfig-Bq36PQFF.mjs.map +1 -0
- package/dist/{piConfig-Bx26HMb_.d.mts → piConfig-C9rGUqPe.d.mts} +3 -3
- package/dist/{piConfig-Bx26HMb_.d.mts.map → piConfig-C9rGUqPe.d.mts.map} +1 -1
- package/dist/{piConfig-CCBdZXQr.cjs → piConfig-cluCie5i.cjs} +122 -70
- package/dist/piConfig-cluCie5i.cjs.map +1 -0
- package/dist/piConfig.cjs +4 -1
- package/dist/piConfig.d.mts +2 -2
- package/dist/piConfig.mjs +1 -2
- package/dist/piContext.cjs +27 -16
- package/dist/piContext.d.mts +3 -3
- package/dist/piContext.mjs +1 -2
- package/dist/{profiles-DBcYg5nA.mjs → profiles-CHict0x-.mjs} +322 -101
- package/dist/profiles-CHict0x-.mjs.map +1 -0
- package/dist/{profiles-tpplXY4r.cjs → profiles-t2EUj0aB.cjs} +359 -102
- package/dist/profiles-t2EUj0aB.cjs.map +1 -0
- package/dist/profiles.cjs +7 -1
- package/dist/profiles.d.mts +27 -3
- package/dist/profiles.d.mts.map +1 -1
- package/dist/profiles.mjs +1 -2
- package/dist/selectionSwitch.cjs +88 -22
- package/dist/selectionSwitch.cjs.map +1 -1
- package/dist/selectionSwitch.d.mts +40 -18
- package/dist/selectionSwitch.d.mts.map +1 -1
- package/dist/selectionSwitch.mjs +85 -22
- package/dist/selectionSwitch.mjs.map +1 -1
- package/dist/{sessionConfig-DV5xTRRw.mjs → sessionConfig-DFQF618G.mjs} +48 -47
- package/dist/sessionConfig-DFQF618G.mjs.map +1 -0
- package/dist/{sessionConfig-Bf6xHWLd.cjs → sessionConfig-DeP6pplT.cjs} +74 -85
- package/dist/sessionConfig-DeP6pplT.cjs.map +1 -0
- package/dist/sync-BJ8gCP9s.mjs +29 -0
- package/dist/sync-BJ8gCP9s.mjs.map +1 -0
- package/dist/sync-CC_15kkB.d.mts +46 -0
- package/dist/sync-CC_15kkB.d.mts.map +1 -0
- package/dist/sync-Dlxz2msM.cjs +37 -0
- package/dist/sync-Dlxz2msM.cjs.map +1 -0
- package/dist/types.cjs +2 -2
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +1 -2
- package/llms.txt +1 -1
- package/package.json +16 -16
- package/src/prompts/po-author-config/SKILL.md +4 -4
- package/src/prompts/po-author-config/agents/openai.yaml +1 -1
- package/src/prompts/po-author-config/references/config-contract.md +5 -5
- package/dist/atomicJson-1W0WhuFF.mjs +0 -44
- package/dist/atomicJson-1W0WhuFF.mjs.map +0 -1
- package/dist/atomicJson-Dt2z_DXl.cjs +0 -52
- package/dist/atomicJson-Dt2z_DXl.cjs.map +0 -1
- package/dist/config-CfTb0_9G.cjs +0 -219
- package/dist/config-CfTb0_9G.cjs.map +0 -1
- package/dist/config-D2HbBLzo.d.mts.map +0 -1
- package/dist/config-DoQWSt1V.mjs +0 -162
- package/dist/config-DoQWSt1V.mjs.map +0 -1
- package/dist/config-NSHRd6na.mjs +0 -2
- package/dist/configPolicy-Ce1QKDxa.cjs.map +0 -1
- package/dist/configPolicy-DCQgF5-f.mjs.map +0 -1
- package/dist/configWriter-B7uO8MuN.cjs +0 -150
- package/dist/configWriter-B7uO8MuN.cjs.map +0 -1
- package/dist/configWriter-DUtLgOlD.mjs +0 -130
- package/dist/configWriter-DUtLgOlD.mjs.map +0 -1
- package/dist/domains-BroCVHrS.mjs.map +0 -1
- package/dist/domains-DGCb7uMC.cjs.map +0 -1
- package/dist/harnessStore-CJSxdSkV.cjs.map +0 -1
- package/dist/harnessStore-CltwLB7M.mjs.map +0 -1
- package/dist/index-78zvoS9s.d.mts +0 -35
- package/dist/index-78zvoS9s.d.mts.map +0 -1
- package/dist/index-BT29GZx5.d.mts.map +0 -1
- package/dist/index-C6GaYjq-.d.mts +0 -6
- package/dist/index-C6GaYjq-.d.mts.map +0 -1
- package/dist/index-CEUc7m16.d.mts.map +0 -1
- package/dist/index-CRcoVYXz.d.mts +0 -39
- package/dist/index-CRcoVYXz.d.mts.map +0 -1
- package/dist/index-CVlciCJF.d.mts +0 -40
- package/dist/index-CVlciCJF.d.mts.map +0 -1
- package/dist/index-Ch7ptOkW.d.mts.map +0 -1
- package/dist/index-CkDDvVQt.d.mts.map +0 -1
- package/dist/index-Cvdt-Y-i.d.mts +0 -66
- package/dist/index-Cvdt-Y-i.d.mts.map +0 -1
- package/dist/index-DNk4q0Qm.d.mts.map +0 -1
- package/dist/index-DdH0w56b.d.mts +0 -116
- package/dist/index-DdH0w56b.d.mts.map +0 -1
- package/dist/init-Cd3Ki6Ub.cjs.map +0 -1
- package/dist/init-DVzhiCUE.mjs.map +0 -1
- package/dist/layeredConfig-fukqN2EA.mjs +0 -67
- package/dist/layeredConfig-fukqN2EA.mjs.map +0 -1
- package/dist/layeredConfig-ol0274TN.cjs +0 -94
- package/dist/layeredConfig-ol0274TN.cjs.map +0 -1
- package/dist/majorModes-D1Itd8SN.mjs.map +0 -1
- package/dist/majorModes-DnNSH9ZK.cjs.map +0 -1
- package/dist/piConfig-CCBdZXQr.cjs.map +0 -1
- package/dist/piConfig-qGyCbcVj.mjs.map +0 -1
- package/dist/profiles-DBcYg5nA.mjs.map +0 -1
- package/dist/profiles-tpplXY4r.cjs.map +0 -1
- package/dist/sessionConfig-Bf6xHWLd.cjs.map +0 -1
- package/dist/sessionConfig-DV5xTRRw.mjs.map +0 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
2
|
-
const require_layeredConfig = require("./layeredConfig-
|
|
3
|
-
let node_fs = require("node:fs");
|
|
4
|
-
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
2
|
+
const require_layeredConfig = require("./layeredConfig-Bs18dXQG.cjs");
|
|
5
3
|
let node_path = require("node:path");
|
|
6
4
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
|
+
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
6
|
+
let node_fs = require("node:fs");
|
|
7
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs, 1);
|
|
8
|
+
let yaml = require("yaml");
|
|
7
9
|
let node_os = require("node:os");
|
|
8
10
|
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
9
|
-
let
|
|
11
|
+
let node_buffer = require("node:buffer");
|
|
10
12
|
let _agimon_ai_po_core_profileIdentity = require("@agimon-ai/po-core/profileIdentity");
|
|
11
13
|
//#region src/services/personaFrontMatter/index.ts
|
|
12
14
|
/**
|
|
@@ -81,21 +83,11 @@ function parsePersonaFrontMatter(content) {
|
|
|
81
83
|
};
|
|
82
84
|
}
|
|
83
85
|
//#endregion
|
|
84
|
-
//#region src/services/personaIcon/
|
|
86
|
+
//#region src/services/personaIcon/core.ts
|
|
85
87
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* HTTP route. A route would leave a request-time filesystem resolution reachable
|
|
90
|
-
* from the browser for the life of a session, defended on every request forever;
|
|
91
|
-
* this resolves the path once, server side, at the moment the profile loads.
|
|
92
|
-
*
|
|
93
|
-
* The path comes from user-authored front-matter, so it is confined the same way
|
|
94
|
-
* `buildPersonaPrompt` confines persona files: a symlink must not read outside
|
|
95
|
-
* the persona directory.
|
|
96
|
-
*
|
|
97
|
-
* Every failure is silent and returns undefined. An avatar is decoration, and a
|
|
98
|
-
* broken one must never stop a persona from loading.
|
|
88
|
+
* Pure half of persona icon loading: confinement and image sniffing. The
|
|
89
|
+
* readers in `index.ts` (async, over a FileSystem) and `sync.ts` (Node shim)
|
|
90
|
+
* only resolve paths and fetch bytes.
|
|
99
91
|
*/
|
|
100
92
|
const PARENT_DIRECTORY$1 = "..";
|
|
101
93
|
/**
|
|
@@ -108,7 +100,7 @@ const PARENT_DIRECTORY$1 = "..";
|
|
|
108
100
|
const SIGNATURES = [
|
|
109
101
|
{
|
|
110
102
|
mime: "image/png",
|
|
111
|
-
test: (b) => b.length > 8 && b.subarray(0, 8).equals(Buffer.from([
|
|
103
|
+
test: (b) => b.length > 8 && b.subarray(0, 8).equals(node_buffer.Buffer.from([
|
|
112
104
|
137,
|
|
113
105
|
80,
|
|
114
106
|
78,
|
|
@@ -132,13 +124,27 @@ const SIGNATURES = [
|
|
|
132
124
|
test: (b) => b.length > 12 && b.subarray(0, 4).toString("latin1") === "RIFF" && b.subarray(8, 12).toString("latin1") === "WEBP"
|
|
133
125
|
}
|
|
134
126
|
];
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
/** True when `realIconPath` lies inside `realPersonaPath` (both already canonical). */
|
|
128
|
+
function isInsidePersona(realPersonaPath, realIconPath) {
|
|
129
|
+
const relative = node_path.default.relative(realPersonaPath, realIconPath);
|
|
130
|
+
return !(relative === PARENT_DIRECTORY$1 || relative.startsWith(`${PARENT_DIRECTORY$1}${node_path.default.sep}`) || node_path.default.isAbsolute(relative));
|
|
131
|
+
}
|
|
132
|
+
/** A bounded `data:` URL for an allowed image, or undefined. */
|
|
133
|
+
function iconDataUrl(content) {
|
|
134
|
+
const bytes = node_buffer.Buffer.from(content.buffer, content.byteOffset, content.byteLength);
|
|
135
|
+
const mime = SIGNATURES.find((signature) => signature.test(bytes))?.mime;
|
|
136
|
+
if (!mime) return void 0;
|
|
137
|
+
const dataUrl = `data:${mime};base64,${bytes.toString("base64")}`;
|
|
138
|
+
return dataUrl.length > _agimon_ai_po_core_profileIdentity.PROFILE_ICON_MAX_DATA_URL_LENGTH ? void 0 : dataUrl;
|
|
137
139
|
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/services/personaIcon/sync.ts
|
|
138
142
|
/**
|
|
139
143
|
* Resolves an icon declared in persona front-matter, or undefined when it is
|
|
140
144
|
* missing, unreadable, not an allowed image, escapes the persona directory, or
|
|
141
145
|
* exceeds the data-URL ceiling.
|
|
146
|
+
*
|
|
147
|
+
* @deprecated Node-only sync shim; use readPersonaIconAsync. Removed in M2.
|
|
142
148
|
*/
|
|
143
149
|
function readPersonaIcon(personaPath, iconRelative) {
|
|
144
150
|
if (node_path.default.isAbsolute(iconRelative)) return void 0;
|
|
@@ -147,14 +153,41 @@ function readPersonaIcon(personaPath, iconRelative) {
|
|
|
147
153
|
const iconPath = node_path.default.resolve(realPersonaPath, iconRelative);
|
|
148
154
|
if (!node_fs.default.existsSync(iconPath)) return void 0;
|
|
149
155
|
const realIconPath = node_fs.default.realpathSync(iconPath);
|
|
150
|
-
|
|
151
|
-
if (relative === PARENT_DIRECTORY$1 || relative.startsWith(`${PARENT_DIRECTORY$1}${node_path.default.sep}`) || node_path.default.isAbsolute(relative)) return;
|
|
156
|
+
if (!isInsidePersona(realPersonaPath, realIconPath)) return void 0;
|
|
152
157
|
if (!node_fs.default.statSync(realIconPath).isFile()) return void 0;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
return iconDataUrl(node_fs.default.readFileSync(realIconPath));
|
|
159
|
+
} catch {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/services/personaIcon/index.ts
|
|
165
|
+
/**
|
|
166
|
+
* Reads a persona icon into a bounded `data:` URL.
|
|
167
|
+
*
|
|
168
|
+
* The icon travels inside the journalled identity entry rather than through an
|
|
169
|
+
* HTTP route. A route would leave a request-time filesystem resolution reachable
|
|
170
|
+
* from the browser for the life of a session, defended on every request forever;
|
|
171
|
+
* this resolves the path once, server side, at the moment the profile loads.
|
|
172
|
+
*
|
|
173
|
+
* The path comes from user-authored front-matter, so it is confined the same way
|
|
174
|
+
* `buildPersonaPrompt` confines persona files: a symlink must not read outside
|
|
175
|
+
* the persona directory.
|
|
176
|
+
*
|
|
177
|
+
* Every failure is silent and returns undefined. An avatar is decoration, and a
|
|
178
|
+
* broken one must never stop a persona from loading. That includes a host whose
|
|
179
|
+
* filesystem lacks the persona entirely, such as the edge.
|
|
180
|
+
*/
|
|
181
|
+
async function readPersonaIconAsync(fs, personaPath, iconRelative, context) {
|
|
182
|
+
if (node_path.default.isAbsolute(iconRelative)) return void 0;
|
|
183
|
+
try {
|
|
184
|
+
const realPersonaPath = (0, _agimon_ai_po_core_platform.getOrThrow)(await fs.canonicalPath(personaPath, context));
|
|
185
|
+
const iconPath = node_path.default.resolve(realPersonaPath, iconRelative);
|
|
186
|
+
if (!(0, _agimon_ai_po_core_platform.getOrThrow)(await fs.exists(iconPath, context))) return void 0;
|
|
187
|
+
const realIconPath = (0, _agimon_ai_po_core_platform.getOrThrow)(await fs.canonicalPath(iconPath, context));
|
|
188
|
+
if (!isInsidePersona(realPersonaPath, realIconPath)) return void 0;
|
|
189
|
+
if ((0, _agimon_ai_po_core_platform.getOrThrow)(await fs.fileInfo(realIconPath, context)).kind !== "file") return void 0;
|
|
190
|
+
return iconDataUrl((0, _agimon_ai_po_core_platform.getOrThrow)(await fs.readBinaryFile(realIconPath, context)));
|
|
158
191
|
} catch {
|
|
159
192
|
return;
|
|
160
193
|
}
|
|
@@ -237,7 +270,7 @@ function parseProfileBinding(value, location = "Profile integration") {
|
|
|
237
270
|
});
|
|
238
271
|
}
|
|
239
272
|
//#endregion
|
|
240
|
-
//#region src/services/profiles/
|
|
273
|
+
//#region src/services/profiles/core.ts
|
|
241
274
|
/** Files that make up one repository persona, concatenated in this order. */
|
|
242
275
|
const PERSONA_FILES = [
|
|
243
276
|
"profile.md",
|
|
@@ -259,14 +292,12 @@ const PROFILE_CATALOG_KEYS = /* @__PURE__ */ new Set([
|
|
|
259
292
|
const PROFILES_FILE = "profiles.yaml";
|
|
260
293
|
const PROFILES_ROOT_KEY = "profiles";
|
|
261
294
|
const AGENTS_DIRECTORY = "agents";
|
|
262
|
-
const PARENT_DIRECTORY = "..";
|
|
263
|
-
const TEXT_ENCODING = "utf8";
|
|
264
295
|
function isRecord(value) {
|
|
265
296
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
266
297
|
}
|
|
267
298
|
function isPathInside(root, candidate) {
|
|
268
299
|
const relative = node_path.default.relative(root, candidate);
|
|
269
|
-
return relative === "" || !node_path.default.isAbsolute(relative) && relative !==
|
|
300
|
+
return relative === "" || !node_path.default.isAbsolute(relative) && relative !== ".." && !relative.startsWith(`..${node_path.default.sep}`);
|
|
270
301
|
}
|
|
271
302
|
function parseEnvironment(name, value) {
|
|
272
303
|
if (value === void 0) return {};
|
|
@@ -310,11 +341,11 @@ function parseProfileLayer(source) {
|
|
|
310
341
|
...profiles.defaultProfile === void 0 ? {} : { defaultProfile: String(profiles.defaultProfile).trim() }
|
|
311
342
|
};
|
|
312
343
|
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
function
|
|
344
|
+
/**
|
|
345
|
+
* Shape checks for one explicit entry. The caller checks the persona on disk,
|
|
346
|
+
* then `profileFromDraft` parses env and integration, keeping the error order.
|
|
347
|
+
*/
|
|
348
|
+
function draftProfileEntry(personaRoot, configuredRoots, name, value) {
|
|
318
349
|
if (!isRecord(value)) throw new Error(`Profile "${name}" must be a mapping`);
|
|
319
350
|
const unsupported = Object.keys(value).filter((key) => !PROFILE_KEYS.has(key));
|
|
320
351
|
if (unsupported.length > 0) throw new Error(`Profile "${name}" may only set persona, env and integration; unsupported: ${unsupported.join(", ")}`);
|
|
@@ -323,23 +354,99 @@ function parseProfile(personaRoot, configuredRoots, name, value) {
|
|
|
323
354
|
const persona = value.persona;
|
|
324
355
|
const personaPath = node_path.default.resolve(personaRoot, persona);
|
|
325
356
|
const lexicalRoots = [node_path.default.resolve(personaRoot, AGENTS_DIRECTORY), ...configuredRoots].filter((root) => isPathInside(root, personaPath));
|
|
326
|
-
if (lexicalRoots.length === 0) throw
|
|
327
|
-
if (!node_fs.default.existsSync(personaPath) || !node_fs.default.statSync(personaPath).isDirectory()) throw new Error(`Profile "${name}" references a missing persona: ${persona}`);
|
|
328
|
-
assertProfileInsideAllowedRoot(name, personaPath, lexicalRoots);
|
|
329
|
-
if (!buildPersonaPrompt(personaRoot, persona)) {
|
|
330
|
-
const declaresIdentity = readPersonaFrontMatter(personaRoot, persona) !== void 0;
|
|
331
|
-
throw new Error(declaresIdentity ? `Profile "${name}" persona declares identity front-matter but no persona text: ${persona}` : `Profile "${name}" persona has no readable persona files: ${persona}`);
|
|
332
|
-
}
|
|
357
|
+
if (lexicalRoots.length === 0) throw outsideAllowedRoot(name);
|
|
333
358
|
return {
|
|
334
359
|
name,
|
|
335
360
|
persona,
|
|
361
|
+
personaPath,
|
|
362
|
+
lexicalRoots,
|
|
363
|
+
value
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function outsideAllowedRoot(name) {
|
|
367
|
+
return /* @__PURE__ */ new Error(`Profile "${name}" persona must stay inside agents/ or a configured profile root`);
|
|
368
|
+
}
|
|
369
|
+
function missingPersona(name, persona) {
|
|
370
|
+
return /* @__PURE__ */ new Error(`Profile "${name}" references a missing persona: ${persona}`);
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* An identity block is not persona text, so a profile.md holding nothing else
|
|
374
|
+
* leaves the persona empty. Say that, rather than claiming the file is unreadable.
|
|
375
|
+
*/
|
|
376
|
+
function emptyPersona(name, persona, declaresIdentity) {
|
|
377
|
+
return /* @__PURE__ */ new Error(declaresIdentity ? `Profile "${name}" persona declares identity front-matter but no persona text: ${persona}` : `Profile "${name}" persona has no readable persona files: ${persona}`);
|
|
378
|
+
}
|
|
379
|
+
function profileFromDraft(draft, personaRoot, presentation) {
|
|
380
|
+
const { name, value } = draft;
|
|
381
|
+
return {
|
|
382
|
+
name,
|
|
383
|
+
persona: draft.persona,
|
|
336
384
|
personaRoot,
|
|
337
385
|
env: parseEnvironment(name, value.env),
|
|
338
386
|
...value.integration === void 0 ? {} : { integration: parseProfileBinding(value.integration, `Profile "${name}" integration`) },
|
|
339
|
-
...
|
|
387
|
+
...presentation
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function presentationFrom(frontMatter, icon) {
|
|
391
|
+
const identity = {
|
|
392
|
+
...frontMatter.name === void 0 ? {} : { name: frontMatter.name },
|
|
393
|
+
...icon === void 0 ? {} : { icon }
|
|
340
394
|
};
|
|
395
|
+
return {
|
|
396
|
+
...identity.name === void 0 && identity.icon === void 0 ? {} : { identity },
|
|
397
|
+
...frontMatter.voice === void 0 ? {} : { voice: frontMatter.voice }
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** Rejects a persona file whose real path left the persona directory. */
|
|
401
|
+
function assertPersonaFileInside(personaPath, realFilePath, personaDirectory, file) {
|
|
402
|
+
const relativeFilePath = node_path.default.relative(personaPath, realFilePath);
|
|
403
|
+
if (relativeFilePath === ".." || relativeFilePath.startsWith(`..${node_path.default.sep}`)) throw new Error(`Persona file must stay inside ${personaDirectory}: ${file}`);
|
|
404
|
+
}
|
|
405
|
+
/** The text one persona file contributes. Only profile.md may declare identity, so only profile.md is stripped. */
|
|
406
|
+
function personaFileSection(file, raw) {
|
|
407
|
+
return (file === "profile.md" ? parsePersonaFrontMatter(raw).body : raw).trim();
|
|
408
|
+
}
|
|
409
|
+
function personaPromptFromSections(personaDirectory, sections) {
|
|
410
|
+
if (sections.length === 0) return void 0;
|
|
411
|
+
return [`[PERSONA] You are operating as the person described below (source: ${personaDirectory}).`, ...sections].join("\n\n");
|
|
412
|
+
}
|
|
413
|
+
function sortProfiles(byName) {
|
|
414
|
+
return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));
|
|
415
|
+
}
|
|
416
|
+
/** A repository declaration replaces a personal one; an unknown name is an error, not a fallback. */
|
|
417
|
+
function catalogDefaultProfile(layers, profiles) {
|
|
418
|
+
let defaultProfile;
|
|
419
|
+
for (const layer of layers) if (layer.defaultProfile !== void 0) defaultProfile = layer.defaultProfile;
|
|
420
|
+
if (defaultProfile !== void 0 && !profiles.some((profile) => profile.name === defaultProfile)) throw new Error(`profiles.defaultProfile names an unknown profile: ${defaultProfile}`);
|
|
421
|
+
return defaultProfile;
|
|
422
|
+
}
|
|
423
|
+
/** Applies profile environment defaults and returns only the values it contributed. */
|
|
424
|
+
function applyProfileEnvironment(environment, defaults) {
|
|
425
|
+
const applied = {};
|
|
426
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
427
|
+
if (environment[key] !== void 0) continue;
|
|
428
|
+
environment[key] = value;
|
|
429
|
+
applied[key] = value;
|
|
430
|
+
}
|
|
431
|
+
return applied;
|
|
432
|
+
}
|
|
433
|
+
/** Replaces environment defaults previously contributed by another profile. */
|
|
434
|
+
function replaceProfileEnvironment(environment, previous, next) {
|
|
435
|
+
for (const [key, value] of Object.entries(previous)) if (environment[key] === value) delete environment[key];
|
|
436
|
+
return applyProfileEnvironment(environment, next);
|
|
437
|
+
}
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/services/profiles/sync.ts
|
|
440
|
+
const TEXT_ENCODING = "utf8";
|
|
441
|
+
function parseProfile$1(personaRoot, configuredRoots, name, value) {
|
|
442
|
+
const draft = draftProfileEntry(personaRoot, configuredRoots, name, value);
|
|
443
|
+
if (!node_fs.default.existsSync(draft.personaPath) || !node_fs.default.statSync(draft.personaPath).isDirectory()) throw missingPersona(name, draft.persona);
|
|
444
|
+
const realPersonaPath = node_fs.default.realpathSync(draft.personaPath);
|
|
445
|
+
if (!draft.lexicalRoots.some((root) => isPathInside(node_fs.default.realpathSync(root), realPersonaPath))) throw outsideAllowedRoot(name);
|
|
446
|
+
if (!buildPersonaPrompt(personaRoot, draft.persona)) throw emptyPersona(name, draft.persona, readPersonaFrontMatter$1(personaRoot, draft.persona) !== void 0);
|
|
447
|
+
return profileFromDraft(draft, personaRoot, readPersonaPresentation$1(personaRoot, draft.persona));
|
|
341
448
|
}
|
|
342
|
-
function containsPersonaFile(directory) {
|
|
449
|
+
function containsPersonaFile$1(directory) {
|
|
343
450
|
return PERSONA_FILES.some((file) => {
|
|
344
451
|
try {
|
|
345
452
|
return node_fs.default.lstatSync(node_path.default.join(directory, file)).isFile();
|
|
@@ -348,8 +455,8 @@ function containsPersonaFile(directory) {
|
|
|
348
455
|
}
|
|
349
456
|
});
|
|
350
457
|
}
|
|
351
|
-
function discoverProfile(directory, configuredRoot, personaRoot) {
|
|
352
|
-
if (!containsPersonaFile(directory)) return void 0;
|
|
458
|
+
function discoverProfile$1(directory, configuredRoot, personaRoot) {
|
|
459
|
+
if (!containsPersonaFile$1(directory)) return void 0;
|
|
353
460
|
try {
|
|
354
461
|
if (!isPathInside(node_fs.default.realpathSync(configuredRoot), node_fs.default.realpathSync(directory))) return void 0;
|
|
355
462
|
const persona = node_path.default.relative(personaRoot, directory) || ".";
|
|
@@ -359,21 +466,30 @@ function discoverProfile(directory, configuredRoot, personaRoot) {
|
|
|
359
466
|
persona,
|
|
360
467
|
personaRoot,
|
|
361
468
|
env: {},
|
|
362
|
-
...readPersonaPresentation(personaRoot, persona)
|
|
469
|
+
...readPersonaPresentation$1(personaRoot, persona)
|
|
363
470
|
};
|
|
364
471
|
} catch {
|
|
365
472
|
return;
|
|
366
473
|
}
|
|
367
474
|
}
|
|
368
|
-
function discoverProfileRoot(root, personaRoot) {
|
|
475
|
+
function discoverProfileRoot$1(root, personaRoot) {
|
|
369
476
|
if (!node_fs.default.existsSync(root) || !node_fs.default.statSync(root).isDirectory()) throw new Error(`Configured profile root is not a directory: ${root}`);
|
|
370
|
-
const rootProfile = discoverProfile(root, root, personaRoot);
|
|
477
|
+
const rootProfile = discoverProfile$1(root, root, personaRoot);
|
|
371
478
|
if (rootProfile) return [rootProfile];
|
|
372
479
|
return node_fs.default.readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).sort((left, right) => left.name.localeCompare(right.name)).flatMap((entry) => {
|
|
373
|
-
const profile = discoverProfile(node_path.default.join(root, entry.name), root, personaRoot);
|
|
480
|
+
const profile = discoverProfile$1(node_path.default.join(root, entry.name), root, personaRoot);
|
|
374
481
|
return profile ? [profile] : [];
|
|
375
482
|
});
|
|
376
483
|
}
|
|
484
|
+
function readProfileLayers$1(repoRoot, homeDirectory) {
|
|
485
|
+
return require_layeredConfig.readPoConfigSources(PROFILES_FILE, repoRoot, homeDirectory).map(parseProfileLayer);
|
|
486
|
+
}
|
|
487
|
+
function profilesFromLayers$1(layers) {
|
|
488
|
+
const byName = /* @__PURE__ */ new Map();
|
|
489
|
+
for (const layer of layers) for (const root of layer.roots) for (const profile of discoverProfileRoot$1(root, layer.baseDirectory)) byName.set(profile.name, profile);
|
|
490
|
+
for (const layer of layers) for (const [name, value] of Object.entries(layer.entries)) byName.set(name, parseProfile$1(layer.baseDirectory, layer.roots, name, value));
|
|
491
|
+
return sortProfiles(byName);
|
|
492
|
+
}
|
|
377
493
|
/**
|
|
378
494
|
* Loads profiles from the global and repository configs, repository last.
|
|
379
495
|
*
|
|
@@ -381,13 +497,11 @@ function discoverProfileRoot(root, personaRoot) {
|
|
|
381
497
|
* directories for persona files. Later discoveries replace earlier names, and
|
|
382
498
|
* explicit entries replace discoveries. Legacy flat profile mappings remain
|
|
383
499
|
* accepted as explicit entries.
|
|
500
|
+
*
|
|
501
|
+
* @deprecated Node-only sync shim; use loadProfilesAsync. Removed in M2.
|
|
384
502
|
*/
|
|
385
503
|
function loadProfiles(repoRoot, homeDirectory = node_os.default.homedir()) {
|
|
386
|
-
|
|
387
|
-
const byName = /* @__PURE__ */ new Map();
|
|
388
|
-
for (const layer of layers) for (const root of layer.roots) for (const profile of discoverProfileRoot(root, layer.baseDirectory)) byName.set(profile.name, profile);
|
|
389
|
-
for (const layer of layers) for (const [name, value] of Object.entries(layer.entries)) byName.set(name, parseProfile(layer.baseDirectory, layer.roots, name, value));
|
|
390
|
-
return [...byName.values()].sort((left, right) => left.name.localeCompare(right.name));
|
|
504
|
+
return profilesFromLayers$1(readProfileLayers$1(repoRoot, homeDirectory));
|
|
391
505
|
}
|
|
392
506
|
/**
|
|
393
507
|
* The profile catalog: every resolved profile, plus the name a launch starts on
|
|
@@ -398,48 +512,38 @@ function loadProfiles(repoRoot, homeDirectory = node_os.default.homedir()) {
|
|
|
398
512
|
* catalog. A repository declaration replaces a personal one. An unknown name is
|
|
399
513
|
* an error rather than a silent fallback: a typo that quietly starts the session
|
|
400
514
|
* with no persona is worse than a refused launch.
|
|
515
|
+
*
|
|
516
|
+
* @deprecated Node-only sync shim; use loadProfileCatalogAsync. Removed in M2.
|
|
401
517
|
*/
|
|
402
518
|
function loadProfileCatalog(repoRoot, homeDirectory = node_os.default.homedir()) {
|
|
403
|
-
const layers =
|
|
404
|
-
const profiles =
|
|
405
|
-
|
|
406
|
-
for (const layer of layers) if (layer.defaultProfile !== void 0) defaultProfile = layer.defaultProfile;
|
|
407
|
-
if (defaultProfile !== void 0 && !profiles.some((profile) => profile.name === defaultProfile)) throw new Error(`profiles.defaultProfile names an unknown profile: ${defaultProfile}`);
|
|
519
|
+
const layers = readProfileLayers$1(repoRoot, homeDirectory);
|
|
520
|
+
const profiles = profilesFromLayers$1(layers);
|
|
521
|
+
const defaultProfile = catalogDefaultProfile(layers, profiles);
|
|
408
522
|
return {
|
|
409
523
|
profiles,
|
|
410
524
|
...defaultProfile === void 0 ? {} : { defaultProfile }
|
|
411
525
|
};
|
|
412
526
|
}
|
|
413
|
-
/**
|
|
527
|
+
/**
|
|
528
|
+
* Resolves one selected profile and fails clearly when its name is unknown.
|
|
529
|
+
*
|
|
530
|
+
* @deprecated Node-only sync shim; use resolveProfileAsync. Removed in M2.
|
|
531
|
+
*/
|
|
414
532
|
function resolveProfile(repoRoot, name, homeDirectory) {
|
|
415
533
|
const profile = loadProfiles(repoRoot, homeDirectory).find((candidate) => candidate.name === name);
|
|
416
534
|
if (!profile) throw new Error(`Unknown profile: ${name}`);
|
|
417
535
|
return profile;
|
|
418
536
|
}
|
|
537
|
+
/** @deprecated Node-only sync shim; use listProfileNamesAsync. Removed in M2. */
|
|
419
538
|
function listProfileNames(repoRoot, homeDirectory) {
|
|
420
539
|
return loadProfiles(repoRoot, homeDirectory).map((profile) => profile.name);
|
|
421
540
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
*
|
|
425
|
-
* Separate from `buildPersonaPrompt` because the prompt is assembled on several
|
|
426
|
-
* paths that do not want the icon bytes, and because a persona that declares
|
|
427
|
-
* nothing must stay exactly as cheap as it is today.
|
|
428
|
-
*/
|
|
429
|
-
function readPersonaPresentation(personaRoot, personaDirectory) {
|
|
430
|
-
const frontMatter = readPersonaFrontMatter(personaRoot, personaDirectory);
|
|
541
|
+
function readPersonaPresentation$1(personaRoot, personaDirectory) {
|
|
542
|
+
const frontMatter = readPersonaFrontMatter$1(personaRoot, personaDirectory);
|
|
431
543
|
if (!frontMatter) return {};
|
|
432
|
-
|
|
433
|
-
const identity = {
|
|
434
|
-
...frontMatter.name === void 0 ? {} : { name: frontMatter.name },
|
|
435
|
-
...icon === void 0 ? {} : { icon }
|
|
436
|
-
};
|
|
437
|
-
return {
|
|
438
|
-
...identity.name === void 0 && identity.icon === void 0 ? {} : { identity },
|
|
439
|
-
...frontMatter.voice === void 0 ? {} : { voice: frontMatter.voice }
|
|
440
|
-
};
|
|
544
|
+
return presentationFrom(frontMatter, frontMatter.icon === void 0 ? void 0 : readPersonaIcon(node_path.default.join(personaRoot, personaDirectory), frontMatter.icon));
|
|
441
545
|
}
|
|
442
|
-
function readPersonaFrontMatter(personaRoot, personaDirectory) {
|
|
546
|
+
function readPersonaFrontMatter$1(personaRoot, personaDirectory) {
|
|
443
547
|
try {
|
|
444
548
|
const personaPath = node_fs.default.realpathSync(node_path.default.join(personaRoot, personaDirectory));
|
|
445
549
|
const filePath = node_path.default.join(personaPath, PERSONA_IDENTITY_FILE);
|
|
@@ -449,7 +553,11 @@ function readPersonaFrontMatter(personaRoot, personaDirectory) {
|
|
|
449
553
|
return;
|
|
450
554
|
}
|
|
451
555
|
}
|
|
452
|
-
/**
|
|
556
|
+
/**
|
|
557
|
+
* Builds the persona system-prompt block, or undefined when nothing is readable.
|
|
558
|
+
*
|
|
559
|
+
* @deprecated Node-only sync shim; use buildPersonaPromptAsync. Removed in M2.
|
|
560
|
+
*/
|
|
453
561
|
function buildPersonaPrompt(personaRoot, personaDirectory) {
|
|
454
562
|
const sections = [];
|
|
455
563
|
const personaPath = node_fs.default.realpathSync(node_path.default.join(personaRoot, personaDirectory));
|
|
@@ -457,29 +565,142 @@ function buildPersonaPrompt(personaRoot, personaDirectory) {
|
|
|
457
565
|
const filePath = node_path.default.join(personaPath, file);
|
|
458
566
|
if (!node_fs.default.existsSync(filePath)) continue;
|
|
459
567
|
const realFilePath = node_fs.default.realpathSync(filePath);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const raw = node_fs.default.readFileSync(realFilePath, TEXT_ENCODING);
|
|
463
|
-
const content = (file === PERSONA_IDENTITY_FILE ? parsePersonaFrontMatter(raw).body : raw).trim();
|
|
568
|
+
assertPersonaFileInside(personaPath, realFilePath, personaDirectory, file);
|
|
569
|
+
const content = personaFileSection(file, node_fs.default.readFileSync(realFilePath, TEXT_ENCODING));
|
|
464
570
|
if (content) sections.push(content);
|
|
465
571
|
}
|
|
466
|
-
|
|
467
|
-
return [`[PERSONA] You are operating as the person described below (source: ${personaDirectory}).`, ...sections].join("\n\n");
|
|
572
|
+
return personaPromptFromSections(personaDirectory, sections);
|
|
468
573
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
574
|
+
//#endregion
|
|
575
|
+
//#region src/services/profiles/index.ts
|
|
576
|
+
/** Profile reads over a FileSystem; the Node shims in `./sync` give the same answers from node:fs. */
|
|
577
|
+
const realPath = async (fs, target, context) => (0, _agimon_ai_po_core_platform.getOrThrow)(await fs.canonicalPath(target, context));
|
|
578
|
+
const exists = async (fs, target, context) => (0, _agimon_ai_po_core_platform.getOrThrow)(await fs.exists(target, context));
|
|
579
|
+
/** Whether a path is a directory once links are followed, as `statSync().isDirectory()`. */
|
|
580
|
+
async function isDirectory(fs, target, context) {
|
|
581
|
+
if (!await exists(fs, target, context)) return false;
|
|
582
|
+
return (0, _agimon_ai_po_core_platform.getOrThrow)(await fs.fileInfo(await realPath(fs, target, context), context)).kind === "directory";
|
|
583
|
+
}
|
|
584
|
+
async function readPersonaFrontMatter(fs, personaRoot, personaDirectory, context) {
|
|
585
|
+
try {
|
|
586
|
+
const personaPath = await realPath(fs, node_path.default.join(personaRoot, personaDirectory), context);
|
|
587
|
+
const filePath = node_path.default.join(personaPath, PERSONA_IDENTITY_FILE);
|
|
588
|
+
if (!await exists(fs, filePath, context)) return void 0;
|
|
589
|
+
const text = await (0, _agimon_ai_po_core_platform.readTextIfExists)(fs, await realPath(fs, filePath, context), context);
|
|
590
|
+
return text === void 0 ? void 0 : parsePersonaFrontMatter(text).frontMatter;
|
|
591
|
+
} catch {
|
|
592
|
+
return;
|
|
476
593
|
}
|
|
477
|
-
return applied;
|
|
478
594
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
return
|
|
595
|
+
async function readPersonaPresentation(fs, personaRoot, personaDirectory, context) {
|
|
596
|
+
const frontMatter = await readPersonaFrontMatter(fs, personaRoot, personaDirectory, context);
|
|
597
|
+
if (!frontMatter) return {};
|
|
598
|
+
return presentationFrom(frontMatter, frontMatter.icon === void 0 ? void 0 : await readPersonaIconAsync(fs, node_path.default.join(personaRoot, personaDirectory), frontMatter.icon, context));
|
|
599
|
+
}
|
|
600
|
+
/** Builds the persona system-prompt block, or undefined when nothing is readable. */
|
|
601
|
+
async function buildPersonaPromptAsync(fs, personaRoot, personaDirectory, context) {
|
|
602
|
+
const sections = [];
|
|
603
|
+
const personaPath = await realPath(fs, node_path.default.join(personaRoot, personaDirectory), context);
|
|
604
|
+
for (const file of PERSONA_FILES) {
|
|
605
|
+
const filePath = node_path.default.join(personaPath, file);
|
|
606
|
+
if (!await exists(fs, filePath, context)) continue;
|
|
607
|
+
const realFilePath = await realPath(fs, filePath, context);
|
|
608
|
+
assertPersonaFileInside(personaPath, realFilePath, personaDirectory, file);
|
|
609
|
+
const content = personaFileSection(file, (0, _agimon_ai_po_core_platform.getOrThrow)(await fs.readTextFile(realFilePath, context)));
|
|
610
|
+
if (content) sections.push(content);
|
|
611
|
+
}
|
|
612
|
+
return personaPromptFromSections(personaDirectory, sections);
|
|
613
|
+
}
|
|
614
|
+
async function parseProfile(fs, personaRoot, configuredRoots, name, value, context) {
|
|
615
|
+
const draft = draftProfileEntry(personaRoot, configuredRoots, name, value);
|
|
616
|
+
if (!await isDirectory(fs, draft.personaPath, context)) throw missingPersona(name, draft.persona);
|
|
617
|
+
const realPersonaPath = await realPath(fs, draft.personaPath, context);
|
|
618
|
+
let allowed = false;
|
|
619
|
+
for (const root of draft.lexicalRoots) if (isPathInside(await realPath(fs, root, context), realPersonaPath)) {
|
|
620
|
+
allowed = true;
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
if (!allowed) throw outsideAllowedRoot(name);
|
|
624
|
+
if (!await buildPersonaPromptAsync(fs, personaRoot, draft.persona, context)) {
|
|
625
|
+
const declaresIdentity = await readPersonaFrontMatter(fs, personaRoot, draft.persona, context) !== void 0;
|
|
626
|
+
throw emptyPersona(name, draft.persona, declaresIdentity);
|
|
627
|
+
}
|
|
628
|
+
return profileFromDraft(draft, personaRoot, await readPersonaPresentation(fs, personaRoot, draft.persona, context));
|
|
629
|
+
}
|
|
630
|
+
async function containsPersonaFile(fs, directory, context) {
|
|
631
|
+
for (const file of PERSONA_FILES) {
|
|
632
|
+
const info = await fs.fileInfo(node_path.default.join(directory, file), context);
|
|
633
|
+
if (info.ok && info.value.kind === "file") return true;
|
|
634
|
+
}
|
|
635
|
+
return false;
|
|
636
|
+
}
|
|
637
|
+
async function discoverProfile(fs, directory, configuredRoot, personaRoot, context) {
|
|
638
|
+
if (!await containsPersonaFile(fs, directory, context)) return void 0;
|
|
639
|
+
try {
|
|
640
|
+
if (!isPathInside(await realPath(fs, configuredRoot, context), await realPath(fs, directory, context))) return void 0;
|
|
641
|
+
const persona = node_path.default.relative(personaRoot, directory) || ".";
|
|
642
|
+
if (!await buildPersonaPromptAsync(fs, personaRoot, persona, context)) return void 0;
|
|
643
|
+
return {
|
|
644
|
+
name: node_path.default.basename(directory),
|
|
645
|
+
persona,
|
|
646
|
+
personaRoot,
|
|
647
|
+
env: {},
|
|
648
|
+
...await readPersonaPresentation(fs, personaRoot, persona, context)
|
|
649
|
+
};
|
|
650
|
+
} catch {
|
|
651
|
+
return;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
async function discoverProfileRoot(fs, root, personaRoot, context) {
|
|
655
|
+
if (!await isDirectory(fs, root, context)) throw new Error(`Configured profile root is not a directory: ${root}`);
|
|
656
|
+
const rootProfile = await discoverProfile(fs, root, root, personaRoot, context);
|
|
657
|
+
if (rootProfile) return [rootProfile];
|
|
658
|
+
const directories = (0, _agimon_ai_po_core_platform.getOrThrow)(await fs.listDir(root, context)).filter((entry) => entry.kind === "directory").sort((left, right) => left.name.localeCompare(right.name));
|
|
659
|
+
const profiles = [];
|
|
660
|
+
for (const entry of directories) {
|
|
661
|
+
const profile = await discoverProfile(fs, node_path.default.join(root, entry.name), root, personaRoot, context);
|
|
662
|
+
if (profile) profiles.push(profile);
|
|
663
|
+
}
|
|
664
|
+
return profiles;
|
|
665
|
+
}
|
|
666
|
+
async function readProfileLayers(fs, repoRoot, context, homeDirectory) {
|
|
667
|
+
return (await require_layeredConfig.readPoConfigSourcesAsync(fs, PROFILES_FILE, repoRoot, context, homeDirectory)).map(parseProfileLayer);
|
|
668
|
+
}
|
|
669
|
+
async function profilesFromLayers(fs, layers, context) {
|
|
670
|
+
const byName = /* @__PURE__ */ new Map();
|
|
671
|
+
for (const layer of layers) for (const root of layer.roots) for (const profile of await discoverProfileRoot(fs, root, layer.baseDirectory, context)) byName.set(profile.name, profile);
|
|
672
|
+
for (const layer of layers) for (const [name, value] of Object.entries(layer.entries)) byName.set(name, await parseProfile(fs, layer.baseDirectory, layer.roots, name, value, context));
|
|
673
|
+
return sortProfiles(byName);
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Loads profiles from the global and repository configs, repository last.
|
|
677
|
+
*
|
|
678
|
+
* Configured roots accumulate and inspect themselves or their direct-child
|
|
679
|
+
* directories for persona files. Later discoveries replace earlier names, and
|
|
680
|
+
* explicit entries replace discoveries. Legacy flat profile mappings remain
|
|
681
|
+
* accepted as explicit entries.
|
|
682
|
+
*/
|
|
683
|
+
async function loadProfilesAsync(fs, repoRoot, context, homeDirectory = _agimon_ai_po_core_platform.nodeHost.homeDirectory()) {
|
|
684
|
+
return profilesFromLayers(fs, await readProfileLayers(fs, repoRoot, context, homeDirectory), context);
|
|
685
|
+
}
|
|
686
|
+
/** The profile catalog plus the name a launch starts on when the caller names none. */
|
|
687
|
+
async function loadProfileCatalogAsync(fs, repoRoot, context, homeDirectory = _agimon_ai_po_core_platform.nodeHost.homeDirectory()) {
|
|
688
|
+
const layers = await readProfileLayers(fs, repoRoot, context, homeDirectory);
|
|
689
|
+
const profiles = await profilesFromLayers(fs, layers, context);
|
|
690
|
+
const defaultProfile = catalogDefaultProfile(layers, profiles);
|
|
691
|
+
return {
|
|
692
|
+
profiles,
|
|
693
|
+
...defaultProfile === void 0 ? {} : { defaultProfile }
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
/** Resolves one selected profile and fails clearly when its name is unknown. */
|
|
697
|
+
async function resolveProfileAsync(fs, repoRoot, name, context, homeDirectory) {
|
|
698
|
+
const profile = (await loadProfilesAsync(fs, repoRoot, context, homeDirectory)).find((candidate) => candidate.name === name);
|
|
699
|
+
if (!profile) throw new Error(`Unknown profile: ${name}`);
|
|
700
|
+
return profile;
|
|
701
|
+
}
|
|
702
|
+
async function listProfileNamesAsync(fs, repoRoot, context, homeDirectory) {
|
|
703
|
+
return (await loadProfilesAsync(fs, repoRoot, context, homeDirectory)).map((profile) => profile.name);
|
|
483
704
|
}
|
|
484
705
|
//#endregion
|
|
485
706
|
Object.defineProperty(exports, "PERSONA_FILES", {
|
|
@@ -500,24 +721,48 @@ Object.defineProperty(exports, "buildPersonaPrompt", {
|
|
|
500
721
|
return buildPersonaPrompt;
|
|
501
722
|
}
|
|
502
723
|
});
|
|
724
|
+
Object.defineProperty(exports, "buildPersonaPromptAsync", {
|
|
725
|
+
enumerable: true,
|
|
726
|
+
get: function() {
|
|
727
|
+
return buildPersonaPromptAsync;
|
|
728
|
+
}
|
|
729
|
+
});
|
|
503
730
|
Object.defineProperty(exports, "listProfileNames", {
|
|
504
731
|
enumerable: true,
|
|
505
732
|
get: function() {
|
|
506
733
|
return listProfileNames;
|
|
507
734
|
}
|
|
508
735
|
});
|
|
736
|
+
Object.defineProperty(exports, "listProfileNamesAsync", {
|
|
737
|
+
enumerable: true,
|
|
738
|
+
get: function() {
|
|
739
|
+
return listProfileNamesAsync;
|
|
740
|
+
}
|
|
741
|
+
});
|
|
509
742
|
Object.defineProperty(exports, "loadProfileCatalog", {
|
|
510
743
|
enumerable: true,
|
|
511
744
|
get: function() {
|
|
512
745
|
return loadProfileCatalog;
|
|
513
746
|
}
|
|
514
747
|
});
|
|
748
|
+
Object.defineProperty(exports, "loadProfileCatalogAsync", {
|
|
749
|
+
enumerable: true,
|
|
750
|
+
get: function() {
|
|
751
|
+
return loadProfileCatalogAsync;
|
|
752
|
+
}
|
|
753
|
+
});
|
|
515
754
|
Object.defineProperty(exports, "loadProfiles", {
|
|
516
755
|
enumerable: true,
|
|
517
756
|
get: function() {
|
|
518
757
|
return loadProfiles;
|
|
519
758
|
}
|
|
520
759
|
});
|
|
760
|
+
Object.defineProperty(exports, "loadProfilesAsync", {
|
|
761
|
+
enumerable: true,
|
|
762
|
+
get: function() {
|
|
763
|
+
return loadProfilesAsync;
|
|
764
|
+
}
|
|
765
|
+
});
|
|
521
766
|
Object.defineProperty(exports, "parsePersonaFrontMatter", {
|
|
522
767
|
enumerable: true,
|
|
523
768
|
get: function() {
|
|
@@ -536,6 +781,12 @@ Object.defineProperty(exports, "readPersonaIcon", {
|
|
|
536
781
|
return readPersonaIcon;
|
|
537
782
|
}
|
|
538
783
|
});
|
|
784
|
+
Object.defineProperty(exports, "readPersonaIconAsync", {
|
|
785
|
+
enumerable: true,
|
|
786
|
+
get: function() {
|
|
787
|
+
return readPersonaIconAsync;
|
|
788
|
+
}
|
|
789
|
+
});
|
|
539
790
|
Object.defineProperty(exports, "replaceProfileEnvironment", {
|
|
540
791
|
enumerable: true,
|
|
541
792
|
get: function() {
|
|
@@ -548,5 +799,11 @@ Object.defineProperty(exports, "resolveProfile", {
|
|
|
548
799
|
return resolveProfile;
|
|
549
800
|
}
|
|
550
801
|
});
|
|
802
|
+
Object.defineProperty(exports, "resolveProfileAsync", {
|
|
803
|
+
enumerable: true,
|
|
804
|
+
get: function() {
|
|
805
|
+
return resolveProfileAsync;
|
|
806
|
+
}
|
|
807
|
+
});
|
|
551
808
|
|
|
552
|
-
//# sourceMappingURL=profiles-
|
|
809
|
+
//# sourceMappingURL=profiles-t2EUj0aB.cjs.map
|