{"modulePath":"github.com/bborbe/agent-task-controller","version":"v0.31.0","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package gitrestclient\n\n## Variables\n\n```go\nvar ErrAlreadyExists = stderrors.New(\"file already exists\")\n```\nErrAlreadyExists is returned by PostIfAbsent when the target path is already occupied (git-rest responds 409 Conflict for a create-only write). It is a benign conflict, not a transport failure — callers use errors.Is to treat it as \"already there\" instead of an error worth retrying.\n\n## Types\n\n```go\ntype GitClient interface {\n\t// EnsureCloned clones the repo if not present, validates if already cloned.\n\tEnsureCloned(ctx context.Context) error\n\t// Pull runs git pull on the local clone.\n\tPull(ctx context.Context) error\n\t// CommitAndPush stages all changes, creates a commit with the given message, and pushes to the remote.\n\tCommitAndPush(ctx context.Context, message string) error\n\t// AtomicWriteAndCommitPush writes content to absPath and commits+pushes under a single lock.\n\t// Atomicity (no interleaving with other writes) is guaranteed by the implementation:\n\t// - gitClient (local-disk): sync.Mutex around the whole sequence.\n\t// - gitRestGitClientAdapter: relies on per-task serialization (Kafka partitioning by task_id).\n\tAtomicWriteAndCommitPush(\n\t\tctx context.Context,\n\t\tabsPath string,\n\t\tcontent []byte,\n\t\tmessage string,\n\t) error\n\t// AtomicWriteIfAbsentAndCommitPush writes content to absPath only when no file\n\t// exists there yet, then commits+pushes. Returns ErrAlreadyExists (via\n\t// errors.Is) when the path is occupied; nothing is written in that case.\n\tAtomicWriteIfAbsentAndCommitPush(\n\t\tctx context.Context,\n\t\tabsPath string,\n\t\tcontent []byte,\n\t\tmessage string,\n\t) error\n\t// AtomicReadModifyWriteAndCommitPush reads absPath, calls modify on its contents\n\t// to produce new contents, writes the result, and commits+pushes.\n\t// Atomicity (no interleaving with other writes) is guaranteed by the implementation:\n\t// - gitClient (local-disk): sync.Mutex around the whole sequence.\n\t// - gitRestGitClientAdapter: relies on per-task serialization (Kafka partitioning by task_id).\n\t// modify must return the new file bytes or an error.\n\t// If modify returns an error, the file is not written and no commit is made.\n\tAtomicReadModifyWriteAndCommitPush(\n\t\tctx context.Context,\n\t\tabsPath string,\n\t\tmodify func(current []byte) ([]byte, error),\n\t\tmessage string,\n\t) error\n\t// Path returns the local clone path.\n\tPath() string\n\t// ListFiles returns relative file paths under the repo root matching the single-level\n\t// glob pattern (e.g. \"tasks/*.md\"). Paths are relative to the repo root.\n\tListFiles(ctx context.Context, glob string) ([]string, error)\n\t// ReadFile reads the file at relPath (relative to repo root, e.g. \"tasks/foo.md\")\n\t// and returns its content.\n\tReadFile(ctx context.Context, relPath string) ([]byte, error)\n\t// WriteFile writes content to relPath (relative to repo root) on local disk.\n\t// It does NOT commit or push — use AtomicWriteAndCommitPush for that.\n\tWriteFile(ctx context.Context, relPath string, content []byte) error\n}\n```\nGitClient is the interface for vault file operations used throughout the controller.\n\n```go\nfunc NewGitClient(gitRestClient GitRestClient, basePath string) GitClient\n```\nNewGitClient creates a GitClient backed by git-rest HTTP calls. basePath is the logical root path used when computing relative paths (e.g. \"/data/vault\") — it does NOT need to exist on disk. gitRestClient is the HTTP client created by NewGitRestClient.\n\n```go\ntype GitRestClient interface {\n\t// Get retrieves the current content of the file at relPath.\n\tGet(ctx context.Context, relPath string) ([]byte, error)\n\t// Post writes content to relPath; git-rest auto-commits and pushes.\n\tPost(ctx context.Context, relPath string, content []byte) error\n\t// PostIfAbsent writes content to relPath only when no file exists there yet;\n\t// git-rest auto-commits and pushes. Returns ErrAlreadyExists (via errors.Is)\n\t// when relPath is already occupied — nothing is written in that case.\n\tPostIfAbsent(ctx context.Context, relPath string, content []byte) error\n\t// Delete removes the file at relPath; git-rest auto-commits and pushes.\n\tDelete(ctx context.Context, relPath string) error\n\t// List returns relative paths matching the single-level glob pattern (e.g. \"tasks/*.md\").\n\tList(ctx context.Context, glob string) ([]string, error)\n\t// IsReady reports whether git-rest's /readiness returns 200.\n\t// Returns (false, nil) when git-rest returns 503 — that is a valid not-ready state, not an error.\n\t// Returns (false, err) only on network failure or unexpected response.\n\tIsReady(ctx context.Context) (bool, error)\n}\n```\nGitRestClient is the HTTP client for git-rest's /api/v1/files REST API. All paths are relative to the repo root (e.g. \"tasks/foo.md\").\n\n```go\nfunc NewGitRestClient(\n\tbaseURL, gatewaySecret, gatewayInitiator string,\n\tmetrics metrics.Metrics,\n) GitRestClient\n```\nNewGitRestClient creates a GitRestClient targeting the git-rest instance at baseURL. gatewaySecret is the shared secret enforced by git-rest's gateway-secret auth (git-rest spec 004). When gatewaySecret is empty, no auth headers are sent (backward-compat with auth-disabled git-rest). gatewayInitiator is the caller identity logged by git-rest on auth failure; pass a stable, human-readable value (e.g. \"agent-task-controller\").\n\n","path":"github.com/bborbe/agent-task-controller/pkg/gitrestclient","name":"gitrestclient","synopsis":"","isRedistributable":true}
