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
- func Artifact(c Commit, patch string) *a2a.Artifact
- func Event(info a2a.TaskInfoProvider, c Commit, patch string) *a2a.TaskArtifactUpdateEvent
- func Publish(exec a2asrv.AgentExecutor, workspace func(*a2asrv.ExecutorContext) Workspace, ...) a2asrv.AgentExecutor
- type Commit
- type File
- type Workspace
Constants ¶
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 Event ¶
func Event(info a2a.TaskInfoProvider, c Commit, patch string) *a2a.TaskArtifactUpdateEvent
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 FromGit ¶
FromGit reads a commit (any revision git understands) and its patch from the repository in dir.
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.