// The power module's Go bundle (novox/hq ADR 0211, ADR 0198): one process the node's runtime // launches, serving the module's tools over MCP on stdio and running its watcher beside them, which // publishes the machine's power states on the bus. // // Started as `power draw` it is the module's other process instead: the sampler that publishes the // power the machine draws for the bar, as root, because the energy counter is root's (draw.go). package main import ( "context" "fmt" "os" "os/signal" "syscall" stdio "git.novox.be/novox/mesh-sdk/go" ) func main() { if len(os.Args) > 1 { if os.Args[1] != "draw" || len(os.Args) != 2 { fmt.Fprintln(os.Stderr, "usage: power [draw]") os.Exit(2) } ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, os.Interrupt) defer stop() if err := RunDraw(ctx, Here()); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } return } m := Here() w := NewWatcher(m, func(eventType string, body any) error { return stdio.Emit(eventType, body) }, DialLogin1) ctx, cancel := context.WithCancel(context.Background()) defer cancel() go w.Run(ctx) // And the power drawn, from the module's own sampler onto the bus (novox/hq ADR 0260). go ShareDraw(m) if err := stdio.Serve("", Tools(m, w)); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }