feat: add remote config and host metadata

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-02 14:27:39 +08:00
parent 1e7efd9c3b
commit 1e33bfa4bc
4 changed files with 99 additions and 3 deletions
+13 -1
View File
@@ -12,6 +12,7 @@ type Config struct {
Events Events `toml:"events"`
Notify Notify `toml:"notify"`
Inbox Inbox `toml:"inbox"`
Remote Remote `toml:"remote"`
}
type Events struct {
@@ -38,6 +39,13 @@ type Inbox struct {
TimeoutMS int `toml:"timeout_ms"`
}
type Remote struct {
Enabled bool `toml:"enabled"`
URL string `toml:"url"`
Token string `toml:"token"`
TimeoutMS int `toml:"timeout_ms"`
}
func Default() Config {
return Config{
Events: Events{Stop: true, Response: true, Idle: false, Tool: false},
@@ -49,13 +57,17 @@ func Default() Config {
BodyTool: "工具执行完成",
},
Inbox: Inbox{
Enabled: true,
Enabled: false,
Socket: DefaultInboxSocket(),
RemoteSocket: DefaultInboxRemoteSocket(),
Addr: "127.0.0.1:17777",
FallbackLocal: true,
TimeoutMS: 500,
},
Remote: Remote{
Enabled: false,
TimeoutMS: 2000,
},
}
}
+12 -2
View File
@@ -18,8 +18,8 @@ func TestDefaultConfig(t *testing.T) {
if cfg.Notify.Protocol != "osc777" {
t.Fatalf("expected osc777, got %q", cfg.Notify.Protocol)
}
if !cfg.Inbox.Enabled {
t.Fatal("expected inbox enabled by default")
if cfg.Inbox.Enabled {
t.Fatal("expected inbox disabled by default")
}
if cfg.Inbox.Addr != "127.0.0.1:17777" {
t.Fatalf("expected default inbox addr, got %q", cfg.Inbox.Addr)
@@ -104,6 +104,16 @@ func TestDefaultInboxSocketPrefersXDGRuntimeDir(t *testing.T) {
}
}
func TestDefaultRemoteDisabledInbox(t *testing.T) {
cfg := Default()
if cfg.Inbox.Enabled {
t.Fatal("inbox should default disabled")
}
if cfg.Remote.TimeoutMS != 2000 {
t.Fatalf("remote timeout: got %d", cfg.Remote.TimeoutMS)
}
}
func TestEventEnabled(t *testing.T) {
cfg := Default()
if !cfg.EventEnabled("stop") {
+55
View File
@@ -0,0 +1,55 @@
package hostmeta
import (
"net"
"os"
"sort"
)
func Hostname() (string, error) {
return os.Hostname()
}
func IPs() []string {
seen := make(map[string]struct{})
var ips []string
ifaces, err := net.Interfaces()
if err != nil {
return nil
}
for _, iface := range ifaces {
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
continue
}
addrs, err := iface.Addrs()
if err != nil {
continue
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
default:
continue
}
if ip == nil || ip.IsLoopback() {
continue
}
if ip4 := ip.To4(); ip4 != nil {
ip = ip4
}
s := ip.String()
if _, ok := seen[s]; ok {
continue
}
seen[s] = struct{}{}
ips = append(ips, s)
}
}
sort.Strings(ips)
return ips
}
+19
View File
@@ -0,0 +1,19 @@
package hostmeta
import "testing"
func TestHostnameNonEmpty(t *testing.T) {
h, err := Hostname()
if err != nil || h == "" {
t.Fatalf("hostname: %q err=%v", h, err)
}
}
func TestIPsSkipsLoopback(t *testing.T) {
ips := IPs()
for _, ip := range ips {
if ip == "127.0.0.1" || ip == "::1" {
t.Fatalf("loopback in ips: %v", ips)
}
}
}