go-devops/cmd/dev/cmd_bundles.go
Snider ecb50796b7 refactor: migrate core import to dappco.re/go/core
Replace forge.lthn.ai/core/go/pkg/core with dappco.re/go/core v0.4.7.
Adapt to new API: core.New() returns *Core directly, services registered
via c.Service(), Result replaces (any, bool, error) IPC pattern.
Simplify git/agentic integration by calling package-level functions
directly instead of routing through IPC service handlers.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-21 12:24:45 +00:00

66 lines
1.4 KiB
Go

package dev
import (
"context"
"fmt"
"dappco.re/go/core"
)
// WorkBundle contains the Core instance for dev work operations.
type WorkBundle struct {
Core *core.Core
}
// WorkBundleOptions configures the work bundle.
type WorkBundleOptions struct {
RegistryPath string
}
// NewWorkBundle creates a bundle for dev work operations.
// Includes: dev (orchestration) service.
func NewWorkBundle(opts WorkBundleOptions) (*WorkBundle, error) {
c := core.New()
svc := &Service{
ServiceRuntime: core.NewServiceRuntime(c, ServiceOptions{
RegistryPath: opts.RegistryPath,
}),
}
c.Service("dev", core.Service{
OnStart: func() core.Result {
c.RegisterTask(svc.handleTask)
return core.Result{OK: true}
},
})
c.LockEnable()
c.LockApply()
return &WorkBundle{Core: c}, nil
}
// Start initialises the bundle services.
func (b *WorkBundle) Start(ctx context.Context) error {
return resultError(b.Core.ServiceStartup(ctx, nil))
}
// Stop shuts down the bundle services.
func (b *WorkBundle) Stop(ctx context.Context) error {
return resultError(b.Core.ServiceShutdown(ctx))
}
// resultError extracts an error from a failed core.Result, returning nil on success.
func resultError(r core.Result) error {
if !r.OK {
if err, ok := r.Value.(error); ok {
return err
}
if r.Value != nil {
return fmt.Errorf("service operation failed: %v", r.Value)
}
return fmt.Errorf("service operation failed")
}
return nil
}