{"modulePath":"github.com/three-agent-problem/lagrange","version":"v0.1.0-beta.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package code\n\nPackage 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.\n\nThe artifact is named \"commit\" (ID \"commit-\\\u003csha\u003e\") and has a data part {\"commit\": {...}} (see [Commit](#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}.\n\n## Constants\n\n```go\nconst (\n\t// ArtifactName is the name of a commit artifact.\n\tArtifactName = \"commit\"\n\t// Key is the data part key of a commit.\n\tKey = \"commit\"\n\t// PatchMediaType is the media type of the patch part.\n\tPatchMediaType = \"text/x-diff\"\n\t// MaxPatch caps the patch in an artifact, in bytes. A longer patch is cut, and\n\t// Commit.PatchCut says so.\n\tMaxPatch = 256 \u003c\u003c 10\n)\n```\n\n## Functions\n\n```go\nfunc Artifact(c Commit, patch string) *a2a.Artifact\n```\nArtifact returns the commit's artifact, with patch if it isn't empty.\n\n```go\nfunc Event(info a2a.TaskInfoProvider, c Commit, patch string) *a2a.TaskArtifactUpdateEvent\n```\nEvent returns the artifact event that publishes a commit in a task.\n\n```go\nfunc Publish(exec a2asrv.AgentExecutor, workspace func(*a2asrv.ExecutorContext) Workspace, logger *slog.Logger) a2asrv.AgentExecutor\n```\nPublish 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.\n\n## Types\n\n```go\ntype Commit struct {\n\tSHA     string    `json:\"sha\"`\n\tParents []string  `json:\"parents,omitempty\"`\n\tBranch  string    `json:\"branch,omitempty\"`\n\tSubject string    `json:\"subject\"`\n\tBody    string    `json:\"body,omitempty\"`\n\tAuthor  string    `json:\"author,omitempty\"`\n\tAt      time.Time `json:\"at\"`\n\t// Files changed, with their line counts (zero for binary files).\n\tFiles      []File `json:\"files,omitempty\"`\n\tInsertions int    `json:\"insertions\"`\n\tDeletions  int    `json:\"deletions\"`\n\t// PatchCut is set when the artifact's patch was cut to MaxPatch.\n\tPatchCut bool `json:\"patchCut,omitempty\"`\n}\n```\nCommit describes a commit.\n\n```go\nfunc Find(parts []*a2a.Part) (Commit, string, bool)\n```\nFind returns the commit and the patch in parts, if they hold one.\n\n```go\nfunc FromGit(ctx context.Context, dir, rev string) (Commit, string, error)\n```\nFromGit reads a commit (any revision git understands) and its patch from the repository in dir.\n\n```go\nfunc (c Commit) Map() map[string]any\n```\nMap returns c as the JSON object of the commit data part.\n\n```go\nfunc (c Commit) Short() string\n```\nShort returns the commit's SHA cut to 7 characters.\n\n```go\nfunc (c Commit) Summary() string\n```\nSummary says the commit in a line: \"3f2a1c9 add the store (+44 −9)\".\n\n```go\ntype File struct {\n\tPath       string `json:\"path\"`\n\tInsertions int    `json:\"insertions\"`\n\tDeletions  int    `json:\"deletions\"`\n}\n```\nFile is a file a commit changed.\n\n```go\ntype Workspace struct {\n\tDir    string\n\tBranch string\n\t// Start is a repository whose HEAD is where Dir starts, for a Dir that doesn't\n\t// exist before the context's first task (a worktree the agent creates).\n\tStart string\n}\n```\nWorkspace is where an agent works on a task: a git checkout and its branch.\n\n","path":"github.com/three-agent-problem/lagrange/code","name":"code","synopsis":"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.","isRedistributable":true}
