fork

package
v0.0.232 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fork launches a DSH session as a child of another session in a different checkout. The child inherits the source transcript up to a chosen cut, so an Agent can keep its context while working in a new worktree without disturbing the conversation that is still running.

The package owns the fork policy — checkout separation, resume of a partially delivered child, verification that the Host honoured the checkout, draft seeding and the optional browser launch. It never writes the session store: every fact about a session comes from the caller-supplied reader.

Index

Constants

View Source
const DefaultTimeout = 2 * time.Minute

DefaultTimeout bounds one attempt: a long transcript can take a while to seed, and the Host composes the child Agent before it answers.

Variables

View Source
var (
	// ErrSourceMissing means the fork source is not a known session.
	ErrSourceMissing = errors.New("source session not found")
	// ErrSameCheckout means the child would share the source checkout and could
	// interfere with the Agent that is still running there.
	ErrSameCheckout = errors.New("fork needs a checkout different from the source session")
	// ErrChildElsewhere means a resumed child belongs to a different checkout.
	ErrChildElsewhere = errors.New("session does not belong to the selected checkout")
	// ErrCwdNotHonored means the Host forked into the source checkout, which only
	// a Host without fork-checkout support does.
	ErrCwdNotHonored = errors.New("fork stayed in the source checkout; update the harness that serves dsh web")
)

Refusals a caller should surface verbatim; errors.Is matches all of them.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Client talks to the Host. Required; a nil HTTPClient gets one bounded by
	// Timeout, because the default is too short for seeding a long transcript.
	Client web.Client
	// ReadSession reports a session's current checkout. Required; pass the
	// caller's live-aware reader so a running Agent is seen.
	ReadSession func(id string) (SessionInfo, error)
	// SourceID is the session whose transcript the child inherits. Required.
	SourceID string
	// Cwd is the child checkout, which must differ from the source's. Required.
	Cwd string
	// AtSeq is the inclusive transcript cut; 0 keeps the latest completed turn.
	AtSeq int64
	// Resume is a child ID from an earlier partial attempt; when it still
	// belongs to Cwd the fork is skipped and only the remaining steps run.
	Resume string
	// Draft is stored in the child composer for review and never submitted.
	Draft string
	// Browser selects the window opened when Open is set; web.BrowserNone skips it.
	Browser string
	// Open launches the child's browser window after the draft is seeded.
	Open bool
	// Timeout bounds the attempt; 0 uses DefaultTimeout.
	Timeout time.Duration
}

Options is one fork attempt.

type Result

type Result struct {
	SessionID string
	Forked    bool
	Drafted   bool
	Opened    bool
}

Result reports what the attempt did. SessionID is set as soon as a child exists, even when a later step fails, so a caller can checkpoint it and retry with Resume.

func Run

func Run(ctx context.Context, opts Options) (Result, error)

Run forks SourceID into Cwd and seeds the draft. A refused fork returns no session ID; a failure after the fork keeps it so the caller can retry.

type SessionInfo

type SessionInfo struct {
	ID  string
	Cwd string
}

SessionInfo is the durable or live fact a fork needs about one session. Cwd is the session's working directory as recorded by the Host; an empty Cwd means the reader cannot tell and skips the checkout checks.

Jump to

Keyboard shortcuts

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