Skip to content

Commit 8d80e34

Browse files
teovlclaude
andcommitted
fix(embedded): restore PilotEmbeddedStart now that web4 #155 merged
PR #155 (satisfy daemonapi.Daemon via adapter) landed on web4 main as 6c45b716, making d.DaemonAPI() available. This commit removes the stub error and wires the real boot path: daemon.New → DaemonAPI() → runtime.New → register trustedagents/handshake/policy plugins → StartPlugins → Start. go.mod promotes handshake, policy, trustedagents to direct dependencies and picks up minor upstream bumps (common v0.5.5, coder/websocket v1.8.15, golang.org/x/sys v0.46.0) from go mod tidy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1a187b7 commit 8d80e34

3 files changed

Lines changed: 71 additions & 19 deletions

File tree

embedded.go

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ import (
3333
"sync"
3434
"time"
3535

36+
"github.com/pilot-protocol/common/crypto"
37+
"github.com/pilot-protocol/handshake"
3638
"github.com/pilot-protocol/pilotprotocol/pkg/daemon"
37-
39+
"github.com/pilot-protocol/policy"
3840
"github.com/pilot-protocol/runtime"
41+
"github.com/pilot-protocol/trustedagents"
3942
)
4043

4144
type embeddedNode struct {
@@ -105,14 +108,63 @@ func PilotEmbeddedStart(configJSON *C.char) *C.char {
105108

106109
identityPath := filepath.Join(cfg.DataDir, "identity.json")
107110

108-
// TODO(libpilot): the embedded daemon boot path depends on
109-
// d.DaemonAPI() (TeoSlayer/pilotprotocol#155 — "satisfy daemonapi.Daemon
110-
// via adapter") which has not landed on web4 main. Once #155 merges,
111-
// restore the daemon.New + runtime.New + plugin registration block
112-
// removed in this stub. Until then PilotEmbeddedStart returns a clear
113-
// runtime error so the C ABI surface keeps compiling.
114-
_ = identityPath
115-
return errJSON(fmt.Errorf("embedded daemon not implemented yet — blocked on web4 #155 (daemon.DaemonAPI adapter)"))
111+
d := daemon.New(daemon.Config{
112+
RegistryAddr: cfg.RegistryAddr,
113+
BeaconAddr: cfg.BeaconAddr,
114+
SocketPath: cfg.SocketPath,
115+
IdentityPath: identityPath,
116+
TrustAutoApprove: cfg.TrustAutoApprove,
117+
KeepaliveInterval: time.Duration(cfg.KeepaliveSec) * time.Second,
118+
Version: cfg.Version,
119+
Encrypt: true,
120+
})
121+
122+
dapi := d.DaemonAPI()
123+
rt := runtime.New(dapi)
124+
125+
// Register trust + handshake plugin (mirrors cmd/daemon composition root).
126+
ta := trustedagents.NewService()
127+
if err := rt.Register(ta); err != nil {
128+
return errJSON(fmt.Errorf("register trustedagents: %w", err))
129+
}
130+
d.RegisterTrustChecker(ta)
131+
132+
hsSvc := handshake.NewService(runtime.NewHandshakeRuntime(dapi))
133+
if err := rt.Register(hsSvc); err != nil {
134+
return errJSON(fmt.Errorf("register handshake: %w", err))
135+
}
136+
d.RegisterHandshakeService(runtime.NewHandshakeServiceAdapter(hsSvc))
137+
138+
policySvc := policy.NewService(runtime.NewPolicyRuntime(dapi))
139+
if err := rt.Register(policySvc); err != nil {
140+
return errJSON(fmt.Errorf("register policy: %w", err))
141+
}
142+
d.RegisterPolicyManager(runtime.AsDaemonPolicyManager(policySvc.Manager()))
143+
144+
startCtx := context.Background()
145+
if err := rt.StartPlugins(startCtx); err != nil {
146+
return errJSON(fmt.Errorf("plugin startup: %w", err))
147+
}
148+
149+
if err := d.Start(); err != nil {
150+
_ = rt.StopPlugins(startCtx)
151+
return errJSON(fmt.Errorf("daemon start: %w", err))
152+
}
153+
154+
// Build the success payload. Public key may be empty for ephemeral
155+
// (no-identity) mode — callers should handle that.
156+
pubKey := ""
157+
if id := d.Identity(); id != nil {
158+
pubKey = crypto.EncodePublicKey(id.PublicKey)
159+
}
160+
161+
embedded.node = &embeddedNode{d: d, rt: rt}
162+
return okJSON(map[string]interface{}{
163+
"address": fmt.Sprintf("%d", d.NodeID()),
164+
"node_id": d.NodeID(),
165+
"public_key": pubKey,
166+
"socket": cfg.SocketPath,
167+
})
116168
}
117169

118170
// Tear down the embedded daemon and all plugins. Safe to call when

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ module github.com/pilot-protocol/libpilot
33
go 1.25.10
44

55
require (
6+
github.com/pilot-protocol/common v0.5.5
7+
github.com/pilot-protocol/handshake v0.2.1
68
github.com/pilot-protocol/pilotprotocol v1.10.5
7-
github.com/pilot-protocol/common v0.4.8
9+
github.com/pilot-protocol/policy v0.2.2
810
github.com/pilot-protocol/runtime v0.3.1
11+
github.com/pilot-protocol/trustedagents v0.2.3
912
)
1013

1114
require (
12-
github.com/coder/websocket v1.8.14 // indirect
15+
github.com/coder/websocket v1.8.15 // indirect
1316
github.com/expr-lang/expr v1.17.8 // indirect
14-
github.com/pilot-protocol/handshake v0.2.1 // indirect
15-
github.com/pilot-protocol/policy v0.2.2 // indirect
16-
github.com/pilot-protocol/trustedagents v0.2.3 // indirect
17-
golang.org/x/sys v0.45.0 // indirect
17+
golang.org/x/sys v0.46.0 // indirect
1818
)
1919

2020
replace github.com/pilot-protocol/pilotprotocol => ../web4

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
2-
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
1+
github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=
2+
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
33
github.com/expr-lang/expr v1.17.8 h1:W1loDTT+0PQf5YteHSTpju2qfUfNoBt4yw9+wOEU9VM=
44
github.com/expr-lang/expr v1.17.8/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
5-
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
6-
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
5+
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
6+
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=

0 commit comments

Comments
 (0)