code

package
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 13 Imported by: ? 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 code is Lagrange's convention for code changes: an agent that commits publishes each commit as an artifact of its task, so every Lagrange client can list a run's commits and show their diffs, not only the machine with the repository.

The artifact is named "commit" (ID "commit-<sha>") and has a data part {"commit": {...}} (see Commit) and, optionally, the patch as a text part with the media type text/x-diff. The relay records the commit (without the patch) in the activity log as data.commit of the artifact entry; the patch stays in the task's artifact, for GET /api/tasks/{id}.

Index

Constants

View Source
const (
	// ArtifactName is the name of a commit artifact.
	ArtifactName = "commit"
	// Key is the data part key of a commit.
	Key = "commit"
	// PatchMediaType is the media type of the patch part.
	PatchMediaType = "text/x-diff"
	// MaxPatch caps the patch in an artifact, in bytes. A longer patch is cut, and
	// Commit.PatchCut says so.
	MaxPatch = 256 << 10
)

Variables

This section is empty.

Functions

func Artifact

func Artifact(c Commit, patch string) *a2a.Artifact

Artifact returns the commit's artifact, with patch if it isn't empty.

func Event

Event returns the artifact event that publishes a commit in a task.

func Publish

func Publish(exec a2asrv.AgentExecutor, workspace func(*a2asrv.ExecutorContext) Workspace, logger *slog.Logger) a2asrv.AgentExecutor

Publish wraps an agent executor so that the commits it makes in a context's workspace are published as commit artifacts of the task that made them, just before the task ends or asks something. Each commit is published once. workspace says where a task's context works; an empty Dir skips the task.

Types

type Commit

type Commit struct {
	SHA     string    `json:"sha"`
	Parents []string  `json:"parents,omitempty"`
	Branch  string    `json:"branch,omitempty"`
	Subject string    `json:"subject"`
	Body    string    `json:"body,omitempty"`
	Author  string    `json:"author,omitempty"`
	At      time.Time `json:"at"`
	// Files changed, with their line counts (zero for binary files).
	Files      []File `json:"files,omitempty"`
	Insertions int    `json:"insertions"`
	Deletions  int    `json:"deletions"`
	// PatchCut is set when the artifact's patch was cut to MaxPatch.
	PatchCut bool `json:"patchCut,omitempty"`
}

Commit describes a commit.

func Find

func Find(parts []*a2a.Part) (Commit, string, bool)

Find returns the commit and the patch in parts, if they hold one.

func FromGit

func FromGit(ctx context.Context, dir, rev string) (Commit, string, error)

FromGit reads a commit (any revision git understands) and its patch from the repository in dir.

func (Commit) Map

func (c Commit) Map() map[string]any

Map returns c as the JSON object of the commit data part.

func (Commit) Short

func (c Commit) Short() string

Short returns the commit's SHA cut to 7 characters.

func (Commit) Summary

func (c Commit) Summary() string

Summary says the commit in a line: "3f2a1c9 add the store (+44 −9)".

type File

type File struct {
	Path       string `json:"path"`
	Insertions int    `json:"insertions"`
	Deletions  int    `json:"deletions"`
}

File is a file a commit changed.

type Workspace

type Workspace struct {
	Dir    string
	Branch string
	// Start is a repository whose HEAD is where Dir starts, for a Dir that doesn't
	// exist before the context's first task (a worktree the agent creates).
	Start string
}

Workspace is where an agent works on a task: a git checkout and its branch.

Jump to

Keyboard shortcuts

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