durableagent

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package durableagent holds the pi setup of a coding agent over the pi-durable Harness: the coding registry, the Harness settings, the execution environments, the HTTP setup and the initial model.

Index

Constants

This section is empty.

Variables

View Source
var CodingProfile = Profile{
	Kind: "durable",
	Registry: func(settings *codingagent.SettingsManager, cwd string) (harness.Registry, error) {
		registry, err := CreateCodingRegistry(settings, cwd)
		if err != nil {
			return nil, err
		}
		return registry, registry.Install(Subagent)
	},
	Environments: true,
	RootAgent:    func(cwd string) harness.AgentChange { return harness.AgentChange{Cwd: harness.SetTo(cwd)} },
}

CodingProfile is the coding agent: pi's coding registry with the subagent tool, execution environments, and a root conversation in the session's directory.

View Source
var Subagent = createSubagent()

Subagent is a foreground subagent: each call creates a child conversation owned by the call's task, runs the task there, and returns the child's answer. Aborting the call aborts the child. The child outlives the call, so the user can switch to it and keep talking.

Functions

func AgentOf

AgentOf is the agent document of a view; absent while the conversation has none.

func ConfigureHarnessHTTP

func ConfigureHarnessHTTP(settings *codingagent.SettingsManager) error

ConfigureHarnessHTTP is pi's HTTP setup: proxy and idle timeouts. Without it, some provider streams break off.

func CreateCodingRegistry

func CreateCodingRegistry(settings *codingagent.SettingsManager, cwd string) (harness.Registry, error)

CreateCodingRegistry is a registry with pi's coding tools and system prompt.

func CreateHarnessSettings

func CreateHarnessSettings(settings *codingagent.SettingsManager) func() *harness.HarnessSettings

CreateHarnessSettings returns the Harness settings, read at every use from pi's settings as loaded at startup. A setting that does not parse fails the read as its getter throws upstream: the read panics, and the Harness fails the operation that made it.

func CreatePiPrompt

func CreatePiPrompt(settings *codingagent.SettingsManager, fallbackCwd string) *durable.Extension

CreatePiPrompt is pi's system prompt as one extension: the sections of BuildSystemPromptSections for the request's tools and the conversation's directory. Context files and skills load once per directory, like pi at startup.

Upstream builds the sections once per request and renders each key from that build. The Go section callback receives the input by value and has no identity to key the build on, so each key builds from the cached resources; the build is pure in them and the input, so the rendered text is the same.

Types

type Completion

type Completion <-chan struct{}

Completion is closed when a command has run. A command reports its failure as a notice, so it has no error.

type ConversationSummary

type ConversationSummary struct {
	ID    durable.ConversationId
	Label string
	// Title is the first user message, for a subagent its task. The main conversation needs no title; nil when absent.
	Title *string
}

ConversationSummary is a conversation the user can switch to: the main one, or a subagent's.

type DefaultModelSettings

type DefaultModelSettings interface {
	GetDefaultProvider() string
	GetDefaultModel() string
	GetDefaultThinkingLevel() string
}

DefaultModelSettings is the saved default model selection of pi's settings.

type DurableController

type DurableController interface {
	// Submit prompts when idle; otherwise it steers or queues a follow-up.
	Submit(text string, whenBusy durable.WhenBusy) Completion
	Compact(instructions *string) Completion
	// Abort is not queued: it waits until the conversation is idle.
	Abort() Completion
	CycleThinking() Completion
	SetModel(model durable.ModelRef) Completion
	ToggleTasks() Completion
	// SwitchConversation shows and talks to another conversation.
	SwitchConversation(id durable.ConversationId) Completion
}

DurableController is what the TUI may ask for. Commands run one at a time in the order they were asked, so toggles, switches and key presses apply in order; each returns without waiting.

type DurableView

type DurableView struct {
	Session SessionSummary
	// Conversation is the conversation shown and talked to.
	Conversation  harness.ConversationView
	Conversations []ConversationSummary
	Models        []ModelSummary
	Notices       []Notice
	// Tasks is the live task graph while the task panel is open; nil otherwise.
	Tasks *harness.TaskGraph
}

DurableView is everything the TUI renders. Plain values; no Harness objects cross this boundary. A view is replaced, never changed in place.

type DurableViewSource

type DurableViewSource interface {
	Current() DurableView
	// Subscribe registers listener and returns the function that removes it.
	Subscribe(listener func()) func()
}

DurableViewSource publishes the view. Listeners run off the Session line, once per burst of changes.

type ExecutionEnvs

type ExecutionEnvs struct {
	// contains filtered or unexported fields
}

ExecutionEnvs holds one execution environment per directory, shared by every conversation in it.

func NewExecutionEnvs

func NewExecutionEnvs(defaultCwd string) *ExecutionEnvs

NewExecutionEnvs returns environments whose default directory is defaultCwd.

func (*ExecutionEnvs) Cleanup

func (envs *ExecutionEnvs) Cleanup(ctx context.Context) error

Cleanup forgets every environment, then cleans each in creation order. The first failure stops the cleaning, as the awaited loop of upstream does.

func (*ExecutionEnvs) Env

Env is HarnessOptions.Env: the environment of the target's directory, the default directory when the target has none.

type InitialModel

type InitialModel struct {
	Model           *durable.ModelRef
	ThinkingLevel   string
	FallbackMessage string
}

InitialModel is the model and thinking level a new root conversation starts with.

func FindInitialAgentModel

func FindInitialAgentModel(selection ModelSelection, settings DefaultModelSettings, provider, model string) (InitialModel, error)

FindInitialAgentModel is the model a new root conversation starts with: an explicit --provider/--model, or pi's default resolution (harness-setup.ts:93-124).

type ModelSelection

type ModelSelection struct {
	Runtime        *coding.ModelRuntime
	ConfiguredAuth func(string) bool
}

ModelSelection projects only resolver metadata while retaining every native model field through the non-wire attachment. Availability comes from the runtime's own snapshot.

func (ModelSelection) GetAvailableSnapshot

func (view ModelSelection) GetAvailableSnapshot() []codingagent.RuntimeModel

func (ModelSelection) GetModel

func (view ModelSelection) GetModel(provider, id string) *codingagent.RuntimeModel

func (ModelSelection) GetModels

func (view ModelSelection) GetModels(provider string) []codingagent.RuntimeModel

func (ModelSelection) HasConfiguredAuth

func (view ModelSelection) HasConfiguredAuth(provider string) bool

type ModelSummary

type ModelSummary struct {
	durable.ModelRef
	Name          string
	ContextWindow int
}

ModelSummary is a model the user can select.

type Notice

type Notice struct {
	ID      int
	Level   NoticeLevel
	Message string
}

Notice is a message shown below the transcript.

type NoticeLevel

type NoticeLevel string

NoticeLevel is "info", "warning", or "error".

const (
	NoticeInfo    NoticeLevel = "info"
	NoticeWarning NoticeLevel = "warning"
	NoticeError   NoticeLevel = "error"
)

type OpenDurableOptions

type OpenDurableOptions struct {
	// CWD is the working directory; empty is the process's.
	CWD             string
	ContinueSession bool
}

OpenDurableOptions select the session to open.

func ParseArgs

func ParseArgs(argv []string) (OpenDurableOptions, error)

ParseArgs reads the command line of the durable and vacation programs: --continue (-c) opens the newest session of the directory; anything else is an error.

type OpenDurableResult

type OpenDurableResult struct {
	View       DurableViewSource
	Controller DurableController
	// Settings are pi's settings, for the TUI's theme and terminal capabilities.
	Settings *codingagent.SettingsManager
	// Close closes the Harness, which writes no outcome, and releases the session lock. Repeated calls return the first result.
	Close func() error
}

OpenDurableResult is an open session.

func Open

func Open(ctx context.Context, options OpenDurableOptions, profile Profile) (result *OpenDurableResult, err error)

Open opens a session of the profile's kind: the Harness over the session's SQLite storage with the profile's registry and pi's settings, the model runtime, and the view and controller over them. Work that an interrupted turn left behind resumes now.

type Profile

type Profile struct {
	// Kind is the session kind: "durable" or "vacation".
	Kind string
	// Registry builds the registry the Harness opens with.
	Registry func(settings *codingagent.SettingsManager, cwd string) (harness.Registry, error)
	// Environments gives every conversation a Node execution environment of its directory.
	Environments bool
	// RootAgent is the agent the root conversation starts with, before the initial model.
	RootAgent func(cwd string) harness.AgentChange
}

Profile is what separates an agent from the coding agent: the sessions it keeps, its registry, whether its conversations have execution environments, and the agent of its root conversation.

type SessionLocation

type SessionLocation struct {
	ID        string
	Directory string
	Database  string
	CWD       string
	Created   bool
	// Release releases the directory lock.
	Release func() error
}

SessionLocation is one session directory holding session.sqlite, locked by this process.

func SelectSession

func SelectSession(ctx context.Context, kind, cwdInput string, continueSession bool) (*SessionLocation, error)

SelectSession returns a new session for cwdInput, or its newest one with continueSession. kind is "durable" or "vacation": the sessions live in <kind>-sessions under the agent directory's experimental directory.

type SessionSummary

type SessionSummary struct {
	ID        string
	Directory string
	CWD       string
}

SessionSummary identifies the open session.

Directories

Path Synopsis
Command main runs the durable coding agent: pi's coding tools on the pi-durable Harness, with its own TUI.
Command main runs the durable coding agent: pi's coding tools on the pi-durable Harness, with its own TUI.

Jump to

Keyboard shortcuts

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