@mistralys/persona-builder 2.3.0 → 2.4.1
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/README.md +3 -0
- package/dist/cli.cjs +71 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +71 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +73 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +223 -26
- package/dist/index.d.ts +223 -26
- package/dist/index.js +72 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -157,7 +157,7 @@ function runBuildContext(plugins, ctx, persona, suite, target) {
|
|
|
157
157
|
let accumulated = ctx;
|
|
158
158
|
for (const plugin of plugins) {
|
|
159
159
|
if (typeof plugin.onBuildContext === "function") {
|
|
160
|
-
accumulated = plugin.onBuildContext(accumulated, persona, suite, target);
|
|
160
|
+
accumulated = plugin.onBuildContext(accumulated, persona, suite, target) ?? accumulated;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
return accumulated;
|
|
@@ -166,11 +166,29 @@ function runPostRender(plugins, rendered, persona, target) {
|
|
|
166
166
|
let output = rendered;
|
|
167
167
|
for (const plugin of plugins) {
|
|
168
168
|
if (typeof plugin.onPostRender === "function") {
|
|
169
|
-
output = plugin.onPostRender(output, persona, target);
|
|
169
|
+
output = plugin.onPostRender(output, persona, target) ?? output;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
return output;
|
|
173
173
|
}
|
|
174
|
+
function runPartials(plugins, partialsMap, suiteName, suite) {
|
|
175
|
+
let accumulated = partialsMap;
|
|
176
|
+
for (const plugin of plugins) {
|
|
177
|
+
if (typeof plugin.onPartials === "function") {
|
|
178
|
+
accumulated = plugin.onPartials(accumulated, suiteName, suite) ?? accumulated;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return accumulated;
|
|
182
|
+
}
|
|
183
|
+
function runPersonaPartials(plugins, partialsMap, persona, context, suite, target) {
|
|
184
|
+
let accumulated = partialsMap;
|
|
185
|
+
for (const plugin of plugins) {
|
|
186
|
+
if (typeof plugin.onPersonaPartials === "function") {
|
|
187
|
+
accumulated = plugin.onPersonaPartials(accumulated, persona, context, suite, target) ?? accumulated;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return accumulated;
|
|
191
|
+
}
|
|
174
192
|
function runValidate(plugins, persona, suite, target) {
|
|
175
193
|
const results = [];
|
|
176
194
|
for (const plugin of plugins) {
|
|
@@ -393,9 +411,20 @@ async function buildAgentNameMap(config) {
|
|
|
393
411
|
}
|
|
394
412
|
return agentMap;
|
|
395
413
|
}
|
|
396
|
-
function buildContext(
|
|
414
|
+
function buildContext(options) {
|
|
415
|
+
const {
|
|
416
|
+
personaMeta,
|
|
417
|
+
sharedMeta,
|
|
418
|
+
agentMap = {},
|
|
419
|
+
target,
|
|
420
|
+
registry,
|
|
421
|
+
configVariables,
|
|
422
|
+
suiteVariables
|
|
423
|
+
} = options;
|
|
397
424
|
const version = typeof personaMeta["version"] === "string" ? personaMeta["version"] : typeof sharedMeta["default_version"] === "string" ? sharedMeta["default_version"] : "0.0.0";
|
|
398
425
|
const merged = {
|
|
426
|
+
...configVariables ?? {},
|
|
427
|
+
...suiteVariables ?? {},
|
|
399
428
|
...sharedMeta,
|
|
400
429
|
...personaMeta,
|
|
401
430
|
version
|
|
@@ -448,18 +477,49 @@ function buildContext(personaMeta, sharedMeta, agentMap = {}, target, registry)
|
|
|
448
477
|
}
|
|
449
478
|
return merged;
|
|
450
479
|
}
|
|
480
|
+
function validateSubagentRefs(persona, agentMap) {
|
|
481
|
+
const subagents = persona.subagents;
|
|
482
|
+
if (!Array.isArray(subagents) || subagents.length === 0) return [];
|
|
483
|
+
const results = [];
|
|
484
|
+
for (const slug of subagents) {
|
|
485
|
+
const key = `agent_slug_${slug.replace(/-/g, "_")}`;
|
|
486
|
+
if (!(key in agentMap)) {
|
|
487
|
+
results.push({
|
|
488
|
+
severity: "error",
|
|
489
|
+
message: `Persona '${persona.name}' declares subagent '${slug}' but no persona with that slug exists in any configured suite.`
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return results;
|
|
494
|
+
}
|
|
451
495
|
async function buildPersona(personaYamlPath, suiteName, suiteConfig, sharedMeta, partialsMap, config, plugins, target, agentMap = {}, registry = defaultRegistry) {
|
|
452
496
|
const personaMeta = await loadPersonaYaml(personaYamlPath);
|
|
453
|
-
let context = buildContext(
|
|
497
|
+
let context = buildContext({
|
|
498
|
+
personaMeta,
|
|
499
|
+
sharedMeta,
|
|
500
|
+
agentMap,
|
|
501
|
+
target,
|
|
502
|
+
registry,
|
|
503
|
+
configVariables: config.variables,
|
|
504
|
+
suiteVariables: suiteConfig.variables
|
|
505
|
+
});
|
|
454
506
|
const personaMetaTyped = personaMeta;
|
|
455
507
|
context = runBuildContext(plugins, context, personaMetaTyped, suiteConfig, target);
|
|
508
|
+
const personaPartialsMap = runPersonaPartials(
|
|
509
|
+
plugins,
|
|
510
|
+
{ ...partialsMap },
|
|
511
|
+
personaMetaTyped,
|
|
512
|
+
context,
|
|
513
|
+
suiteConfig,
|
|
514
|
+
target
|
|
515
|
+
);
|
|
456
516
|
const fmTemplate = resolveFrontmatterTemplate(target, plugins, config.frontmatter, registry);
|
|
457
517
|
const contentBasename = path4__default.default.basename(personaYamlPath, ".yaml") + ".md";
|
|
458
518
|
const frontmatter = renderFrontmatter(fmTemplate, context, contentBasename);
|
|
459
519
|
const contentSubdir = suiteConfig.contentSubdir ?? "content";
|
|
460
520
|
const contentPath = path4__default.default.join(suiteConfig.srcDir, contentSubdir, contentBasename);
|
|
461
521
|
const bodyTemplate = normalizeNewlines(await promises.readFile(contentPath, "utf8"));
|
|
462
|
-
let body = resolvePartials(bodyTemplate,
|
|
522
|
+
let body = resolvePartials(bodyTemplate, personaPartialsMap);
|
|
463
523
|
body = resolveConditionals(body, context);
|
|
464
524
|
body = resolveVariables(body, context, contentBasename);
|
|
465
525
|
body = collapseBlankLines(body);
|
|
@@ -470,7 +530,10 @@ async function buildPersona(personaYamlPath, suiteName, suiteConfig, sharedMeta,
|
|
|
470
530
|
${body}
|
|
471
531
|
`);
|
|
472
532
|
output = runPostRender(plugins, output, personaMetaTyped, target);
|
|
473
|
-
const validationResults =
|
|
533
|
+
const validationResults = [
|
|
534
|
+
...runValidate(plugins, personaMetaTyped, suiteConfig, target),
|
|
535
|
+
...validateSubagentRefs(personaMetaTyped, agentMap)
|
|
536
|
+
];
|
|
474
537
|
const def = registry.has(target) ? registry.get(target) : void 0;
|
|
475
538
|
const outputDir = resolveOutputDir(target, suiteConfig, def);
|
|
476
539
|
const fnKey = def?.filenameContextKey;
|
|
@@ -497,7 +560,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
|
|
|
497
560
|
const metaSubdir = suiteConfig.metaSubdir ?? "meta";
|
|
498
561
|
const sharedYamlPath = path4__default.default.join(suiteConfig.srcDir, metaSubdir, "_shared.yaml");
|
|
499
562
|
const sharedMeta = await loadRawYaml(sharedYamlPath);
|
|
500
|
-
let partialsMap = {};
|
|
563
|
+
let partialsMap = { ...config.partials ?? {} };
|
|
501
564
|
if (config.sharedPartialsDir && fs.existsSync(config.sharedPartialsDir)) {
|
|
502
565
|
partialsMap = { ...partialsMap, ...await loadPartials(config.sharedPartialsDir) };
|
|
503
566
|
}
|
|
@@ -507,6 +570,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
|
|
|
507
570
|
partialsMap = { ...partialsMap, ...await loadPartials(suitePartialsDir) };
|
|
508
571
|
}
|
|
509
572
|
runSuiteInit(plugins, suiteConfig, sharedMeta);
|
|
573
|
+
partialsMap = runPartials(plugins, partialsMap, suiteName, suiteConfig);
|
|
510
574
|
const personaYamlPaths = await discoverSuitePersonaYamls(suiteConfig);
|
|
511
575
|
const results = [];
|
|
512
576
|
for (const yamlPath of personaYamlPaths) {
|
|
@@ -648,6 +712,8 @@ exports.resolveFrontmatterTemplate = resolveFrontmatterTemplate;
|
|
|
648
712
|
exports.resolvePartials = resolvePartials;
|
|
649
713
|
exports.resolveVariables = resolveVariables;
|
|
650
714
|
exports.runBuildContext = runBuildContext;
|
|
715
|
+
exports.runPartials = runPartials;
|
|
716
|
+
exports.runPersonaPartials = runPersonaPartials;
|
|
651
717
|
exports.runPostRender = runPostRender;
|
|
652
718
|
exports.runSuiteInit = runSuiteInit;
|
|
653
719
|
exports.runValidate = runValidate;
|