relay

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 29 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 relay builds and takes a relay's package (リレー, PROTOCOL.md "Relay", ssh-term ADR 0004 and 0005): on the relay source the conversation's document and the working tree's parts (a git bundle of what no remote has, the uncommitted changes, the untracked files), packed into one gzip tar for another host; on the relay target the package checked and unpacked, and the agent's argv. The bridge runs the methods; `stagent task run --relay` applies the parts (task.RelayPrep).

Index

Constants

View Source
const (
	ManifestFile = "manifest.json"
	DocumentFile = "relay.md"
	MemoFile     = "memo.md"
	ImagesDir    = "images"
	TreeDir      = "tree"
	PackageFile  = "package.tar.gz"
)

Members of a package and files of a relay's directories.

View Source
const Keep = 7 * 24 * time.Hour

Keep is how long a relay's package and working tree parts stay without relay.discard.

View Source
const ManifestVersion = 1

ManifestVersion is the only manifest.json version there is.

Variables

This section is empty.

Functions

func AgentArgv

func AgentArgv(id, model, document, goos string) ([]string, error)

AgentArgv is the relay target's agent: [command, model args…, prompt args…].

func Clone

func Clone(ctx context.Context, env []string, url, dir string) error

Clone runs `git clone url dir` with no credential prompt nobody would see, within its limit, removing what it made when it fails.

func CloneDir

func CloneDir(parent, url string) string

CloneDir is where relay.start's clone of url goes without a dir: in parent, the URL's last path segment without ".git", with -2, -3, … added while that exists.

func CopyParts

func CopyParts(src, dest string) error

CopyParts copies the document's files (manifest, document, images, memo) from the source directory src to dest: a relay within one host.

func Discard

func Discard(l *paths.Layout, id string) error

Discard removes what relay id left on this host but a started relay's document: its source directory, and on the target the package and the tree parts — the whole directory of a relay never started. Idempotent.

func FileSHA256

func FileSHA256(p string) (int64, string, error)

FileSHA256 is the size and SHA-256 (hex) of the file at p.

func ForgetStarted

func ForgetStarted(dir string) error

ForgetStarted removes what relay.start recorded in dir.

func InDir

func InDir(l *paths.Layout, id string) string

InDir is relay id's directory on its target: the received package, the unpacked tree parts and the document.

func Instruction

func Instruction(document, goos string) string

Instruction is the agent's fixed first prompt: the user's own is in the document. On Windows a path holding % (cmd.exe would expand it) is named by the environment variable instead.

func IsEmptyOrAbsent

func IsEmptyOrAbsent(dir string) bool

IsEmptyOrAbsent tells whether dir does not exist or is an empty directory.

func MatchRemote

func MatchRemote(ctx context.Context, env []string, repo, url string) string

MatchRemote is the name of the remote of the checkout repo whose fetch URL is url (NormalizeRemote), "" when none is.

func MemoRequest

func MemoRequest(lang string) string

MemoRequest is the hand-off memo request typed into the source agent.

func MkdirPrivate

func MkdirPrivate(dir string) error

MkdirPrivate makes dir (and its parents) owner-only.

func NameOf

func NameOf(branch string) string

NameOf is a task name made from a branch: each / made -, cut to 64 characters, the characters a name may not have made -, no leading . or -.

func NormalizeRemote

func NormalizeRemote(u string) string

NormalizeRemote is a remote URL as relay.start compares them: scheme, user and a trailing ".git" or "/" dropped, the host lower-cased, an scp-like host:path read as host/path — so git@github.com:o/r.git, ssh://git@github.com/o/r and https://github.com/o/r are the same.

func OutDir

func OutDir(l *paths.Layout, id string) string

OutDir is relay id's directory on its source: the package, or within one host its parts as files.

func Pack

func Pack(dir, out string, progress func(done, total int64)) (int64, string, error)

Pack writes the parts in dir — the manifest, the document, its images, the memo and the tree parts — as a gzip tar to out (mode 0600) and answers its size and SHA-256 (hex). progress is told the bytes written of total.

func RelayBranch

func RelayBranch(id, source string, taken func(string) bool) string

RelayBranch is the new task's branch when relay.start names none: the source's branch when the checkout has no local branch of that name, else <branch>-relay, <branch>-relay-2, …; on a detached HEAD relay-<first 8 of the relay id>. taken tells whether a local branch exists.

func Staged

func Staged(stage string, err error) error

Staged wraps err (nil: nil) as failing stage.

func Sweep

func Sweep(l *paths.Layout, now time.Time)

Sweep removes what has passed its time (Keep): a source's directory 7 days after relay.prepare, a received package 7 days after its last relay.write (with its directory, when the relay never started), the tree parts 7 days after relay.start. Documents stay.

func TooLarge

func TooLarge(total, bundle int64, u *Untracked) error

TooLarge is a package over wire.RelayPackageMax: the bundle's bytes and the largest untracked files, for the user to commit, ignore or remove.

func Undo

func Undo(l *paths.Layout, id string) error

Undo removes what relay.start left in relay id's target directory but the received package: the document, the tree parts and the record of the start (relay.abort).

func ValidModel

func ValidModel(model string) bool

ValidModel tells whether model may be relay.start's model.

func WriteManifest

func WriteManifest(dir string, m *Manifest) error

WriteManifest writes m to dir's manifest.json.

func WriteStarted

func WriteStarted(dir string, s Started) error

WriteStarted records s in dir.

Types

type Checkout

type Checkout struct {
	// Root is the worktree cwd is in, canonical.
	Root      string
	Repo      string
	CwdRel    string
	Remote    string
	RemoteURL string
	Branch    string
	Head      string
	Base      string
	// Unpushed is how many commits of HEAD no remote-tracking ref has.
	Unpushed int
}

Checkout is the git state of a relay source's cwd (wire.RelaySource's git members).

func Inspect

func Inspect(ctx context.Context, env []string, cwd string) (*Checkout, error)

Inspect reads the git state of cwd; nil when cwd is in no git checkout (a bare repository included). git not found is an error.

func (*Checkout) Bundle

func (c *Checkout) Bundle(ctx context.Context, env []string, dest string) (bool, error)

Bundle writes the commits of HEAD no remote has to dest (`git bundle create dest <branch or HEAD> --not --remotes`); false when there are none.

func (*Checkout) Diff

func (c *Checkout) Diff(ctx context.Context, env []string, staged, unstaged string) (int64, error)

Diff writes the staged and the unstaged changes to the patches staged and unstaged, each left out when empty, and answers their bytes.

func (*Checkout) TreeState

func (c *Checkout) TreeState(ctx context.Context, env []string, bundleCommits int, staged, unstaged int64, u *Untracked) *TreeState

TreeState is what the document tells of the working tree.

func (*Checkout) Untracked

func (c *Checkout) Untracked(ctx context.Context, env []string, dest string, progress func(done int64)) (*Untracked, error)

Untracked copies every untracked file of the worktree (`git ls-files --others --exclude-standard`) to dest at the same path: regular files owner-only with their executable bit, symbolic links as links. Sockets, FIFOs, devices and nested git checkouts are skipped. progress is told the bytes copied.

type DocInput

type DocInput struct {
	Lang          string           // wire.LangJa → 日本語, anything else → English
	Instruction   string           // "" = the default first instruction of Lang
	Source        wire.RelaySource // the source as the manifest records it
	InPlace       bool             // the target works in the source's own place (nothing brought)
	SourceMayWork bool             // InPlace with source_agent keep: the source agent may still be at work there
	Entries       []transcript.Entry
	Question      *wire.Question  // Session.question when read (nil: none)
	Approvals     []wire.Approval // approvals pending when read
	Tree          *TreeState      // nil: cwd is in no git checkout
	Memo          *MemoDoc        // nil: no memo asked for
	Location      *time.Location  // for the times; nil = time.Local
}

DocInput is what the relay document is written from.

type DocResult

type DocResult struct {
	Bytes      int64 // relay.md's size
	Messages   int   // messages under the full conversation
	Images     int   // image files written
	ImageBytes int64
}

DocResult tells what WriteDocument wrote.

func WriteDocument

func WriteDocument(dir string, in DocInput) (DocResult, error)

WriteDocument writes dir/relay.md and dir/images/<nnnn>.<ext> (dirs 0700, files 0600 on unix whatever the umask). dir exists.

type Manifest

type Manifest struct {
	Version int              `json:"version"`
	RelayID string           `json:"relay_id"`
	Source  wire.RelaySource `json:"source"`
	Parts   wire.RelayParts  `json:"parts"`
	Memo    wire.RelayMemo   `json:"memo"`
}

Manifest is a package's manifest.json.

func ReadManifest

func ReadManifest(dir string) (*Manifest, error)

ReadManifest reads dir's manifest.json, refusing another version.

func Unpack

func Unpack(pkg, dest string, progress func(done, total int64)) (*Manifest, error)

Unpack checks the package pkg and unpacks it into dest: every member a regular file of the table of PROTOCOL.md "Relay" (a symbolic link only under tree/untracked/), with a relative path free of ".."; manifest.json of version 1. Regular files are written owner-only (0700 with an executable bit). progress is told the package's bytes read.

type MemoDoc

type MemoDoc struct {
	Text     string // the memo ("" with TimedOut)
	TimedOut bool
}

MemoDoc is the hand-off memo: Text, or TimedOut when it did not come in time.

type SkippedEntry

type SkippedEntry struct{ Path, Why string }

SkippedEntry is an untracked entry not carried: Why is "socket", "fifo", "nested git checkout", "device", …

type StageError

type StageError struct {
	Stage string
	Err   error
}

StageError prefixes err with the relay stage it failed at.

func (*StageError) Error

func (e *StageError) Error() string

func (*StageError) Unwrap

func (e *StageError) Unwrap() error

type Started

type Started struct {
	TaskID    string `json:"task_id,omitempty"`
	SessionID string `json:"session_id"`
	// Branch is the branch the relay made (deleted by relay.abort), Repo
	// its checkout.
	Branch string `json:"branch,omitempty"`
	Repo   string `json:"repo,omitempty"`
	At     int64  `json:"at"` // unix ms
}

Started is what relay.start made on its target, for busy, relay.abort and the 7 days of the tree parts.

func ReadStarted

func ReadStarted(dir string) *Started

ReadStarted is what relay.start recorded in dir, nil when nothing.

type TreeState

type TreeState struct {
	BundleCommits      int      // commits carried in the bundle (0: none)
	Commits            []string // `git log --oneline base..head`, at most 50
	CommitsMore        int      // how many more there were
	Status             []string // `git status --porcelain=v1` lines, at most 200
	StatusMore         int
	StagedPatchBytes   int64 // 0: no staged patch
	UnstagedPatchBytes int64
	Untracked          []string // carried untracked paths ("/" separated, relative to the worktree root)
	Skipped            []SkippedEntry
	Submodules         []string // `git submodule status` lines (not carried)
	LFS                bool     // the repo uses Git LFS (objects not carried)
}

TreeState is what the document tells of the working tree.

type Untracked

type Untracked struct {
	Files   []UntrackedFile
	Bytes   int64
	Skipped []SkippedEntry
}

Untracked is what Untracked carried and skipped.

type UntrackedFile

type UntrackedFile struct {
	Path string // "/" separated, relative to the worktree's root
	Size int64
}

UntrackedFile is a carried untracked file.

Jump to

Keyboard shortcuts

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