client

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 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.

README

gitd-client for Go

A client for gitd: instant, secretless git checkouts for agent sandboxes. Your agents work in their own copy and publish a branch; they never see your token. It is the client gitd's own command line and MCP server use.

go get github.com/dooservice/gitd/client@latest
gitd, err := client.Open(client.Options{}) // $GITD_SOCKET, then your own gitd's, then the system's
if err != nil {
	return err
}
path := "/var/lib/gitd/workspaces/agent-1"
workspace, err := gitd.Prepare(ctx, &gitdv1.PrepareRequest{Url: "https://github.com/acme/web", Path: path}, nil)
if err != nil {
	return err
}
fmt.Println(workspace.GetCommit(), workspace.GetStrategy())

// … the agent works in path with plain git, and commits …

published, err := gitd.Publish(ctx, &gitdv1.PublishRequest{Path: path, Branch: "agents/fix-login"})

No call takes a credential: gitd reads and publishes with the ones it keeps. Requests and answers are the contract's own messages, from github.com/dooservice/gitd/gen/go/gitd/v1.

Method What it does
Prepare, Update, Checkout, SyncSubmodules, Adopt A workspace made, moved to a branch's tip or a commit, its submodules brought in, or one made elsewhere taken in; each takes a Progress for what git is doing, or nil
Describe, Changes, Diff, Compare, Conflicts, Watch What a workspace is and what its agent changed, read without running anything of the agent's
Publish Its commits pushed to a new branch, or with Update an earlier publish's branch moved forward; its pull request opened or updated
Seal, ListWarm Warm layers: a workspace's installed dependencies kept for the next ones
Remove Deleted; its pool stays
Probe, Info, Retire, Audit A repository checked, which gitd answers and how, unused pools retired, every publish on record
IssueToken, RevokeToken, ListTokens Tokens of gitd's own for a sandbox cloning from its endpoint
ListConnections, AddToken, AddGitHubApp, BeginGitHubApp, … The credentials gitd keeps, never a secret
GetSettings, SetSettings, ListPresets, … Publishing rules

A gitd on another machine is called at its address, with the key naming the caller's tenant, and the authority of its certificate when the system does not trust it:

gitd, err := client.Open(client.Options{URL: "https://gitd.internal:9420", Key: key, CAFile: "/etc/gitd/ca.pem"})

A refusal is an error whose reason client.Reason(err) reads (REASON_AUTH_REQUIRED, REASON_NOT_FOUND, REASON_PATH_REFUSED, …), with what git said. Decide from the reason, never from the message.

Go 1.27 or later, on Linux, macOS and Windows; the same version as gitd. Apache-2.0.

Documentation

Overview

Package client calls a gitd, on its Unix socket or on the network: for programs written in Go, and for gitd's own command line and MCP server.

It speaks the Connect protocol over HTTP/1.1, which the server answers besides gRPC, so a stream of progress needs nothing more than the standard library.

Example

An agent's round trip: a workspace, the agent's work in it with plain git, its commits published as a branch, and the workspace removed. No call takes a credential.

package main

import (
	"context"
	"fmt"

	"github.com/dooservice/gitd/client"
	gitdv1 "github.com/dooservice/gitd/gen/go/gitd/v1"
)

func main() {
	ctx := context.Background()
	gitd, err := client.Open(client.Options{})
	if err != nil {
		panic(err)
	}
	path := "/var/lib/gitd/workspaces/agent-1"
	workspace, err := gitd.Prepare(ctx, &gitdv1.PrepareRequest{Url: "https://github.com/acme/web", Path: path}, nil)
	if reason, said := client.Reason(err); reason != "" {
		fmt.Println("refused:", reason, said)
		return
	}
	fmt.Println(path, workspace.GetCommit(), workspace.GetStrategy())

	published, err := gitd.Publish(ctx, &gitdv1.PublishRequest{Path: path, Branch: "agents/fix-login"})
	if err != nil {
		panic(err)
	}
	fmt.Println(published.GetBranch())
	_ = gitd.Remove(ctx, path)
}

Index

Examples

Constants

View Source
const SocketVariable = "GITD_SOCKET"

SocketVariable names the environment variable that says where gitd's socket is.

Variables

This section is empty.

Functions

func Reason

func Reason(err error) (reason, said string)

Reason is why gitd refused a call, as the contract names it, and what git said, read from the error's typed detail; empty when the error is not one of gitd's refusals.

Types

type Client

Client is a gitd on one socket.

func New

func New(socket string) *Client

New returns the gitd that answers on socket, with no key. Nothing is dialled until the first call.

func Open

func Open(options Options) (*Client, error)

Open returns the gitd options name. Nothing is dialled until the first call.

Example (Network)

A gitd on another machine, with the key naming the caller's tenant.

package main

import (
	"context"

	"github.com/dooservice/gitd/client"
)

func main() {
	gitd, err := client.Open(client.Options{URL: "https://gitd.internal:9420", Key: "acme-key"})
	if err != nil {
		panic(err)
	}
	_, _ = gitd.Info(context.Background())
}

func (*Client) AddGitHubApp

func (client *Client) AddGitHubApp(ctx context.Context, request *gitdv1.AddGitHubAppRequest) (*gitdv1.AddGitHubAppResponse, error)

AddGitHubApp keeps a GitHub App by its ID and private key.

func (*Client) AddToken

func (client *Client) AddToken(ctx context.Context, request *gitdv1.AddTokenRequest) (*gitdv1.AddTokenResponse, error)

AddToken keeps a token for the repositories under a prefix.

func (*Client) Adopt

func (client *Client) Adopt(
	ctx context.Context, request *gitdv1.AdoptRequest, progress Progress,
) (*gitdv1.AdoptResult, error)

Adopt takes an existing clone in.

func (*Client) Audit

func (client *Client) Audit(ctx context.Context, request *gitdv1.AuditRequest) (*gitdv1.AuditResponse, error)

Audit reads the audit log: every publish, done or refused, newest first.

func (*Client) BeginGitHubApp

func (client *Client) BeginGitHubApp(ctx context.Context, request *gitdv1.BeginGitHubAppRequest) (*gitdv1.BeginGitHubAppResponse, error)

BeginGitHubApp starts creating a GitHub App from a manifest.

func (*Client) Changes

func (client *Client) Changes(ctx context.Context, request *gitdv1.ChangesRequest) (*gitdv1.ChangesResponse, error)

Changes says what was changed in a workspace since gitd last put it on a commit.

func (*Client) Checkout

func (client *Client) Checkout(
	ctx context.Context, request *gitdv1.CheckoutRequest, progress Progress,
) (*gitdv1.WorkspaceResult, error)

Checkout moves a workspace to a commit.

func (*Client) Compare

func (client *Client) Compare(ctx context.Context, request *gitdv1.CompareRequest) (*gitdv1.CompareResponse, error)

Compare says how two works differ.

func (*Client) CompleteGitHubApp

func (client *Client) CompleteGitHubApp(ctx context.Context, request *gitdv1.CompleteGitHubAppRequest) (*gitdv1.CompleteGitHubAppResponse, error)

CompleteGitHubApp finishes creating a GitHub App with the code GitHub sent back.

func (*Client) Conflicts

func (client *Client) Conflicts(ctx context.Context, request *gitdv1.ConflictsRequest) (*gitdv1.ConflictsResponse, error)

Conflicts says which pairs of works do not merge cleanly.

func (*Client) Describe

func (client *Client) Describe(ctx context.Context, path string) (*gitdv1.DescribeResponse, error)

Describe says what a workspace is on disk.

func (*Client) Diff

func (client *Client) Diff(ctx context.Context, request *gitdv1.DiffRequest) (*gitdv1.DiffResponse, error)

Diff writes the unified diff of a workspace's changes.

func (*Client) FinishGitHubLogin

func (client *Client) FinishGitHubLogin(ctx context.Context, loginID string) (*gitdv1.FinishGitHubLoginResponse, error)

FinishGitHubLogin waits until the person entered the code, and keeps the sign-in.

func (*Client) GetSettings

func (client *Client) GetSettings(ctx context.Context) (*gitdv1.GetSettingsResponse, error)

GetSettings is every publishing setting.

func (*Client) Info

func (client *Client) Info(ctx context.Context) (*gitdv1.InfoResponse, error)

Info says which gitd answers.

func (*Client) IssueToken

func (client *Client) IssueToken(ctx context.Context, request *gitdv1.IssueTokenRequest) (*gitdv1.IssueTokenResponse, error)

IssueToken issues a token of gitd's endpoint for a sandbox.

func (*Client) List added in v0.15.0

func (client *Client) List(ctx context.Context) (*gitdv1.ListResponse, error)

List is every workspace gitd made, with what Describe says of each and the branches published from it.

func (*Client) ListConnections

func (client *Client) ListConnections(ctx context.Context) (*gitdv1.ListConnectionsResponse, error)

ListConnections is the credentials gitd keeps, never a secret.

func (*Client) ListPresets

func (client *Client) ListPresets(ctx context.Context) (*gitdv1.ListPresetsResponse, error)

ListPresets is every preset as it applies.

func (*Client) ListTokens

func (client *Client) ListTokens(ctx context.Context) (*gitdv1.ListTokensResponse, error)

ListTokens lists the endpoint's tokens alive.

func (*Client) ListWarm

func (client *Client) ListWarm(ctx context.Context, request *gitdv1.ListWarmRequest) (*gitdv1.ListWarmResponse, error)

ListWarm lists the warm layers of a repository.

func (*Client) Prepare

func (client *Client) Prepare(
	ctx context.Context, request *gitdv1.PrepareRequest, progress Progress,
) (*gitdv1.WorkspaceResult, error)

Prepare makes a workspace, or moves the one gitd already made there.

func (*Client) Probe

func (client *Client) Probe(ctx context.Context, request *gitdv1.ProbeRequest) (*gitdv1.ProbeResponse, error)

Probe asks a repository whether it can be read, and for its branches.

func (*Client) Publish

func (client *Client) Publish(ctx context.Context, request *gitdv1.PublishRequest) (*gitdv1.PublishResponse, error)

Publish pushes what was committed in a workspace to a new branch.

func (*Client) Remove

func (client *Client) Remove(ctx context.Context, path string) error

Remove deletes a workspace.

func (*Client) RemoveConnection

func (client *Client) RemoveConnection(ctx context.Context, id string) error

RemoveConnection forgets a connection made through the API.

func (*Client) RemovePreset

func (client *Client) RemovePreset(ctx context.Context, name string) error

RemovePreset forgets a preset set through the API.

func (*Client) RemoveSettings

func (client *Client) RemoveSettings(ctx context.Context, prefix string) error

RemoveSettings forgets the publishing settings of a prefix.

func (*Client) Retire

func (client *Client) Retire(ctx context.Context, unusedForSeconds int64) (*gitdv1.RetireResponse, error)

Retire removes now the pools nobody used for a while.

func (*Client) RevokeToken

func (client *Client) RevokeToken(ctx context.Context, request *gitdv1.RevokeTokenRequest) (*gitdv1.RevokeTokenResponse, error)

RevokeToken ends a token of gitd's endpoint.

func (*Client) Seal

func (client *Client) Seal(ctx context.Context, request *gitdv1.SealRequest) (*gitdv1.SealResponse, error)

Seal makes an overlay workspace's own layer a warm layer of its repository.

func (*Client) SetPreset

func (client *Client) SetPreset(ctx context.Context, preset *gitdv1.Preset) (*gitdv1.SetPresetResponse, error)

SetPreset keeps a preset.

func (*Client) SetSettings

func (client *Client) SetSettings(ctx context.Context, settings *gitdv1.PublishSettings) (*gitdv1.SetSettingsResponse, error)

SetSettings keeps the publishing settings of a prefix.

func (*Client) StartGitHubLogin

func (client *Client) StartGitHubLogin(ctx context.Context, host string) (*gitdv1.StartGitHubLoginResponse, error)

StartGitHubLogin asks for the code a person enters to sign in to GitHub.

func (*Client) SyncSubmodules

func (client *Client) SyncSubmodules(
	ctx context.Context, request *gitdv1.SyncSubmodulesRequest, progress Progress,
) (*gitdv1.SyncSubmodulesResult, error)

SyncSubmodules checks out a workspace's submodules.

func (*Client) Update

func (client *Client) Update(
	ctx context.Context, request *gitdv1.UpdateRequest, progress Progress,
) (*gitdv1.WorkspaceResult, error)

Update brings a workspace to the tip of a branch.

func (*Client) Watch

func (client *Client) Watch(ctx context.Context, paths []string, told func(*gitdv1.WatchResponse)) error

Watch hands each event of the workspaces at paths, or of every one, to told, until ctx ends or gitd ends the watch.

type Options

type Options struct {
	Socket string
	URL    string
	Key    string
	CAFile string
}

Options say which gitd to call and how: on its Unix socket, or at URL on the network (https, or http on a private network), with Key naming the caller's tenant, and CAFile the certificate authority of a gitd whose certificate the system does not trust. With neither Socket nor URL, the socket is $GITD_SOCKET, then that of the gitd `gitd up` runs for the user when it is there, then the system's default.

type Progress

type Progress func(*gitdv1.Progress)

Progress is told what git is doing while a long operation runs.

Jump to

Keyboard shortcuts

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