@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/cli.js
CHANGED
|
@@ -123,7 +123,7 @@ function runBuildContext(plugins, ctx, persona, suite, target) {
|
|
|
123
123
|
let accumulated = ctx;
|
|
124
124
|
for (const plugin of plugins) {
|
|
125
125
|
if (typeof plugin.onBuildContext === "function") {
|
|
126
|
-
accumulated = plugin.onBuildContext(accumulated, persona, suite, target);
|
|
126
|
+
accumulated = plugin.onBuildContext(accumulated, persona, suite, target) ?? accumulated;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
return accumulated;
|
|
@@ -132,11 +132,29 @@ function runPostRender(plugins, rendered, persona, target) {
|
|
|
132
132
|
let output = rendered;
|
|
133
133
|
for (const plugin of plugins) {
|
|
134
134
|
if (typeof plugin.onPostRender === "function") {
|
|
135
|
-
output = plugin.onPostRender(output, persona, target);
|
|
135
|
+
output = plugin.onPostRender(output, persona, target) ?? output;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
return output;
|
|
139
139
|
}
|
|
140
|
+
function runPartials(plugins, partialsMap, suiteName, suite) {
|
|
141
|
+
let accumulated = partialsMap;
|
|
142
|
+
for (const plugin of plugins) {
|
|
143
|
+
if (typeof plugin.onPartials === "function") {
|
|
144
|
+
accumulated = plugin.onPartials(accumulated, suiteName, suite) ?? accumulated;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return accumulated;
|
|
148
|
+
}
|
|
149
|
+
function runPersonaPartials(plugins, partialsMap, persona, context, suite, target) {
|
|
150
|
+
let accumulated = partialsMap;
|
|
151
|
+
for (const plugin of plugins) {
|
|
152
|
+
if (typeof plugin.onPersonaPartials === "function") {
|
|
153
|
+
accumulated = plugin.onPersonaPartials(accumulated, persona, context, suite, target) ?? accumulated;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return accumulated;
|
|
157
|
+
}
|
|
140
158
|
function runValidate(plugins, persona, suite, target) {
|
|
141
159
|
const results = [];
|
|
142
160
|
for (const plugin of plugins) {
|
|
@@ -359,9 +377,20 @@ async function buildAgentNameMap(config) {
|
|
|
359
377
|
}
|
|
360
378
|
return agentMap;
|
|
361
379
|
}
|
|
362
|
-
function buildContext(
|
|
380
|
+
function buildContext(options) {
|
|
381
|
+
const {
|
|
382
|
+
personaMeta,
|
|
383
|
+
sharedMeta,
|
|
384
|
+
agentMap = {},
|
|
385
|
+
target,
|
|
386
|
+
registry,
|
|
387
|
+
configVariables,
|
|
388
|
+
suiteVariables
|
|
389
|
+
} = options;
|
|
363
390
|
const version = typeof personaMeta["version"] === "string" ? personaMeta["version"] : typeof sharedMeta["default_version"] === "string" ? sharedMeta["default_version"] : "0.0.0";
|
|
364
391
|
const merged = {
|
|
392
|
+
...configVariables ?? {},
|
|
393
|
+
...suiteVariables ?? {},
|
|
365
394
|
...sharedMeta,
|
|
366
395
|
...personaMeta,
|
|
367
396
|
version
|
|
@@ -414,18 +443,49 @@ function buildContext(personaMeta, sharedMeta, agentMap = {}, target, registry)
|
|
|
414
443
|
}
|
|
415
444
|
return merged;
|
|
416
445
|
}
|
|
446
|
+
function validateSubagentRefs(persona, agentMap) {
|
|
447
|
+
const subagents = persona.subagents;
|
|
448
|
+
if (!Array.isArray(subagents) || subagents.length === 0) return [];
|
|
449
|
+
const results = [];
|
|
450
|
+
for (const slug of subagents) {
|
|
451
|
+
const key = `agent_slug_${slug.replace(/-/g, "_")}`;
|
|
452
|
+
if (!(key in agentMap)) {
|
|
453
|
+
results.push({
|
|
454
|
+
severity: "error",
|
|
455
|
+
message: `Persona '${persona.name}' declares subagent '${slug}' but no persona with that slug exists in any configured suite.`
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return results;
|
|
460
|
+
}
|
|
417
461
|
async function buildPersona(personaYamlPath, suiteName, suiteConfig, sharedMeta, partialsMap, config, plugins, target, agentMap = {}, registry = defaultRegistry) {
|
|
418
462
|
const personaMeta = await loadPersonaYaml(personaYamlPath);
|
|
419
|
-
let context = buildContext(
|
|
463
|
+
let context = buildContext({
|
|
464
|
+
personaMeta,
|
|
465
|
+
sharedMeta,
|
|
466
|
+
agentMap,
|
|
467
|
+
target,
|
|
468
|
+
registry,
|
|
469
|
+
configVariables: config.variables,
|
|
470
|
+
suiteVariables: suiteConfig.variables
|
|
471
|
+
});
|
|
420
472
|
const personaMetaTyped = personaMeta;
|
|
421
473
|
context = runBuildContext(plugins, context, personaMetaTyped, suiteConfig, target);
|
|
474
|
+
const personaPartialsMap = runPersonaPartials(
|
|
475
|
+
plugins,
|
|
476
|
+
{ ...partialsMap },
|
|
477
|
+
personaMetaTyped,
|
|
478
|
+
context,
|
|
479
|
+
suiteConfig,
|
|
480
|
+
target
|
|
481
|
+
);
|
|
422
482
|
const fmTemplate = resolveFrontmatterTemplate(target, plugins, config.frontmatter, registry);
|
|
423
483
|
const contentBasename = path2.basename(personaYamlPath, ".yaml") + ".md";
|
|
424
484
|
const frontmatter = renderFrontmatter(fmTemplate, context, contentBasename);
|
|
425
485
|
const contentSubdir = suiteConfig.contentSubdir ?? "content";
|
|
426
486
|
const contentPath = path2.join(suiteConfig.srcDir, contentSubdir, contentBasename);
|
|
427
487
|
const bodyTemplate = normalizeNewlines(await readFile(contentPath, "utf8"));
|
|
428
|
-
let body = resolvePartials(bodyTemplate,
|
|
488
|
+
let body = resolvePartials(bodyTemplate, personaPartialsMap);
|
|
429
489
|
body = resolveConditionals(body, context);
|
|
430
490
|
body = resolveVariables(body, context, contentBasename);
|
|
431
491
|
body = collapseBlankLines(body);
|
|
@@ -436,7 +496,10 @@ async function buildPersona(personaYamlPath, suiteName, suiteConfig, sharedMeta,
|
|
|
436
496
|
${body}
|
|
437
497
|
`);
|
|
438
498
|
output = runPostRender(plugins, output, personaMetaTyped, target);
|
|
439
|
-
const validationResults =
|
|
499
|
+
const validationResults = [
|
|
500
|
+
...runValidate(plugins, personaMetaTyped, suiteConfig, target),
|
|
501
|
+
...validateSubagentRefs(personaMetaTyped, agentMap)
|
|
502
|
+
];
|
|
440
503
|
const def = registry.has(target) ? registry.get(target) : void 0;
|
|
441
504
|
const outputDir = resolveOutputDir(target, suiteConfig, def);
|
|
442
505
|
const fnKey = def?.filenameContextKey;
|
|
@@ -463,7 +526,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
|
|
|
463
526
|
const metaSubdir = suiteConfig.metaSubdir ?? "meta";
|
|
464
527
|
const sharedYamlPath = path2.join(suiteConfig.srcDir, metaSubdir, "_shared.yaml");
|
|
465
528
|
const sharedMeta = await loadRawYaml(sharedYamlPath);
|
|
466
|
-
let partialsMap = {};
|
|
529
|
+
let partialsMap = { ...config.partials ?? {} };
|
|
467
530
|
if (config.sharedPartialsDir && existsSync(config.sharedPartialsDir)) {
|
|
468
531
|
partialsMap = { ...partialsMap, ...await loadPartials(config.sharedPartialsDir) };
|
|
469
532
|
}
|
|
@@ -473,6 +536,7 @@ async function buildSuite(suiteName, suiteConfig, config, plugins, target, agent
|
|
|
473
536
|
partialsMap = { ...partialsMap, ...await loadPartials(suitePartialsDir) };
|
|
474
537
|
}
|
|
475
538
|
runSuiteInit(plugins, suiteConfig, sharedMeta);
|
|
539
|
+
partialsMap = runPartials(plugins, partialsMap, suiteName, suiteConfig);
|
|
476
540
|
const personaYamlPaths = await discoverSuitePersonaYamls(suiteConfig);
|
|
477
541
|
const results = [];
|
|
478
542
|
for (const yamlPath of personaYamlPaths) {
|