Archie runs its own agent loop only. Removes Kit resolution and launch, the harness runner and adapters, the setup terminal and sandbox view, harness secrets and OAuth capture (table dropped in migration 0075), the task-tools contract that only Kit containers reached, and the sandbox-kit-spec dependency. Agent profiles carry image and tools only. The egress proxy keeps the model-session path; the sandbox relay code stays for #1867.
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package archied
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/samcharles93/archie-core/internal/app/servicekit"
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
daemonpb "github.com/samcharles93/archie-core/internal/contracts/daemon/v1"
|
|
"github.com/samcharles93/archie-core/internal/domain/access"
|
|
"github.com/samcharles93/archie-core/internal/domain/presence"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/rpcidentity"
|
|
)
|
|
|
|
// setupDaemonRPC serves the daemon contract. Without certificates it binds
|
|
// only loopback.
|
|
func (b *boot) setupDaemonRPC(ctx context.Context) {
|
|
conn := b.cfg.Services.Get(config.ServiceNameDaemon)
|
|
listen, err := servicekit.ResolveListen(config.ServiceNameDaemon, "", conn.Listen)
|
|
if err != nil {
|
|
b.log.WarnContext(ctx, "daemon contract disabled", "err", err)
|
|
return
|
|
}
|
|
id, err := servicekit.Identity(b.cfg.TLS, presence.Daemon)
|
|
if err != nil {
|
|
b.log.WarnContext(ctx, "daemon contract disabled", "err", err)
|
|
return
|
|
}
|
|
creds, err := id.ServerOption(listen, false)
|
|
if err != nil {
|
|
b.log.WarnContext(ctx, "daemon contract disabled", "err", err)
|
|
return
|
|
}
|
|
ln, err := (&net.ListenConfig{}).Listen(ctx, "tcp", listen)
|
|
if err != nil {
|
|
b.log.WarnContext(ctx, "daemon contract disabled: listen", "err", err)
|
|
return
|
|
}
|
|
workspaces, _ := b.stateStore.(access.WorkspaceLister)
|
|
callers := rpcidentity.Callers{Principals: b.d.Principals, Workspaces: workspaces}
|
|
srv := grpc.NewServer(append(servicekit.ServerLimits(), creds, grpc.ChainUnaryInterceptor(callers.Unary()), grpc.ChainStreamInterceptor(callers.Stream()))...)
|
|
daemonpb.RegisterDaemonServiceServer(srv, &repositoryServer{boot: b})
|
|
go func() {
|
|
if err := srv.Serve(ln); err != nil && !errors.Is(err, grpc.ErrServerStopped) {
|
|
b.log.ErrorContext(ctx, "daemon contract listener stopped", "err", err)
|
|
}
|
|
}()
|
|
b.addCleanup(func() {
|
|
timer := time.AfterFunc(10*time.Second, srv.Stop)
|
|
srv.GracefulStop()
|
|
timer.Stop()
|
|
_ = ln.Close()
|
|
})
|
|
b.log.InfoContext(ctx, "daemon contract serving", "addr", ln.Addr().String())
|
|
}
|