82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
//go:build ignore
|
||
|
||
package main
|
||
|
||
import (
|
||
"os"
|
||
"strings"
|
||
)
|
||
|
||
func main() {
|
||
// === Fix 1: advice_wx.go - project info from MySQL Base.Name ===
|
||
f1 := "internal/biz/advice_wx.go"
|
||
b1, _ := os.ReadFile(f1)
|
||
lines1 := strings.Split(string(b1), "\n")
|
||
var out1 []string
|
||
for i := 0; i < len(lines1); i++ {
|
||
line := lines1[i]
|
||
trimmed := strings.TrimSpace(line)
|
||
|
||
// Replace the project info block (L468-L477 area)
|
||
if trimmed == `if pi := projectInfo.ConfigInfo.ProjectInfo; pi.Name != "" || pi.Address != "" {` {
|
||
// Get the indent
|
||
indent := line[:len(line)-len(strings.TrimLeft(line, "\t"))]
|
||
// Replace with new code that uses Base.Name
|
||
out1 = append(out1, indent+`// 项目信息:优先用 MySQL 的 Base.Name(一定有),MongoDB 的 ProjectInfo 作为补充`)
|
||
out1 = append(out1, indent+`projectDesc := "\n[项目信息]"`)
|
||
out1 = append(out1, indent+`hasProjectInfo := false`)
|
||
out1 = append(out1, indent+`if projectInfo.Base.Name != "" {`)
|
||
out1 = append(out1, indent+` projectDesc += "\n项目名称:" + projectInfo.Base.Name`)
|
||
out1 = append(out1, indent+` hasProjectInfo = true`)
|
||
out1 = append(out1, indent+`}`)
|
||
out1 = append(out1, indent+`if pi := projectInfo.ConfigInfo.ProjectInfo; pi.Address != "" {`)
|
||
out1 = append(out1, indent+` projectDesc += "\n项目地址:" + pi.Address`)
|
||
out1 = append(out1, indent+` hasProjectInfo = true`)
|
||
out1 = append(out1, indent+`}`)
|
||
out1 = append(out1, indent+`if hasProjectInfo {`)
|
||
out1 = append(out1, indent+` mission = mission + projectDesc`)
|
||
// Skip the old block (find closing })
|
||
braceCount := 0
|
||
for i < len(lines1)-1 {
|
||
i++
|
||
for _, ch := range lines1[i] {
|
||
if ch == '{' {
|
||
braceCount++
|
||
}
|
||
if ch == '}' {
|
||
braceCount--
|
||
}
|
||
}
|
||
if braceCount < 0 {
|
||
break
|
||
}
|
||
}
|
||
continue
|
||
}
|
||
out1 = append(out1, line)
|
||
}
|
||
os.WriteFile(f1, []byte(strings.Join(out1, "\n")), 0644)
|
||
println("fix1: project info updated")
|
||
|
||
// === Fix 2: advice_chat.go - add persona diagnostic log ===
|
||
f2 := "internal/biz/advice_chat.go"
|
||
b2, _ := os.ReadFile(f2)
|
||
s2 := string(b2)
|
||
|
||
old2 := "\tif v == nil || len(v) == 0 {\n\t\treturn \"\"\n\t}\n\tvar b strings.Builder"
|
||
new2 := "\tif v == nil || len(v) == 0 {\n\t\treturn \"\"\n\t}\n" +
|
||
"\t// 诊断:打印每个维度的实际类型\n" +
|
||
"\tfor _k, _val := range v {\n" +
|
||
"\t\tlog.Infof(\"[人设诊断] key=%q type=%T\", _k, _val)\n" +
|
||
"\t}\n" +
|
||
"\tvar b strings.Builder"
|
||
|
||
if strings.Contains(s2, old2) {
|
||
s2 = strings.Replace(s2, old2, new2, 1)
|
||
os.WriteFile(f2, []byte(s2), 0644)
|
||
println("fix2: persona diagnostic log added")
|
||
} else {
|
||
println("fix2: WARNING - block not found")
|
||
}
|
||
}
|