Unfortunately at the moment morale boost types are hardcoded, meaning that even if you got the boost working through lua, you’d have to either override optimist (ie. make the new mutation incompatible with it and use the same morale message), edit the sources or use some other morale type and have wrong messages.
Another problem is that there aren’t many lua hooks implemented yet. The closest one would be on_day_passed, but this doesn’t trigger until the end of the first day.
If it’s OK for the trait not to work in the first day and use the optimist message, the lua function would look roughly like:
function MOD.on_day_passed()
player:add_morale("MORALE_PERM_OPTIMIST", bonus_value_here, bonus_value_here, 10 * 60 * 24, 10 * 60 * 24)
end
For example on how to set up the mod, check the existing StatsThroughSkills mod. Actually just copy it and change the .on_day_passed to what I provided above, then adjust until it works.