78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
)
|
|
|
|
type Config struct {
|
|
Port int
|
|
AgentDir string
|
|
PiCmd string // pi CLI 启动命令(完整路径)
|
|
PiArgs []string
|
|
|
|
// 派生路径(从 AgentDir 推导)
|
|
SessionsDir string
|
|
SystemPromptFile string
|
|
ModelsConfigFile string
|
|
McpConfigFile string
|
|
McpCacheFile string
|
|
SettingsFile string
|
|
SkillsDir string
|
|
SkillsDisabledDir string
|
|
ExtensionsDir string
|
|
FrontendDist string // ../frontend/dist 相对于可执行文件
|
|
}
|
|
|
|
func New() *Config {
|
|
port := flag.Int("port", 19133, "HTTP port")
|
|
agentDir := flag.String("agent-dir", "", "pi agent directory (e.g. /path/to/.pi/agent)")
|
|
piCmd := flag.String("pi-cmd", "", "pi CLI executable path")
|
|
flag.Parse()
|
|
|
|
if *agentDir == "" {
|
|
// 默认值:当前目录的 .pi/agent
|
|
cwd, _ := os.Getwd()
|
|
*agentDir = filepath.Join(cwd, ".pi", "agent")
|
|
}
|
|
|
|
cfg := &Config{
|
|
Port: *port,
|
|
AgentDir: *agentDir,
|
|
PiCmd: *piCmd,
|
|
}
|
|
cfg.derivePaths()
|
|
return cfg
|
|
}
|
|
|
|
func (c *Config) derivePaths() {
|
|
a := c.AgentDir
|
|
c.SessionsDir = filepath.Join(a, "sessions")
|
|
c.SystemPromptFile = filepath.Join(a, "AGENTS.md")
|
|
c.ModelsConfigFile = filepath.Join(a, "models.json")
|
|
c.McpConfigFile = filepath.Join(a, "mcp.json")
|
|
c.McpCacheFile = filepath.Join(a, "mcp-cache.json")
|
|
c.SettingsFile = filepath.Join(a, "settings.json")
|
|
c.SkillsDir = filepath.Join(a, "skills")
|
|
c.SkillsDisabledDir = filepath.Join(a, "skills-disabled")
|
|
c.ExtensionsDir = filepath.Join(a, "extensions")
|
|
|
|
// frontend/dist 相对于二进制所在目录的上级
|
|
exe, err := os.Executable()
|
|
if err != nil {
|
|
exe, _ = os.Getwd()
|
|
}
|
|
exeDir := filepath.Dir(exe)
|
|
c.FrontendDist = filepath.Join(exeDir, "..", "frontend", "dist")
|
|
}
|
|
|
|
func Platform() string {
|
|
return runtime.GOOS
|
|
}
|
|
|
|
func Arch() string {
|
|
return runtime.GOARCH
|
|
}
|