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
- func AgentArgv(id, model, document, goos string) ([]string, error)
- func Clone(ctx context.Context, env []string, url, dir string) error
- func CloneDir(parent, url string) string
- func CopyParts(src, dest string) error
- func Discard(l *paths.Layout, id string) error
- func FileSHA256(p string) (int64, string, error)
- func ForgetStarted(dir string) error
- func InDir(l *paths.Layout, id string) string
- func Instruction(document, goos string) string
- func IsEmptyOrAbsent(dir string) bool
- func MatchRemote(ctx context.Context, env []string, repo, url string) string
- func MemoRequest(lang string) string
- func MkdirPrivate(dir string) error
- func NameOf(branch string) string
- func NormalizeRemote(u string) string
- func OutDir(l *paths.Layout, id string) string
- func Pack(dir, out string, progress func(done, total int64)) (int64, string, error)
- func RelayBranch(id, source string, taken func(string) bool) string
- func Staged(stage string, err error) error
- func Sweep(l *paths.Layout, now time.Time)
- func TooLarge(total, bundle int64, u *Untracked) error
- func Undo(l *paths.Layout, id string) error
- func ValidModel(model string) bool
- func WriteManifest(dir string, m *Manifest) error
- func WriteStarted(dir string, s Started) error
- type Checkout
- func (c *Checkout) Bundle(ctx context.Context, env []string, dest string) (bool, error)
- func (c *Checkout) Diff(ctx context.Context, env []string, staged, unstaged string) (int64, error)
- func (c *Checkout) TreeState(ctx context.Context, env []string, bundleCommits int, staged, unstaged int64, ...) *TreeState
- func (c *Checkout) Untracked(ctx context.Context, env []string, dest string, progress func(done int64)) (*Untracked, error)
- type DocInput
- type DocResult
- type Manifest
- type MemoDoc
- type SkippedEntry
- type StageError
- type Started
- type TreeState
- type Untracked
- type UntrackedFile
Constants ¶
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.
const Keep = 7 * 24 * time.Hour
Keep is how long a relay's package and working tree parts stay without relay.discard.
const ManifestVersion = 1
ManifestVersion is the only manifest.json version there is.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
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 ¶
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 ¶
CopyParts copies the document's files (manifest, document, images, memo) from the source directory src to dest: a relay within one host.
func Discard ¶
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 ¶
FileSHA256 is the size and SHA-256 (hex) of the file at p.
func ForgetStarted ¶
ForgetStarted removes what relay.start recorded in dir.
func InDir ¶
InDir is relay id's directory on its target: the received package, the unpacked tree parts and the document.
func Instruction ¶
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 ¶
IsEmptyOrAbsent tells whether dir does not exist or is an empty directory.
func MatchRemote ¶
MatchRemote is the name of the remote of the checkout repo whose fetch URL is url (NormalizeRemote), "" when none is.
func MemoRequest ¶
MemoRequest is the hand-off memo request typed into the source agent.
func MkdirPrivate ¶
MkdirPrivate makes dir (and its parents) owner-only.
func NameOf ¶
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 ¶
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 ¶
OutDir is relay id's directory on its source: the package, or within one host its parts as files.
func Pack ¶
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 ¶
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 Sweep ¶
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 ¶
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 ¶
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 ¶
ValidModel tells whether model may be relay.start's model.
func WriteManifest ¶
WriteManifest writes m to dir's manifest.json.
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 ¶
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 ¶
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 ¶
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.
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 ¶
ReadManifest reads dir's manifest.json, refusing another version.
func Unpack ¶
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 SkippedEntry ¶
type SkippedEntry struct{ Path, Why string }
SkippedEntry is an untracked entry not carried: Why is "socket", "fifo", "nested git checkout", "device", …
type StageError ¶
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 ¶
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.