init: ops-assistant codebase

This commit is contained in:
OpenClaw Agent
2026-03-19 21:23:28 +08:00
commit 81deba4766
94 changed files with 10767 additions and 0 deletions

66
cmd/runbook_test.go Normal file
View File

@@ -0,0 +1,66 @@
//go:build runbooktest
// +build runbooktest
package main
import (
"fmt"
"os"
"path/filepath"
"ops-assistant/internal/core/ops"
)
func main() {
if len(os.Args) < 4 {
fmt.Println("usage: runbook_test <db_path> <base_dir> <command_text>")
os.Exit(2)
}
dbPath := os.Args[1]
baseDir := os.Args[2]
cmd := os.Args[3]
inputs := map[string]string{}
// minimal parse for /cf dnsadd <name> <content> [true] [type]
parts := split(cmd)
if len(parts) >= 4 && parts[0] == "/cf" && parts[1] == "dnsadd" {
inputs["name"] = parts[2]
inputs["content"] = parts[3]
inputs["type"] = "A"
inputs["proxied"] = "false"
if len(parts) >= 5 {
if parts[4] == "true" {
inputs["proxied"] = "true"
if len(parts) >= 6 {
inputs["type"] = parts[5]
}
} else {
inputs["type"] = parts[4]
}
}
}
jobID, _, err := ops.RunOnce(dbPath, filepath.Clean(baseDir), cmd, "cf_dns_add", 1, inputs)
if err != nil {
fmt.Printf("ERR: %v\n", err)
os.Exit(1)
}
fmt.Printf("OK job=%d\n", jobID)
}
func split(s string) []string {
out := []string{}
cur := ""
for _, r := range s {
if r == ' ' || r == '\t' || r == '\n' {
if cur != "" {
out = append(out, cur)
cur = ""
}
continue
}
cur += string(r)
}
if cur != "" {
out = append(out, cur)
}
return out
}