first commit

This commit is contained in:
2026-06-14 20:31:10 +08:00
parent c33b143176
commit 1ed3f576fa
51 changed files with 3362 additions and 810 deletions

View File

@@ -5,11 +5,14 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
)
type Config struct {
Port int
AgentDir string
RepoRoot string // pi 仓库根目录pi CLI 子进程的工作目录)
DataDir string // sproutclaw-web 自己的数据目录SQLite 等)
PiCmd string // pi CLI 启动命令(完整路径)
PiArgs []string
@@ -29,11 +32,13 @@ type Config struct {
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")
repoRoot := flag.String("repo-root", "", "pi repo root (pi CLI cwd); defaults to two levels above agent-dir")
dataDir := flag.String("data-dir", "", "sproutclaw-web data dir for SQLite (defaults to ./data)")
piCmd := flag.String("pi-cmd", "", "pi CLI command (may include args, e.g. \"node /path/tsx.mjs /path/cli.ts\")")
frontendDist := flag.String("frontend-dist", "", "path to frontend/dist (defaults to ../frontend/dist relative to binary)")
flag.Parse()
if *agentDir == "" {
// 默认值:当前目录的 .pi/agent
cwd, _ := os.Getwd()
*agentDir = filepath.Join(cwd, ".pi", "agent")
}
@@ -41,9 +46,34 @@ func New() *Config {
cfg := &Config{
Port: *port,
AgentDir: *agentDir,
PiCmd: *piCmd,
RepoRoot: *repoRoot,
DataDir: *dataDir,
}
// repoRoot defaults to the directory two levels above agentDir (.pi/agent -> repo root)
if cfg.RepoRoot == "" {
cfg.RepoRoot = filepath.Dir(filepath.Dir(*agentDir))
}
// dataDir defaults to ./data relative to cwd (run-backend.bat cd's into backend/)
if cfg.DataDir == "" {
cwd, _ := os.Getwd()
cfg.DataDir = filepath.Join(cwd, "data")
}
if abs, err := filepath.Abs(cfg.DataDir); err == nil {
cfg.DataDir = abs
}
// --pi-cmd may include arguments separated by spaces, e.g.
// "node /path/to/tsx/dist/cli.mjs /path/to/pi/cli.ts"
// Split into executable + args so exec.Command receives them correctly.
if parts := strings.Fields(*piCmd); len(parts) > 0 {
cfg.PiCmd = parts[0]
cfg.PiArgs = parts[1:]
}
cfg.derivePaths()
// Override frontend dist if explicitly specified
if *frontendDist != "" {
cfg.FrontendDist = *frontendDist
}
return cfg
}