11import { describe , expect , it } from 'vitest' ;
2- import { personaFromAgentOptions } from '../gmiPersona.js' ;
2+ import { agentStableIdOf , derivedSoulPersonaId , personaFromAgentOptions } from '../gmiPersona.js' ;
33import { resolveCognition } from '../gmiCognition.js' ;
44import { buildSystemPrompt , type AgentOptions } from '../../agent.js' ;
55import { ALL_METAPROMPT_PRESETS } from '../../../cognition/substrate/personas/metaprompt_presets.js' ;
6+ import { parseSoul } from '../../../cognition/substrate/personas/SoulLoader.js' ;
67
78const tool = {
89 id : 'lookup-tool' ,
@@ -27,7 +28,8 @@ describe('personaFromAgentOptions', () => {
2728 } ;
2829 const p = personaFromAgentOptions ( opts , resolveCognition ( { } ) , [ ] ) ;
2930 expect ( p ) . toMatchObject ( { id : 'ops-helper' , name : 'Ops Helper' , description : 'Answer briefly.' , version : '1.0.0' , defaultProviderId : 'openai' , defaultModelId : 'gpt-4o' } ) ;
30- expect ( p . baseSystemPrompt ) . toBe ( buildSystemPrompt ( opts ) ) ;
31+ // The persona has traits, so the GMI renders the personality section itself and the base prompt leaves it out.
32+ expect ( p . baseSystemPrompt ) . toBe ( buildSystemPrompt ( { ...opts , personality : undefined } ) ) ;
3133 expect ( p . personalityTraits ) . toMatchObject ( { openness : 0.9 } ) ;
3234 expect ( p . defaultModelCompletionOptions ) . toEqual ( { maxTokens : 300 , effort : 'low' , requestTimeout : 9000 } ) ;
3335 expect ( p . metaPrompts ) . toEqual ( [ ] ) ;
@@ -69,3 +71,54 @@ describe('personaFromAgentOptions', () => {
6971 expect ( idOf ( '助手' ) ) . not . toBe ( idOf ( '秘書' ) ) ;
7072 } ) ;
7173} ) ;
74+
75+ describe ( 'personaFromAgentOptions with a soul' , ( ) => {
76+ const base = { provider : 'openai' , model : 'gpt-4o' } as const ;
77+ const soul = parseSoul (
78+ '---\nname: Aria\nagentId: aria-1\nrole: Support for the clinic\nhexaco:\n honestyHumility: 0.9\ndefaultMood: calm\nallowedMoods: [calm, warm]\n' +
79+ 'hardLimits:\n - Never name a diagnosis.\nreasoningTrace:\n maxEntries: 7\nvoice:\n provider: x\navatar:\n type: y\nmetadata:\n team: care\n---\nYou are Aria.' ,
80+ ) ;
81+
82+ it ( 'takes the id, role, traits, mood, trace limits, hard limits and metadata from the soul, and never its voice or avatar' , ( ) => {
83+ const p = personaFromAgentOptions ( { ...base , instructions : 'Answer briefly.' } , resolveCognition ( { } ) , [ ] , soul ) as unknown as Record < string , unknown > ;
84+ expect ( p ) . toMatchObject ( {
85+ id : 'aria-1' ,
86+ name : 'Aria' ,
87+ description : 'Support for the clinic' ,
88+ personalityTraits : { honesty : 0.9 } ,
89+ moodAdaptation : { enabled : true , defaultMood : 'calm' , allowedMoods : [ 'calm' , 'warm' ] } ,
90+ reasoningTraceConfig : { maxEntries : 7 } ,
91+ hardLimits : [ 'Never name a diagnosis.' ] ,
92+ metadata : { team : 'care' } ,
93+ } ) ;
94+ expect ( p . voiceConfig ) . toBeUndefined ( ) ;
95+ expect ( p . avatarConfig ) . toBeUndefined ( ) ;
96+ // The traits render in the GMI's own section, so the base prompt holds none, and it holds no limits block.
97+ expect ( p . baseSystemPrompt ) . toBe ( buildSystemPrompt ( { ...base , instructions : 'Answer briefly.' } , soul , { personality : false } ) ) ;
98+ expect ( String ( p . baseSystemPrompt ) ) . not . toContain ( '## Hard limits' ) ;
99+ } ) ;
100+
101+ it ( 'lets the name and personality options win, and keeps the id from the soul' , ( ) => {
102+ const p = personaFromAgentOptions ( { ...base , name : 'Support' , personality : { openness : 0.2 } } , resolveCognition ( { } ) , [ ] , soul ) ;
103+ expect ( p ) . toMatchObject ( { id : 'aria-1' , name : 'Support' , personalityTraits : { openness : 0.2 } } ) ;
104+ } ) ;
105+
106+ it ( 'names a soul with a name and no agentId by the slug of that name' , ( ) => {
107+ expect ( personaFromAgentOptions ( { ...base , name : 'Support' } , resolveCognition ( { } ) , [ ] , parseSoul ( '---\nname: Aria Stone\n---\nHi.' ) ) . id ) . toBe ( 'aria-stone' ) ;
108+ } ) ;
109+
110+ it ( 'gives a soul with no agentId and no name, on an agent with no name, an id derived from its text' , ( ) => {
111+ const bare = parseSoul ( '---\nhardLimits:\n - Never guess.\n---\nYou are terse.' ) ;
112+ const other = parseSoul ( '---\nhardLimits:\n - Never guess.\n---\nYou are warm.' ) ;
113+ const id = personaFromAgentOptions ( base , resolveCognition ( { } ) , [ ] , bare ) . id ;
114+ expect ( id ) . toMatch ( / ^ s o u l - [ 0 - 9 a - f ] { 16 } $ / ) ;
115+ expect ( personaFromAgentOptions ( base , resolveCognition ( { } ) , [ ] , bare ) . id ) . toBe ( id ) ;
116+ expect ( derivedSoulPersonaId ( bare ) ) . toBe ( id ) ;
117+ expect ( personaFromAgentOptions ( base , resolveCognition ( { } ) , [ ] , other ) . id ) . not . toBe ( id ) ;
118+ expect ( personaFromAgentOptions ( base , resolveCognition ( { } ) , [ ] , bare ) . hardLimits ) . toEqual ( [ 'Never guess.' ] ) ;
119+ // The derived id is the persona's alone: the agent has no stable id.
120+ expect ( agentStableIdOf ( base , bare ) ) . toBeUndefined ( ) ;
121+ expect ( agentStableIdOf ( { name : 'Ops' } , null ) ) . toBe ( 'ops' ) ;
122+ expect ( agentStableIdOf ( { name : 'Ops' } , soul ) ) . toBe ( 'aria-1' ) ;
123+ } ) ;
124+ } ) ;
0 commit comments