backend

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package backend implements the concrete Harness foreign-loop backend.

Index

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

func BuildWith(backendCfg Config) foreign.Builder

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.
}

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

type ForeignPublicationError struct {
	Event string
	Cause error
}

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

type ForeignSessionBusyError struct {
	SID, Cwd string
	PID      int
}

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 LockError

type LockError struct {
	Op    string
	Path  string
	Cause error
}

LockError reports an I/O failure while acquiring a foreign-session lock.

func (*LockError) Error

func (e *LockError) Error() string

func (*LockError) Unwrap

func (e *LockError) Unwrap() error

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

func (l *Loop) CommandSink() chan<- command.Command

func (*Loop) DoneChan

func (l *Loop) DoneChan() <-chan struct{}

func (*Loop) Snapshot

Snapshot requests a consistent defensive view from the backend actor.

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.

const (
	SIDPrebound SIDMode = iota
	SIDLateBound
)

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"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL