Documentation
¶
Overview ¶
Package backend implements the concrete Harness foreign-loop backend.
Index ¶
- func BuildRestoredWith(backendCfg Config) foreign.RestoredBuilder
- func BuildRestoredWithServices(backendCfg Config) foreign.ServicesRestoredBuilder
- func BuildWith(backendCfg Config) foreign.Builder
- func BuildWithServices(backendCfg Config) foreign.ServicesBuilder
- type Config
- type ConfigError
- type ForeignProtocolError
- type ForeignPublicationError
- type ForeignResultError
- type ForeignSessionBusyError
- type LockError
- type Loop
- type SIDMode
- type SnapshotError
- type SnapshotErrorReason
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildRestoredWith ¶
func BuildRestoredWith(backendCfg Config) foreign.RestoredBuilder
BuildRestoredWith constructs and starts an actor from Harness-folded state through the legacy seam. It withholds all scoped capabilities by invoking the additive builder with zero Services.
func BuildRestoredWithServices ¶
func BuildRestoredWithServices(backendCfg Config) foreign.ServicesRestoredBuilder
BuildRestoredWithServices constructs and starts an actor from Harness-folded state through the additive services-aware seam. The supplied services are copied into the restored actor before it starts.
func BuildWith ¶
BuildWith adapts actor construction to the legacy Harness-owned seam. It withholds all scoped capabilities by invoking the additive builder with zero Services.
Example ¶
package main
import (
"fmt"
"github.com/looprig/foreignloops/backend"
"github.com/looprig/foreignloops/driver"
"github.com/looprig/foreignloops/driver/claude"
"github.com/looprig/harness/pkg/rig"
)
func main() {
workspace := "/srv/agent-workspace"
// The product provisions this private directory writable by the provider.
providerHome := "/srv/looprig/provider-home"
parentEnv := []string{
"HOME=" + providerHome,
"PATH=/usr/local/bin:/usr/bin",
}
agent, err := claude.NewAgent(parentEnv, claude.Config{
ExecPath: "/usr/local/bin/claude",
Home: providerHome,
Model: "claude-sonnet-4-20250514",
EnvAllow: []string{"HOME", "PATH"},
})
if err != nil {
fmt.Printf("configure Claude agent: %v\n", err)
return
}
cfg := backend.Config{
Agent: agent,
Cwd: workspace,
Posture: driver.PostureAcceptEdits,
SIDMode: backend.SIDPrebound,
}
option := rig.WithForeignBuilders(
backend.BuildWith(cfg),
backend.BuildRestoredWith(cfg),
)
_ = option // Apply this option at the product's Harness composition root.
}
Output:
func BuildWithServices ¶
func BuildWithServices(backendCfg Config) foreign.ServicesBuilder
BuildWithServices adapts actor construction to the additive Harness seam. The supplied services are copied into the actor before it starts.
Types ¶
type Config ¶
type Config struct {
Agent driver.Agent
Cwd string
Posture driver.PermissionPosture
SIDMode SIDMode
}
Config is the composition-root wiring consumed by the generic backend. Provider process and environment settings belong to concrete driver configs.
type ConfigError ¶
type ConfigError struct{ Field, Reason string }
ConfigError reports invalid backend composition or runtime wiring.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
type ForeignProtocolError ¶
type ForeignProtocolError struct{ Reason string }
ForeignProtocolError reports a stream that ended without a result terminal.
func (*ForeignProtocolError) Error ¶
func (e *ForeignProtocolError) Error() string
type ForeignPublicationError ¶
ForeignPublicationError reports a checked lifecycle event that the session publisher rejected. The actor must stop rather than continue with a local state transition that is absent from the durable event stream.
func (*ForeignPublicationError) Error ¶
func (e *ForeignPublicationError) Error() string
func (*ForeignPublicationError) Unwrap ¶
func (e *ForeignPublicationError) Unwrap() error
type ForeignResultError ¶
type ForeignResultError struct{ Detail string }
ForeignResultError reports a result-level failure sent by the foreign agent.
func (*ForeignResultError) Error ¶
func (e *ForeignResultError) Error() string
type ForeignSessionBusyError ¶
ForeignSessionBusyError reports that another process holds the liveness lock for the same foreign session and workspace.
func (*ForeignSessionBusyError) Error ¶
func (e *ForeignSessionBusyError) Error() string
type Loop ¶
type Loop struct {
Commands chan command.Command
Done chan struct{}
// contains filtered or unexported fields
}
Loop holds the backend actor's immutable dependencies and actor-owned state. Only the run goroutine mutates messages, turn state, binding, and the queue.
func New ¶
func New(loopCtx context.Context, sessionID, loopID uuid.UUID, parent loop.Provenance, pub foreign.EventPublisher, loopCfg loop.BoundDefinition, backendCfg Config, idGen func() (uuid.UUID, error), fac *event.Factory, ) (*Loop, string, error)
New validates the composition wiring, binds an initial session ID when requested, and starts the single-owner backend actor.
func (*Loop) CommandSink ¶
type SIDMode ¶
type SIDMode uint8
SIDMode selects whether the foreign session ID is known when the loop is constructed or learned later from the agent's first initialization event.
type SnapshotError ¶
type SnapshotError struct {
Reason SnapshotErrorReason
Cause error
}
SnapshotError reports that the backend could not return a consistent view of its committed state.
func (*SnapshotError) Error ¶
func (e *SnapshotError) Error() string
func (*SnapshotError) Unwrap ¶
func (e *SnapshotError) Unwrap() error
type SnapshotErrorReason ¶
type SnapshotErrorReason string
SnapshotErrorReason classifies why a consistent backend snapshot was not available.
const ( SnapshotLoopExited SnapshotErrorReason = "loop_exited" // SnapshotUnsupportedContent means the committed state holds a content // value this module's deep copy does not recognize, so no consistent // defensive view can be produced. SnapshotUnsupportedContent SnapshotErrorReason = "unsupported_content" SnapshotContextDone SnapshotErrorReason = "context_done" )