🎨 移除多余模块

This commit is contained in:
2026-04-08 12:19:24 +08:00
parent 22bb5fdc94
commit 7599146f24
192 changed files with 623 additions and 13983 deletions

View File

@@ -1,7 +1,6 @@
package main
import (
"bufio"
"errors"
"flag"
"fmt"
@@ -16,8 +15,7 @@ import (
)
type standaloneConfig struct {
MCP config.MCP `yaml:"mcp"`
AutoCode config.Autocode `yaml:"autocode"`
MCP config.MCP `yaml:"mcp"`
}
func loadStandaloneConfig() (string, error) {
@@ -39,7 +37,6 @@ func loadStandaloneConfig() (string, error) {
applyStandaloneDefaults(configPath, &cfg)
global.GVA_CONFIG.MCP = cfg.MCP
global.GVA_CONFIG.AutoCode = cfg.AutoCode
return configPath, nil
}
@@ -122,68 +119,6 @@ func applyStandaloneDefaults(configPath string, cfg *standaloneConfig) {
cfg.MCP.BaseURL = fmt.Sprintf("http://127.0.0.1:%d%s", cfg.MCP.Addr, cfg.MCP.Path)
}
configDir := filepath.Dir(configPath)
if cfg.AutoCode.Server == "" {
cfg.AutoCode.Server = "server"
}
if cfg.AutoCode.Web == "" {
cfg.AutoCode.Web = "web/src"
}
if cfg.AutoCode.Root == "" {
if root, err := detectProjectRoot(configDir); err == nil {
cfg.AutoCode.Root = root
}
} else if !filepath.IsAbs(cfg.AutoCode.Root) {
cfg.AutoCode.Root = filepath.Clean(filepath.Join(configDir, cfg.AutoCode.Root))
}
if cfg.AutoCode.Module == "" && cfg.AutoCode.Root != "" {
goModPath := filepath.Join(cfg.AutoCode.Root, cfg.AutoCode.Server, "go.mod")
if module, err := detectGoModule(goModPath); err == nil {
cfg.AutoCode.Module = module
}
}
}
func detectProjectRoot(startDir string) (string, error) {
dir := startDir
for {
serverDir := filepath.Join(dir, "server")
webDir := filepath.Join(dir, "web")
if isDir(serverDir) && isDir(webDir) {
return dir, nil
}
parent := filepath.Dir(dir)
if parent == dir {
break
}
dir = parent
}
return "", errors.New("未能自动识别项目根目录,请在 MCP 配置中设置 autocode.root")
}
func detectGoModule(goModPath string) (string, error) {
file, err := os.Open(goModPath)
if err != nil {
return "", err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if strings.HasPrefix(line, "module ") {
return strings.TrimSpace(strings.TrimPrefix(line, "module ")), nil
}
}
if err := scanner.Err(); err != nil {
return "", err
}
return "", errors.New("go.mod 中未找到 module 定义")
}
func isDir(path string) bool {