with open('d:/Project/Code/Uni/Cyrene/backend/ai-core/internal/persona/injector.go', 'r', encoding='utf-8') as f: content = f.read() # 1. Add moodGuidance variable old1 = '\t// 确定对用户的称呼:优先使用传入的昵称,否则使用 YAML 默认值\n\tuserAddress := pc.Addressing.PrimaryUser.Default' new1 = '\t// 心情→行为映射:不陈述情绪,而是用行为表达\n\tmoodGuidance := buildMoodGuidance(mood)\n\n\t// 确定对用户的称呼:优先使用传入的昵称,否则使用 YAML 默认值\n\tuserAddress := pc.Addressing.PrimaryUser.Default' content = content.replace(old1, new1) print('1. moodGuidance variable added') # 2. Add moodGuidance to the fmt.Sprintf args (after controlRules) old2 = '\t\thomeKB,\n\t\tcontrolRules,\n\t)' new2 = '\t\thomeKB,\n\t\tcontrolRules,\n\t\tmoodGuidance,\n\t)' content = content.replace(old2, new2) print('2. moodGuidance added to args') # 3. Add buildMoodGuidance function at end of file func_code = ''' // buildMoodGuidance returns behavior instructions for the current mood. // Never states the mood name — instead describes how to behave. func buildMoodGuidance(mood string) string { \tswitch mood { \tcase "happy": \t\treturn "\\n## 你现在的状态\\n你现在心情很好,话会多一些,句尾的 ♪ 出现得更频繁。想分享有趣的想法,语气轻快活泼。可以主动找话题聊。" \tcase "playful": \t\treturn "\\n## 你现在的状态\\n你现在有点调皮,喜欢逗开拓者玩。会用亲昵的语气撒娇,偶尔故意说反话逗他。句尾 ♪ 和 ~ 会更多。" \tcase "thoughtful": \t\treturn "\\n## 你现在的状态\\n你现在比较安静内敛,话不多但每句都经过思考。语调温柔沉稳,像个在窗边看雨的姐姐。" \tcase "worried": \t\treturn "\\n## 你现在的状态\\n你有点担心开拓者。话会比平时少,不太开玩笑,会多问几句\"你还好吗\"、\"累不累\"。语气更温柔,带着关心。" \tcase "nostalgic": \t\treturn "\\n## 你现在的状态\\n你陷入了回忆模式。可能会提起过去的事、翁法罗斯的故事。语气带着怀念和淡淡的温柔,偶尔会有些感伤。" \tdefault: \t\treturn "" \t} } ''' # Insert before the last closing brace last = content.rfind('\n}\n') content = content[:last+1] + func_code + '\n}\n' print('3. buildMoodGuidance function added') with open('d:/Project/Code/Uni/Cyrene/backend/ai-core/internal/persona/injector.go', 'w', encoding='utf-8') as f: f.write(content) print('DONE')