← Back to Pull requests

feat(tools): add read-only "git" toolset for structured repository inspection #3637

Merged
dwin-gharibi merged 7 files (732 lines) on Jul 17, 2026 08:24 UTC
View on GitHub
dwin-gharibi dwin-gharibi commented on Jul 14, 2026 07:19 UTC
Author

Closes #3636

---

Summary

Adds a new built-in toolset, git, giving an agent structured, read-only access to the working repository: status, log, branches, commit details, and blame. Implemented with go-git (already a direct dependency), so it needs no git binary and is fully unit-testable.

Tools: git_status, git_log, git_branches, git_show, git_blame.

Motivation

Coding agents constantly need git context. Today the only option is the shell tool with raw git, which forces the model to parse free-form porcelain, exposes the full writable shell surface, and depends on a git binary. A dedicated read-only toolset returns clean structured output, is safe by construction, and works without shell or the binary.

What changed

| File | Change |
| --- | --- |
| pkg/tools/builtin/git/git.go | New. The toolset: 5 read-only tools over go-git. |
| pkg/tools/builtin/git/git_test.go | New. Tests build throwaway repos with go-git and exercise every tool. |
| pkg/teamloader/toolsets/toolsets.go | Register the git creator. |
| pkg/teamloader/toolsets/catalog.go | Add the git catalog entry (required by the drift-guard test). |
| docs/configuration/tools/index.md | Add git to the built-in toolsets table. |
| docs/tools/git/index.md | New. Dedicated docs page. |

Design

  • Read-only by design. No add/commit/checkout — write ops are stateful, overlap shell, and raise permission questions; deferred to keep v1 safe.

  • go-git, not the CLI — pure Go, no binary dependency, deterministically testable. The repo opens at the agent's WorkingDir with DetectDotGit.

  • The catalog drift-guard test forces the catalog entry: registering the type without documenting it fails the build.
  • Example output

    $ git_status
    On branch master
    1 changed file(s) [XY = staged/worktree; M=modified A=added D=deleted R=renamed ?=untracked]:
       M main.go
    
    $ git_log
    b3951c61  2026-01-02  Alice  feat: print hi
    aac3216e  2026-01-02  Alice  feat: initial commit
    
    $ git_show
    commit b3951c61b84a0c298552096542bbd3bd7f58840b
    Author: Alice <alice@example.com>
    Date:   2026-01-02 03:04:05 +0000
    
    feat: print hi
    
    Changed files:
      main.go (+1, -1)
    
    $ git_blame main.go
    aac3216e alice@example.com          1| package main
    b3951c61 alice@example.com          3| func main() { println("hi") }
    

    Testing

    go test ./pkg/tools/builtin/git/ ./pkg/teamloader/toolsets/
    

  • git_status (changed + clean), git_log (order + limit), git_branches (current marked), git_show (metadata + stats), git_blame (authorship), plus not-a-repo and missing-path error paths, and the tool-count/interface check.

  • TestBuiltinToolsetsCatalogMatchesRegistry passes with git in both registry and catalog.
  • All pass; gofmt -l and go vet clean. (CI runs task lint / task test.)

    Scope / non-goals

  • Read-only v1 — no write operations.

  • No working-tree line diff (go-git's worktree diff is limited); git_show covers commit-level diffs. Both are noted as possible future work.
  • Diff: 732 lines (+730 / -2) across 7 files Reviewer: Sayt-0 Review duration: 4385m
    All Vouch review confidence checks passed
    Residual risk 0.13 = Change Risk (0.51) × (1 − Review Confidence (0.74)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.51 · 732 lines diff across 7 files
    0.51
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.48 · 5 substantive comment(s)
    0.48
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    73%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.395
    Real PR Conversation Timeline
    21 items
    dwin-gharibi dwin-gharibi commented on Jul 14, 2026 07:20 UTC
    Author

    Let's just continue. @aheritier @Sayt-0

    Sayt-0 Sayt-0 commented on code on Jul 16, 2026 11:11 UTC
    Code Review
    pkg/tools/builtin/git/git_test.go:1
    @@ -0,0 +1,153 @@
    +package git
    +
    +import (
    +	"context"
    +	"os"
    +	"path/filepath"
    +	"testing"
    +	"time"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/stretchr/testify/require"
    +)
    +
    +var fixedTime = time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
    +
    +func sig() *object.Signature {
    +	return &object.Signature{Name: "Alice", Email: "alice@example.com", When: fixedTime}
    +}
    +
    +func newRepo(t *testing.T) (string, *gogit.Repository) {
    +	t.Helper()
    +	dir := t.TempDir()
    +	repo, err := gogit.PlainInit(dir, false)
    +	require.NoError(t, err)
    +	return dir, repo
    +}
    +
    +func addCommit(t *testing.T, repo *gogit.Repository, dir string, files map[string]string, msg string) plumbing.Hash {
    +	t.Helper()
    +	wt, err := repo.Worktree()
    +	require.NoError(t, err)
    +	for name, content := range files {
    +		require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644))
    +		_, err := wt.Add(name)
    +		require.NoError(t, err)
    +	}
    +	h, err := wt.Commit(msg, &gogit.CommitOptions{Author: sig()})
    +	require.NoError(t, err)
    +	return h
    +}
    +
    +func TestGitStatus(t *testing.T) {
    +	t.Parallel()
    +	dir, repo := newRepo(t)
    +	addCommit(t, repo, dir, map[string]string{"a.txt": "hello\nworld\n"}, "initial")
    +
    +	require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte("changed\n"), 0o644))
    +	require.NoError(t, os.WriteFile(filepath.Join(dir, "b.txt"), []byte("new\n"), 0o644))
    +
    +	res, err := New(dir).status(context.Background(), StatusArgs{})

    forbidigo bans context.Background() in tests repo-wide; t.Context() is required (see .golangci.yml). Applies to all 10 occurrences in this file (lines 52, 64, 76, 82, 97, 109, 122, 134, 141, 149). The linter only reports 3 of them because of max-same-issues: 3, so a local golangci-lint run after the fix is worth double-checking.

    Sayt-0 Sayt-0 commented on code on Jul 16, 2026 11:11 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400
    +)
    +
    +func CreateToolSet(runConfig *config.RuntimeConfig) (tools.ToolSet, error) {
    +	wd := runConfig.WorkingDir
    +	if wd == "" {
    +		var err error
    +		wd, err = os.Getwd()
    +		if err != nil {
    +			return nil, fmt.Errorf("determining working directory: %w", err)
    +		}
    +	}
    +	return New(wd), nil
    +}
    +
    +type ToolSet struct {
    +	dir string
    +}
    +
    +var (
    +	_ tools.ToolSet      = (*ToolSet)(nil)
    +	_ tools.Instructable = (*ToolSet)(nil)
    +)
    +
    +func New(dir string) *ToolSet { return &ToolSet{dir: dir} }
    +
    +func (t *ToolSet) open() (*gogit.Repository, error) {
    +	repo, err := gogit.PlainOpenWithOptions(t.dir, &gogit.PlainOpenOptions{DetectDotGit: true})
    +	if err != nil {
    +		return nil, fmt.Errorf("opening git repository at %s: %w", t.dir, err)
    +	}
    +	return repo, nil
    +}
    +
    +type StatusArgs struct{}
    +
    +type LogArgs struct {
    +	Limit int    `json:"limit,omitempty" jsonschema:"Maximum number of commits to return (default 20)"`
    +	Path  string `json:"path,omitempty" jsonschema:"Only show commits that touch this path"`
    +}
    +
    +type BranchesArgs struct{}
    +
    +type ShowArgs struct {
    +	Ref string `json:"ref,omitempty" jsonschema:"Commit hash or revision to show (default HEAD)"`
    +}
    +
    +type BlameArgs struct {
    +	Path string `json:"path" jsonschema:"File path to blame, relative to the repository root"`
    +	Rev  string `json:"rev,omitempty" jsonschema:"Commit or revision to blame at (default HEAD)"`
    +}
    +
    +func (t *ToolSet) status(_ context.Context, _ StatusArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	wt, err := repo.Worktree()
    +	if err != nil {
    +		return tools.ResultError("Error: reading worktree: " + err.Error()), nil
    +	}
    +	st, err := wt.Status()
    +	if err != nil {
    +		return tools.ResultError("Error: reading status: " + err.Error()), nil
    +	}
    +
    +	branch := "(detached HEAD)"
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		branch = head.Name().Short()
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "On branch %s\n", branch)
    +
    +	paths := make([]string, 0, len(st))
    +	for p, fs := range st {
    +		if fs.Staging == gogit.Unmodified && fs.Worktree == gogit.Unmodified {
    +			continue
    +		}
    +		paths = append(paths, p)
    +	}
    +	if len(paths) == 0 {
    +		b.WriteString("Working tree clean.")
    +		return tools.ResultSuccess(b.String()), nil
    +	}
    +	sort.Strings(paths)
    +	fmt.Fprintf(&b, "%d changed file(s) [XY = staged/worktree; M=modified A=added D=deleted R=renamed ?=untracked]:\n", len(paths))
    +	for _, p := range paths {
    +		fs := st[p]
    +		fmt.Fprintf(&b, "  %c%c %s\n", fs.Staging, fs.Worktree, p)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) log(_ context.Context, args LogArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	opts := &gogit.LogOptions{Order: gogit.LogOrderCommitterTime}
    +	if args.Path != "" {
    +		p := args.Path
    +		opts.FileName = &p
    +	}
    +	iter, err := repo.Log(opts)
    +	if err != nil {
    +		return tools.ResultError("Error: reading log: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	limit := args.Limit
    +	if limit <= 0 {
    +		limit = defaultLogLimit
    +	}
    +
    +	var b strings.Builder
    +	count := 0
    +	err = iter.ForEach(func(c *object.Commit) error {
    +		if count >= limit {
    +			return storer.ErrStop
    +		}
    +		fmt.Fprintf(&b, "%s  %s  %s  %s\n",
    +			c.Hash.String()[:8], c.Author.When.Format("2006-01-02"), c.Author.Name, firstLine(c.Message))
    +		count++
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating log: " + err.Error()), nil
    +	}
    +	if count == 0 {
    +		return tools.ResultSuccess("No commits found."), nil
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) branches(_ context.Context, _ BranchesArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	current := ""
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		current = head.Name().Short()
    +	}
    +
    +	iter, err := repo.Branches()
    +	if err != nil {
    +		return tools.ResultError("Error: reading branches: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	var names []string
    +	err = iter.ForEach(func(ref *plumbing.Reference) error {
    +		names = append(names, ref.Name().Short())
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating branches: " + err.Error()), nil
    +	}
    +	if len(names) == 0 {
    +		return tools.ResultSuccess("No branches."), nil
    +	}
    +	sort.Strings(names)
    +
    +	var b strings.Builder
    +	for _, n := range names {
    +		marker := "  "
    +		if n == current {
    +			marker = "* "
    +		}
    +		fmt.Fprintf(&b, "%s%s\n", marker, n)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) show(_ context.Context, args ShowArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Ref)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "commit %s\n", commit.Hash.String())
    +	fmt.Fprintf(&b, "Author: %s <%s>\n", commit.Author.Name, commit.Author.Email)
    +	fmt.Fprintf(&b, "Date:   %s\n\n", commit.Author.When.Format("2006-01-02 15:04:05 -0700"))
    +	fmt.Fprintf(&b, "%s\n", strings.TrimRight(commit.Message, "\n"))
    +
    +	if stats, err := commit.Stats(); err == nil && len(stats) > 0 {
    +		b.WriteString("\nChanged files:\n")
    +		for _, s := range stats {
    +			fmt.Fprintf(&b, "  %s (+%d, -%d)\n", s.Name, s.Addition, s.Deletion)
    +		}
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) blame(_ context.Context, args BlameArgs) (*tools.ToolCallResult, error) {
    +	if strings.TrimSpace(args.Path) == "" {
    +		return tools.ResultError("Error: path is required."), nil
    +	}
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Rev)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +	result, err := gogit.Blame(commit, args.Path)
    +	if err != nil {
    +		return tools.ResultError("Error: blaming " + args.Path + ": " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	for i, line := range result.Lines {
    +		if i >= maxBlameLines {
    +			fmt.Fprintf(&b, "... (%d more lines truncated)\n", len(result.Lines)-maxBlameLines)
    +			break
    +		}
    +		short := line.Hash.String()
    +		if len(short) > 8 {
    +			short = short[:8]
    +		}
    +		fmt.Fprintf(&b, "%s %-20s %4d| %s\n", short, line.Author, i+1, line.Text)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func resolveRev(repo *gogit.Repository, rev string) (plumbing.Hash, error) {
    +	if strings.TrimSpace(rev) == "" {
    +		rev = "HEAD"
    +	}
    +	h, err := repo.ResolveRevision(plumbing.Revision(rev))
    +	if err != nil {
    +		return plumbing.ZeroHash, fmt.Errorf("resolving revision %q: %w", rev, err)
    +	}
    +	return *h, nil
    +}
    +
    +func firstLine(msg string) string {
    +	msg = strings.TrimSpace(msg)
    +	if i := strings.IndexByte(msg, '\n'); i >= 0 {

    modernize flags this: strings.IndexByte + slice can be simplified with strings.Cut:

    func firstLine(msg string) string {
    	first, _, _ := strings.Cut(strings.TrimSpace(msg), "\n")
    	return first
    }
    

    Sayt-0 Sayt-0 commented on code on Jul 16, 2026 11:11 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400
    +)
    +
    +func CreateToolSet(runConfig *config.RuntimeConfig) (tools.ToolSet, error) {
    +	wd := runConfig.WorkingDir
    +	if wd == "" {
    +		var err error
    +		wd, err = os.Getwd()
    +		if err != nil {
    +			return nil, fmt.Errorf("determining working directory: %w", err)
    +		}
    +	}
    +	return New(wd), nil
    +}
    +
    +type ToolSet struct {
    +	dir string
    +}
    +
    +var (
    +	_ tools.ToolSet      = (*ToolSet)(nil)
    +	_ tools.Instructable = (*ToolSet)(nil)
    +)
    +
    +func New(dir string) *ToolSet { return &ToolSet{dir: dir} }
    +
    +func (t *ToolSet) open() (*gogit.Repository, error) {
    +	repo, err := gogit.PlainOpenWithOptions(t.dir, &gogit.PlainOpenOptions{DetectDotGit: true})
    +	if err != nil {
    +		return nil, fmt.Errorf("opening git repository at %s: %w", t.dir, err)
    +	}
    +	return repo, nil
    +}
    +
    +type StatusArgs struct{}
    +
    +type LogArgs struct {
    +	Limit int    `json:"limit,omitempty" jsonschema:"Maximum number of commits to return (default 20)"`
    +	Path  string `json:"path,omitempty" jsonschema:"Only show commits that touch this path"`
    +}
    +
    +type BranchesArgs struct{}
    +
    +type ShowArgs struct {
    +	Ref string `json:"ref,omitempty" jsonschema:"Commit hash or revision to show (default HEAD)"`
    +}
    +
    +type BlameArgs struct {
    +	Path string `json:"path" jsonschema:"File path to blame, relative to the repository root"`
    +	Rev  string `json:"rev,omitempty" jsonschema:"Commit or revision to blame at (default HEAD)"`
    +}
    +
    +func (t *ToolSet) status(_ context.Context, _ StatusArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	wt, err := repo.Worktree()
    +	if err != nil {
    +		return tools.ResultError("Error: reading worktree: " + err.Error()), nil
    +	}
    +	st, err := wt.Status()
    +	if err != nil {
    +		return tools.ResultError("Error: reading status: " + err.Error()), nil
    +	}
    +
    +	branch := "(detached HEAD)"
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		branch = head.Name().Short()
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "On branch %s\n", branch)
    +
    +	paths := make([]string, 0, len(st))
    +	for p, fs := range st {
    +		if fs.Staging == gogit.Unmodified && fs.Worktree == gogit.Unmodified {
    +			continue
    +		}
    +		paths = append(paths, p)
    +	}
    +	if len(paths) == 0 {
    +		b.WriteString("Working tree clean.")
    +		return tools.ResultSuccess(b.String()), nil
    +	}
    +	sort.Strings(paths)
    +	fmt.Fprintf(&b, "%d changed file(s) [XY = staged/worktree; M=modified A=added D=deleted R=renamed ?=untracked]:\n", len(paths))
    +	for _, p := range paths {
    +		fs := st[p]
    +		fmt.Fprintf(&b, "  %c%c %s\n", fs.Staging, fs.Worktree, p)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) log(_ context.Context, args LogArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	opts := &gogit.LogOptions{Order: gogit.LogOrderCommitterTime}
    +	if args.Path != "" {
    +		p := args.Path
    +		opts.FileName = &p
    +	}
    +	iter, err := repo.Log(opts)
    +	if err != nil {
    +		return tools.ResultError("Error: reading log: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	limit := args.Limit
    +	if limit <= 0 {
    +		limit = defaultLogLimit
    +	}
    +
    +	var b strings.Builder
    +	count := 0
    +	err = iter.ForEach(func(c *object.Commit) error {
    +		if count >= limit {
    +			return storer.ErrStop
    +		}
    +		fmt.Fprintf(&b, "%s  %s  %s  %s\n",
    +			c.Hash.String()[:8], c.Author.When.Format("2006-01-02"), c.Author.Name, firstLine(c.Message))
    +		count++
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating log: " + err.Error()), nil
    +	}
    +	if count == 0 {
    +		return tools.ResultSuccess("No commits found."), nil
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) branches(_ context.Context, _ BranchesArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	current := ""
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		current = head.Name().Short()
    +	}
    +
    +	iter, err := repo.Branches()
    +	if err != nil {
    +		return tools.ResultError("Error: reading branches: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	var names []string
    +	err = iter.ForEach(func(ref *plumbing.Reference) error {
    +		names = append(names, ref.Name().Short())
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating branches: " + err.Error()), nil
    +	}
    +	if len(names) == 0 {
    +		return tools.ResultSuccess("No branches."), nil
    +	}
    +	sort.Strings(names)
    +
    +	var b strings.Builder
    +	for _, n := range names {
    +		marker := "  "
    +		if n == current {
    +			marker = "* "
    +		}
    +		fmt.Fprintf(&b, "%s%s\n", marker, n)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) show(_ context.Context, args ShowArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Ref)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "commit %s\n", commit.Hash.String())
    +	fmt.Fprintf(&b, "Author: %s <%s>\n", commit.Author.Name, commit.Author.Email)
    +	fmt.Fprintf(&b, "Date:   %s\n\n", commit.Author.When.Format("2006-01-02 15:04:05 -0700"))
    +	fmt.Fprintf(&b, "%s\n", strings.TrimRight(commit.Message, "\n"))
    +
    +	if stats, err := commit.Stats(); err == nil && len(stats) > 0 {
    +		b.WriteString("\nChanged files:\n")
    +		for _, s := range stats {
    +			fmt.Fprintf(&b, "  %s (+%d, -%d)\n", s.Name, s.Addition, s.Deletion)
    +		}
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) blame(_ context.Context, args BlameArgs) (*tools.ToolCallResult, error) {
    +	if strings.TrimSpace(args.Path) == "" {
    +		return tools.ResultError("Error: path is required."), nil
    +	}
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Rev)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +	result, err := gogit.Blame(commit, args.Path)
    +	if err != nil {
    +		return tools.ResultError("Error: blaming " + args.Path + ": " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	for i, line := range result.Lines {
    +		if i >= maxBlameLines {
    +			fmt.Fprintf(&b, "... (%d more lines truncated)\n", len(result.Lines)-maxBlameLines)
    +			break
    +		}
    +		short := line.Hash.String()
    +		if len(short) > 8 {
    +			short = short[:8]
    +		}
    +		fmt.Fprintf(&b, "%s %-20s %4d| %s\n", short, line.Author, i+1, line.Text)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func resolveRev(repo *gogit.Repository, rev string) (plumbing.Hash, error) {
    +	if strings.TrimSpace(rev) == "" {
    +		rev = "HEAD"
    +	}
    +	h, err := repo.ResolveRevision(plumbing.Revision(rev))
    +	if err != nil {
    +		return plumbing.ZeroHash, fmt.Errorf("resolving revision %q: %w", rev, err)
    +	}
    +	return *h, nil
    +}
    +
    +func firstLine(msg string) string {
    +	msg = strings.TrimSpace(msg)
    +	if i := strings.IndexByte(msg, '\n'); i >= 0 {
    +		return msg[:i]
    +	}
    +	return msg
    +}
    +
    +func (t *ToolSet) Tools(context.Context) ([]tools.Tool, error) {
    +	ro := tools.ToolAnnotations{ReadOnlyHint: true}
    +	return []tools.Tool{
    +		{
    +			Name:                    ToolNameGitStatus,
    +			Category:                category,
    +			Description:             "Show the working tree status: current branch and changed files (staged, unstaged, untracked).",
    +			Parameters:              tools.MustSchemaFor[StatusArgs](),
    +			OutputSchema:            tools.MustSchemaFor[string](),
    +			Handler:                 tools.NewHandler(t.status),
    +			Annotations:             tools.ToolAnnotations{ReadOnlyHint: true, Title: "Git Status"},
    +			AddDescriptionParameter: true,
    +		},
    +		{
    +			Name:                    ToolNameGitLog,
    +			Category:                category,
    +			Description:             "Show recent commit history (hash, date, author, subject). Optionally limit the count or filter by path.",
    +			Parameters:              tools.MustSchemaFor[LogArgs](),
    +			OutputSchema:            tools.MustSchemaFor[string](),
    +			Handler:                 tools.NewHandler(t.log),
    +			Annotations:             tools.ToolAnnotations{ReadOnlyHint: true, Title: "Git Log"},
    +			AddDescriptionParameter: true,
    +		},
    +		{
    +			Name:                    ToolNameGitBranches,
    +			Category:                category,
    +			Description:             "List local branches, marking the current one with an asterisk.",
    +			Parameters:              tools.MustSchemaFor[BranchesArgs](),
    +			OutputSchema:            tools.MustSchemaFor[string](),
    +			Handler:                 tools.NewHandler(t.branches),
    +			Annotations:             ro,

    Inconsistency: ro is only used for git_branches, which as a result is the only tool without a Title ("Git Branches"). Either reuse ro for all five tools and set Title separately, or drop the variable and inline tools.ToolAnnotations{ReadOnlyHint: true, Title: "Git Branches"} like the other four.

    Sayt-0 Sayt-0 commented on code on Jul 16, 2026 11:11 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400
    +)
    +
    +func CreateToolSet(runConfig *config.RuntimeConfig) (tools.ToolSet, error) {
    +	wd := runConfig.WorkingDir
    +	if wd == "" {
    +		var err error
    +		wd, err = os.Getwd()
    +		if err != nil {
    +			return nil, fmt.Errorf("determining working directory: %w", err)
    +		}
    +	}
    +	return New(wd), nil
    +}
    +
    +type ToolSet struct {
    +	dir string
    +}
    +
    +var (
    +	_ tools.ToolSet      = (*ToolSet)(nil)
    +	_ tools.Instructable = (*ToolSet)(nil)
    +)
    +
    +func New(dir string) *ToolSet { return &ToolSet{dir: dir} }
    +
    +func (t *ToolSet) open() (*gogit.Repository, error) {
    +	repo, err := gogit.PlainOpenWithOptions(t.dir, &gogit.PlainOpenOptions{DetectDotGit: true})
    +	if err != nil {
    +		return nil, fmt.Errorf("opening git repository at %s: %w", t.dir, err)
    +	}
    +	return repo, nil
    +}
    +
    +type StatusArgs struct{}
    +
    +type LogArgs struct {
    +	Limit int    `json:"limit,omitempty" jsonschema:"Maximum number of commits to return (default 20)"`

    limit has a default but no upper bound: limit: 1000000 on a large repository produces an unbounded string injected into the model context. A hard cap (for example 200, mirroring the maxBlameLines approach) would keep output size predictable.

    Sayt-0 Sayt-0 commented on code on Jul 16, 2026 11:11 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400

    With a hard 400-line cutoff and no range parameter, lines beyond 400 are unreachable ("who touched line 1200?" cannot be answered). Optional start_line / end_line args would fix this and reduce output size for targeted questions. Fine as a follow-up if preferred; worth noting in the docs page either way.

    Sayt-0 Sayt-0 commented on code on Jul 16, 2026 11:11 UTC
    Code Review
    docs/tools/git/index.md:1
    @@ -0,0 +1,86 @@
    +---
    +title: "Git Tool"
    +description: "Read-only inspection of the working git repository."
    +keywords: docker agent, ai agents, tools, toolsets, git tool
    +linkTitle: "Git"
    +weight: 130

    weight: 130 collides with docs/tools/mcp/index.md, making the sidebar order between the two pages non-deterministic. Existing pages use unique weights (scheduler took 135 to slot between 130 and 140). 25 is free and matches the placement next to filesystem / shell in the configuration index table; 125 works too.

    Sayt-0 Sayt-0 commented on code on Jul 16, 2026 11:11 UTC
    Code Review
    pkg/teamloader/toolsets/toolsets.go:1
    @@ -73,6 +74,9 @@ func DefaultToolsetCreators() map[string]teamloader.ToolsetCreator {
     		"fetch": func(_ context.Context, toolset latest.Toolset, _ string, runConfig *config.RuntimeConfig, _ string) (tools.ToolSet, error) {
     			return fetch.CreateToolSet(toolset, runConfig)
     		},
    +		"git": func(_ context.Context, _ latest.Toolset, _ string, runConfig *config.RuntimeConfig, _ string) (tools.ToolSet, error) {

    Registration itself looks right (alphabetical, config ignored since the toolset has no options). Reminder tied to the general review: "git" also needs to be added to the Toolset.type enum in agent-schema.json, which is the one registration point not covered by the drift-guard test.

    Sayt-0 Sayt-0 requested changes on Jul 16, 2026 11:11 UTC
    Changes Requested Reviewer

    Summary

    Useful addition: structured, read-only git context without the writable shell surface or a git binary, and the implementation follows the builtin-toolset patterns closely (creator + catalog + drift-guard, annotations, instructions, docs page, atomic conventional commits). Two blocking items prevent approval as-is; both are quick fixes. Inline comments follow.

    Blocking

    | # | Finding | Where | Impact |
    | --- | --- | --- | --- |
    | 1 | golangci-lint fails on the branch: 10x forbidigo (context.Background() in tests is banned, use t.Context()) and 1x modernize (strings.Cut). Note: the linter output shows only 3 of the 10 forbidigo hits because of max-same-issues: 3. | pkg/tools/builtin/git/git_test.go, pkg/tools/builtin/git/git.go | The ci / lint job will fail. The green checks currently on the PR are docs-only workflows; the Go CI has not run yet. |
    | 2 | agent-schema.json is not updated: the Toolset.type enum does not include "git". | agent-schema.json (Toolset.type enum, near the scheduler / rag entries) | Editors validating configs against the schema flag type: git as invalid, and any future docs example using git fails pkg/config/schema_test.go. The catalog drift-guard was handled, but this second registration point was missed. |

    Non-blocking suggestions

  • git_status on a freshly initialized repository (unborn HEAD) prints On branch (detached HEAD), and git_log returns Error: reading log: reference not found. Friendlier handling ("no commits yet") would help agents on brand-new repos.

  • Docs: a short caveat on go-git performance would set expectations. Worktree().Status() rehashes the whole worktree (slow on large repos) and Blame cost grows with history x file size; maxBlameLines truncates output only after the full computation.

  • Docs: DetectDotGit walks up parent directories. When the working directory is not itself a repository but an ancestor is (for example a dotfiles-tracked home directory), git_show / git_blame expose the ancestor repository's full history and file contents. Worth an explicit note in the docs page, since filesystem confinement (allow/deny lists) does not apply here.

  • Test coverage gaps (fast follows): git_log path filter, git_show with an explicit and an invalid ref, git_blame with rev, the 400-line truncation path, and CreateToolSet.
  • Verdict

    Request changes for items 1 and 2; everything else is optional. With those fixed, the toolset looks good to land as a read-only v1.

    dwin-gharibi dwin-gharibi commented on code on Jul 16, 2026 16:16 UTC
    Code Review
    pkg/tools/builtin/git/git_test.go:1
    @@ -0,0 +1,153 @@
    +package git
    +
    +import (
    +	"context"
    +	"os"
    +	"path/filepath"
    +	"testing"
    +	"time"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/stretchr/testify/require"
    +)
    +
    +var fixedTime = time.Date(2026, 1, 2, 3, 4, 5, 0, time.UTC)
    +
    +func sig() *object.Signature {
    +	return &object.Signature{Name: "Alice", Email: "alice@example.com", When: fixedTime}
    +}
    +
    +func newRepo(t *testing.T) (string, *gogit.Repository) {
    +	t.Helper()
    +	dir := t.TempDir()
    +	repo, err := gogit.PlainInit(dir, false)
    +	require.NoError(t, err)
    +	return dir, repo
    +}
    +
    +func addCommit(t *testing.T, repo *gogit.Repository, dir string, files map[string]string, msg string) plumbing.Hash {
    +	t.Helper()
    +	wt, err := repo.Worktree()
    +	require.NoError(t, err)
    +	for name, content := range files {
    +		require.NoError(t, os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644))
    +		_, err := wt.Add(name)
    +		require.NoError(t, err)
    +	}
    +	h, err := wt.Commit(msg, &gogit.CommitOptions{Author: sig()})
    +	require.NoError(t, err)
    +	return h
    +}
    +
    +func TestGitStatus(t *testing.T) {
    +	t.Parallel()
    +	dir, repo := newRepo(t)
    +	addCommit(t, repo, dir, map[string]string{"a.txt": "hello\nworld\n"}, "initial")
    +
    +	require.NoError(t, os.WriteFile(filepath.Join(dir, "a.txt"), []byte("changed\n"), 0o644))
    +	require.NoError(t, os.WriteFile(filepath.Join(dir, "b.txt"), []byte("new\n"), 0o644))
    +
    +	res, err := New(dir).status(context.Background(), StatusArgs{})

    Done.

    dwin-gharibi dwin-gharibi commented on code on Jul 16, 2026 16:17 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400
    +)
    +
    +func CreateToolSet(runConfig *config.RuntimeConfig) (tools.ToolSet, error) {
    +	wd := runConfig.WorkingDir
    +	if wd == "" {
    +		var err error
    +		wd, err = os.Getwd()
    +		if err != nil {
    +			return nil, fmt.Errorf("determining working directory: %w", err)
    +		}
    +	}
    +	return New(wd), nil
    +}
    +
    +type ToolSet struct {
    +	dir string
    +}
    +
    +var (
    +	_ tools.ToolSet      = (*ToolSet)(nil)
    +	_ tools.Instructable = (*ToolSet)(nil)
    +)
    +
    +func New(dir string) *ToolSet { return &ToolSet{dir: dir} }
    +
    +func (t *ToolSet) open() (*gogit.Repository, error) {
    +	repo, err := gogit.PlainOpenWithOptions(t.dir, &gogit.PlainOpenOptions{DetectDotGit: true})
    +	if err != nil {
    +		return nil, fmt.Errorf("opening git repository at %s: %w", t.dir, err)
    +	}
    +	return repo, nil
    +}
    +
    +type StatusArgs struct{}
    +
    +type LogArgs struct {
    +	Limit int    `json:"limit,omitempty" jsonschema:"Maximum number of commits to return (default 20)"`
    +	Path  string `json:"path,omitempty" jsonschema:"Only show commits that touch this path"`
    +}
    +
    +type BranchesArgs struct{}
    +
    +type ShowArgs struct {
    +	Ref string `json:"ref,omitempty" jsonschema:"Commit hash or revision to show (default HEAD)"`
    +}
    +
    +type BlameArgs struct {
    +	Path string `json:"path" jsonschema:"File path to blame, relative to the repository root"`
    +	Rev  string `json:"rev,omitempty" jsonschema:"Commit or revision to blame at (default HEAD)"`
    +}
    +
    +func (t *ToolSet) status(_ context.Context, _ StatusArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	wt, err := repo.Worktree()
    +	if err != nil {
    +		return tools.ResultError("Error: reading worktree: " + err.Error()), nil
    +	}
    +	st, err := wt.Status()
    +	if err != nil {
    +		return tools.ResultError("Error: reading status: " + err.Error()), nil
    +	}
    +
    +	branch := "(detached HEAD)"
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		branch = head.Name().Short()
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "On branch %s\n", branch)
    +
    +	paths := make([]string, 0, len(st))
    +	for p, fs := range st {
    +		if fs.Staging == gogit.Unmodified && fs.Worktree == gogit.Unmodified {
    +			continue
    +		}
    +		paths = append(paths, p)
    +	}
    +	if len(paths) == 0 {
    +		b.WriteString("Working tree clean.")
    +		return tools.ResultSuccess(b.String()), nil
    +	}
    +	sort.Strings(paths)
    +	fmt.Fprintf(&b, "%d changed file(s) [XY = staged/worktree; M=modified A=added D=deleted R=renamed ?=untracked]:\n", len(paths))
    +	for _, p := range paths {
    +		fs := st[p]
    +		fmt.Fprintf(&b, "  %c%c %s\n", fs.Staging, fs.Worktree, p)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) log(_ context.Context, args LogArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	opts := &gogit.LogOptions{Order: gogit.LogOrderCommitterTime}
    +	if args.Path != "" {
    +		p := args.Path
    +		opts.FileName = &p
    +	}
    +	iter, err := repo.Log(opts)
    +	if err != nil {
    +		return tools.ResultError("Error: reading log: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	limit := args.Limit
    +	if limit <= 0 {
    +		limit = defaultLogLimit
    +	}
    +
    +	var b strings.Builder
    +	count := 0
    +	err = iter.ForEach(func(c *object.Commit) error {
    +		if count >= limit {
    +			return storer.ErrStop
    +		}
    +		fmt.Fprintf(&b, "%s  %s  %s  %s\n",
    +			c.Hash.String()[:8], c.Author.When.Format("2006-01-02"), c.Author.Name, firstLine(c.Message))
    +		count++
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating log: " + err.Error()), nil
    +	}
    +	if count == 0 {
    +		return tools.ResultSuccess("No commits found."), nil
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) branches(_ context.Context, _ BranchesArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	current := ""
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		current = head.Name().Short()
    +	}
    +
    +	iter, err := repo.Branches()
    +	if err != nil {
    +		return tools.ResultError("Error: reading branches: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	var names []string
    +	err = iter.ForEach(func(ref *plumbing.Reference) error {
    +		names = append(names, ref.Name().Short())
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating branches: " + err.Error()), nil
    +	}
    +	if len(names) == 0 {
    +		return tools.ResultSuccess("No branches."), nil
    +	}
    +	sort.Strings(names)
    +
    +	var b strings.Builder
    +	for _, n := range names {
    +		marker := "  "
    +		if n == current {
    +			marker = "* "
    +		}
    +		fmt.Fprintf(&b, "%s%s\n", marker, n)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) show(_ context.Context, args ShowArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Ref)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "commit %s\n", commit.Hash.String())
    +	fmt.Fprintf(&b, "Author: %s <%s>\n", commit.Author.Name, commit.Author.Email)
    +	fmt.Fprintf(&b, "Date:   %s\n\n", commit.Author.When.Format("2006-01-02 15:04:05 -0700"))
    +	fmt.Fprintf(&b, "%s\n", strings.TrimRight(commit.Message, "\n"))
    +
    +	if stats, err := commit.Stats(); err == nil && len(stats) > 0 {
    +		b.WriteString("\nChanged files:\n")
    +		for _, s := range stats {
    +			fmt.Fprintf(&b, "  %s (+%d, -%d)\n", s.Name, s.Addition, s.Deletion)
    +		}
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) blame(_ context.Context, args BlameArgs) (*tools.ToolCallResult, error) {
    +	if strings.TrimSpace(args.Path) == "" {
    +		return tools.ResultError("Error: path is required."), nil
    +	}
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Rev)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +	result, err := gogit.Blame(commit, args.Path)
    +	if err != nil {
    +		return tools.ResultError("Error: blaming " + args.Path + ": " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	for i, line := range result.Lines {
    +		if i >= maxBlameLines {
    +			fmt.Fprintf(&b, "... (%d more lines truncated)\n", len(result.Lines)-maxBlameLines)
    +			break
    +		}
    +		short := line.Hash.String()
    +		if len(short) > 8 {
    +			short = short[:8]
    +		}
    +		fmt.Fprintf(&b, "%s %-20s %4d| %s\n", short, line.Author, i+1, line.Text)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func resolveRev(repo *gogit.Repository, rev string) (plumbing.Hash, error) {
    +	if strings.TrimSpace(rev) == "" {
    +		rev = "HEAD"
    +	}
    +	h, err := repo.ResolveRevision(plumbing.Revision(rev))
    +	if err != nil {
    +		return plumbing.ZeroHash, fmt.Errorf("resolving revision %q: %w", rev, err)
    +	}
    +	return *h, nil
    +}
    +
    +func firstLine(msg string) string {
    +	msg = strings.TrimSpace(msg)
    +	if i := strings.IndexByte(msg, '\n'); i >= 0 {

    Done.

    dwin-gharibi dwin-gharibi commented on code on Jul 16, 2026 16:17 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400
    +)
    +
    +func CreateToolSet(runConfig *config.RuntimeConfig) (tools.ToolSet, error) {
    +	wd := runConfig.WorkingDir
    +	if wd == "" {
    +		var err error
    +		wd, err = os.Getwd()
    +		if err != nil {
    +			return nil, fmt.Errorf("determining working directory: %w", err)
    +		}
    +	}
    +	return New(wd), nil
    +}
    +
    +type ToolSet struct {
    +	dir string
    +}
    +
    +var (
    +	_ tools.ToolSet      = (*ToolSet)(nil)
    +	_ tools.Instructable = (*ToolSet)(nil)
    +)
    +
    +func New(dir string) *ToolSet { return &ToolSet{dir: dir} }
    +
    +func (t *ToolSet) open() (*gogit.Repository, error) {
    +	repo, err := gogit.PlainOpenWithOptions(t.dir, &gogit.PlainOpenOptions{DetectDotGit: true})
    +	if err != nil {
    +		return nil, fmt.Errorf("opening git repository at %s: %w", t.dir, err)
    +	}
    +	return repo, nil
    +}
    +
    +type StatusArgs struct{}
    +
    +type LogArgs struct {
    +	Limit int    `json:"limit,omitempty" jsonschema:"Maximum number of commits to return (default 20)"`

    Done.

    dwin-gharibi dwin-gharibi commented on code on Jul 16, 2026 16:17 UTC
    Code Review
    docs/tools/git/index.md:1
    @@ -0,0 +1,86 @@
    +---
    +title: "Git Tool"
    +description: "Read-only inspection of the working git repository."
    +keywords: docker agent, ai agents, tools, toolsets, git tool
    +linkTitle: "Git"
    +weight: 130

    Done.

    dwin-gharibi dwin-gharibi commented on code on Jul 16, 2026 16:17 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400
    +)
    +
    +func CreateToolSet(runConfig *config.RuntimeConfig) (tools.ToolSet, error) {
    +	wd := runConfig.WorkingDir
    +	if wd == "" {
    +		var err error
    +		wd, err = os.Getwd()
    +		if err != nil {
    +			return nil, fmt.Errorf("determining working directory: %w", err)
    +		}
    +	}
    +	return New(wd), nil
    +}
    +
    +type ToolSet struct {
    +	dir string
    +}
    +
    +var (
    +	_ tools.ToolSet      = (*ToolSet)(nil)
    +	_ tools.Instructable = (*ToolSet)(nil)
    +)
    +
    +func New(dir string) *ToolSet { return &ToolSet{dir: dir} }
    +
    +func (t *ToolSet) open() (*gogit.Repository, error) {
    +	repo, err := gogit.PlainOpenWithOptions(t.dir, &gogit.PlainOpenOptions{DetectDotGit: true})
    +	if err != nil {
    +		return nil, fmt.Errorf("opening git repository at %s: %w", t.dir, err)
    +	}
    +	return repo, nil
    +}
    +
    +type StatusArgs struct{}
    +
    +type LogArgs struct {
    +	Limit int    `json:"limit,omitempty" jsonschema:"Maximum number of commits to return (default 20)"`
    +	Path  string `json:"path,omitempty" jsonschema:"Only show commits that touch this path"`
    +}
    +
    +type BranchesArgs struct{}
    +
    +type ShowArgs struct {
    +	Ref string `json:"ref,omitempty" jsonschema:"Commit hash or revision to show (default HEAD)"`
    +}
    +
    +type BlameArgs struct {
    +	Path string `json:"path" jsonschema:"File path to blame, relative to the repository root"`
    +	Rev  string `json:"rev,omitempty" jsonschema:"Commit or revision to blame at (default HEAD)"`
    +}
    +
    +func (t *ToolSet) status(_ context.Context, _ StatusArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	wt, err := repo.Worktree()
    +	if err != nil {
    +		return tools.ResultError("Error: reading worktree: " + err.Error()), nil
    +	}
    +	st, err := wt.Status()
    +	if err != nil {
    +		return tools.ResultError("Error: reading status: " + err.Error()), nil
    +	}
    +
    +	branch := "(detached HEAD)"
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		branch = head.Name().Short()
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "On branch %s\n", branch)
    +
    +	paths := make([]string, 0, len(st))
    +	for p, fs := range st {
    +		if fs.Staging == gogit.Unmodified && fs.Worktree == gogit.Unmodified {
    +			continue
    +		}
    +		paths = append(paths, p)
    +	}
    +	if len(paths) == 0 {
    +		b.WriteString("Working tree clean.")
    +		return tools.ResultSuccess(b.String()), nil
    +	}
    +	sort.Strings(paths)
    +	fmt.Fprintf(&b, "%d changed file(s) [XY = staged/worktree; M=modified A=added D=deleted R=renamed ?=untracked]:\n", len(paths))
    +	for _, p := range paths {
    +		fs := st[p]
    +		fmt.Fprintf(&b, "  %c%c %s\n", fs.Staging, fs.Worktree, p)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) log(_ context.Context, args LogArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	opts := &gogit.LogOptions{Order: gogit.LogOrderCommitterTime}
    +	if args.Path != "" {
    +		p := args.Path
    +		opts.FileName = &p
    +	}
    +	iter, err := repo.Log(opts)
    +	if err != nil {
    +		return tools.ResultError("Error: reading log: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	limit := args.Limit
    +	if limit <= 0 {
    +		limit = defaultLogLimit
    +	}
    +
    +	var b strings.Builder
    +	count := 0
    +	err = iter.ForEach(func(c *object.Commit) error {
    +		if count >= limit {
    +			return storer.ErrStop
    +		}
    +		fmt.Fprintf(&b, "%s  %s  %s  %s\n",
    +			c.Hash.String()[:8], c.Author.When.Format("2006-01-02"), c.Author.Name, firstLine(c.Message))
    +		count++
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating log: " + err.Error()), nil
    +	}
    +	if count == 0 {
    +		return tools.ResultSuccess("No commits found."), nil
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) branches(_ context.Context, _ BranchesArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +
    +	current := ""
    +	if head, err := repo.Head(); err == nil && head.Name().IsBranch() {
    +		current = head.Name().Short()
    +	}
    +
    +	iter, err := repo.Branches()
    +	if err != nil {
    +		return tools.ResultError("Error: reading branches: " + err.Error()), nil
    +	}
    +	defer iter.Close()
    +
    +	var names []string
    +	err = iter.ForEach(func(ref *plumbing.Reference) error {
    +		names = append(names, ref.Name().Short())
    +		return nil
    +	})
    +	if err != nil {
    +		return tools.ResultError("Error: iterating branches: " + err.Error()), nil
    +	}
    +	if len(names) == 0 {
    +		return tools.ResultSuccess("No branches."), nil
    +	}
    +	sort.Strings(names)
    +
    +	var b strings.Builder
    +	for _, n := range names {
    +		marker := "  "
    +		if n == current {
    +			marker = "* "
    +		}
    +		fmt.Fprintf(&b, "%s%s\n", marker, n)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) show(_ context.Context, args ShowArgs) (*tools.ToolCallResult, error) {
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Ref)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	fmt.Fprintf(&b, "commit %s\n", commit.Hash.String())
    +	fmt.Fprintf(&b, "Author: %s <%s>\n", commit.Author.Name, commit.Author.Email)
    +	fmt.Fprintf(&b, "Date:   %s\n\n", commit.Author.When.Format("2006-01-02 15:04:05 -0700"))
    +	fmt.Fprintf(&b, "%s\n", strings.TrimRight(commit.Message, "\n"))
    +
    +	if stats, err := commit.Stats(); err == nil && len(stats) > 0 {
    +		b.WriteString("\nChanged files:\n")
    +		for _, s := range stats {
    +			fmt.Fprintf(&b, "  %s (+%d, -%d)\n", s.Name, s.Addition, s.Deletion)
    +		}
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func (t *ToolSet) blame(_ context.Context, args BlameArgs) (*tools.ToolCallResult, error) {
    +	if strings.TrimSpace(args.Path) == "" {
    +		return tools.ResultError("Error: path is required."), nil
    +	}
    +	repo, err := t.open()
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	hash, err := resolveRev(repo, args.Rev)
    +	if err != nil {
    +		return tools.ResultError("Error: " + err.Error()), nil
    +	}
    +	commit, err := repo.CommitObject(hash)
    +	if err != nil {
    +		return tools.ResultError("Error: reading commit: " + err.Error()), nil
    +	}
    +	result, err := gogit.Blame(commit, args.Path)
    +	if err != nil {
    +		return tools.ResultError("Error: blaming " + args.Path + ": " + err.Error()), nil
    +	}
    +
    +	var b strings.Builder
    +	for i, line := range result.Lines {
    +		if i >= maxBlameLines {
    +			fmt.Fprintf(&b, "... (%d more lines truncated)\n", len(result.Lines)-maxBlameLines)
    +			break
    +		}
    +		short := line.Hash.String()
    +		if len(short) > 8 {
    +			short = short[:8]
    +		}
    +		fmt.Fprintf(&b, "%s %-20s %4d| %s\n", short, line.Author, i+1, line.Text)
    +	}
    +	return tools.ResultSuccess(b.String()), nil
    +}
    +
    +func resolveRev(repo *gogit.Repository, rev string) (plumbing.Hash, error) {
    +	if strings.TrimSpace(rev) == "" {
    +		rev = "HEAD"
    +	}
    +	h, err := repo.ResolveRevision(plumbing.Revision(rev))
    +	if err != nil {
    +		return plumbing.ZeroHash, fmt.Errorf("resolving revision %q: %w", rev, err)
    +	}
    +	return *h, nil
    +}
    +
    +func firstLine(msg string) string {
    +	msg = strings.TrimSpace(msg)
    +	if i := strings.IndexByte(msg, '\n'); i >= 0 {
    +		return msg[:i]
    +	}
    +	return msg
    +}
    +
    +func (t *ToolSet) Tools(context.Context) ([]tools.Tool, error) {
    +	ro := tools.ToolAnnotations{ReadOnlyHint: true}
    +	return []tools.Tool{
    +		{
    +			Name:                    ToolNameGitStatus,
    +			Category:                category,
    +			Description:             "Show the working tree status: current branch and changed files (staged, unstaged, untracked).",
    +			Parameters:              tools.MustSchemaFor[StatusArgs](),
    +			OutputSchema:            tools.MustSchemaFor[string](),
    +			Handler:                 tools.NewHandler(t.status),
    +			Annotations:             tools.ToolAnnotations{ReadOnlyHint: true, Title: "Git Status"},
    +			AddDescriptionParameter: true,
    +		},
    +		{
    +			Name:                    ToolNameGitLog,
    +			Category:                category,
    +			Description:             "Show recent commit history (hash, date, author, subject). Optionally limit the count or filter by path.",
    +			Parameters:              tools.MustSchemaFor[LogArgs](),
    +			OutputSchema:            tools.MustSchemaFor[string](),
    +			Handler:                 tools.NewHandler(t.log),
    +			Annotations:             tools.ToolAnnotations{ReadOnlyHint: true, Title: "Git Log"},
    +			AddDescriptionParameter: true,
    +		},
    +		{
    +			Name:                    ToolNameGitBranches,
    +			Category:                category,
    +			Description:             "List local branches, marking the current one with an asterisk.",
    +			Parameters:              tools.MustSchemaFor[BranchesArgs](),
    +			OutputSchema:            tools.MustSchemaFor[string](),
    +			Handler:                 tools.NewHandler(t.branches),
    +			Annotations:             ro,

    Done.

    dwin-gharibi dwin-gharibi commented on code on Jul 16, 2026 16:17 UTC
    Code Review
    pkg/teamloader/toolsets/toolsets.go:1
    @@ -73,6 +74,9 @@ func DefaultToolsetCreators() map[string]teamloader.ToolsetCreator {
     		"fetch": func(_ context.Context, toolset latest.Toolset, _ string, runConfig *config.RuntimeConfig, _ string) (tools.ToolSet, error) {
     			return fetch.CreateToolSet(toolset, runConfig)
     		},
    +		"git": func(_ context.Context, _ latest.Toolset, _ string, runConfig *config.RuntimeConfig, _ string) (tools.ToolSet, error) {

    Done.

    dwin-gharibi dwin-gharibi commented on code on Jul 16, 2026 16:18 UTC
    Code Review
    pkg/tools/builtin/git/git.go:1
    @@ -0,0 +1,358 @@
    +package git
    +
    +import (
    +	"context"
    +	"fmt"
    +	"os"
    +	"sort"
    +	"strings"
    +
    +	gogit "github.com/go-git/go-git/v5"
    +	"github.com/go-git/go-git/v5/plumbing"
    +	"github.com/go-git/go-git/v5/plumbing/object"
    +	"github.com/go-git/go-git/v5/plumbing/storer"
    +
    +	"github.com/docker/docker-agent/pkg/config"
    +	"github.com/docker/docker-agent/pkg/tools"
    +)
    +
    +const (
    +	ToolNameGitStatus   = "git_status"
    +	ToolNameGitLog      = "git_log"
    +	ToolNameGitBranches = "git_branches"
    +	ToolNameGitShow     = "git_show"
    +	ToolNameGitBlame    = "git_blame"
    +
    +	category        = "git"
    +	defaultLogLimit = 20
    +	maxBlameLines   = 400

    Done.

    dwin-gharibi dwin-gharibi commented on Jul 16, 2026 16:30 UTC
    Author

    @Sayt-0 Thank you for the review - the reproduction detail (including the max-same-issues: 3 note, which would have had me chasing 3 of 10) made this quick to act on. I have pushed an update addressing both blocking items and all four suggestions.

    Blocking

    1. golangci-lint on the branch. Fixed both:
    - forbidigo: replaced all 10 context.Background() occurrences in git_test.go with t.Context(). As you predicted the linter only showed 3, so I fixed them from the file rather than the report - and the context import became orphaned as a result, which I removed.
    - modernize: firstLine now uses strings.Cut exactly as suggested.

    2. agent-schema.json not updated. Added "git" to the toolset type enum - and to the anyOf branch for types requiring no extra fields, which is the part I would otherwise have missed. #3670 showed that adding only to the primary enum still fails with Must validate at least one schema (anyOf), so both registration points are covered.

    Suggestions (all taken)

    3. Unborn HEAD. A freshly initialized repo now reports On branch (no commits yet) from git_status, and git_log returns No commits yet. instead of Error: reading log: reference not found (checked via plumbing.ErrReferenceNotFound). Covered by TestGitUnbornHead.

    4. limit upper bound. Capped at 200 (maxLogLimit), mirroring the maxBlameLines approach, and the parameter description now says so. TestGitLogLimitIsCapped asserts limit: 1000000 returns exactly 200 lines.

    5. ro inconsistency. Dropped the variable and inlined tools.ToolAnnotations{ReadOnlyHint: true, Title: "Git Branches"} so all five tools are consistent and git_branches now has a Title.

    6. Docs caveats. Added both:
    - A warning that DetectDotGit walks up parent directories, so a non-repo working directory under a tracked ancestor (e.g. dotfiles in $HOME) resolves to that ancestor and exposes its history — and that the filesystem allow/deny lists do not apply. That one is worth having in writing; thank you for catching it.
    - A performance note that Status() rehashes the worktree and Blame scales with history × file size, with the explicit point that maxBlameLines truncates only after the computation.

    7. Test coverage gaps. Added tests for git_log path filter, git_show with an explicit ref and an invalid ref, git_blame with rev, the blame truncation path, and CreateToolSet (working-directory wiring).

    8. Docs weight. Moved to 125 to resolve the collision with docs/tools/mcp/index.md (130).

    On start_line / end_line for blame: I have left that out of v1 as you suggested, and noted the 400-line cutoff in the docs. Happy to add the range parameters in this PR if you would rather have them now.

    Do let me know if any change is required please.

    dwin-gharibi dwin-gharibi commented on Jul 16, 2026 16:40 UTC
    Author

    Fixed malformed agent-schema.json @Sayt-0.

    Sayt-0 Sayt-0 commented on Jul 17, 2026 08:24 UTC
    Contributor

    looks good now thank you !

    Sayt-0 Sayt-0 approved these changes on Jul 17, 2026 08:24 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    dwin-gharibi dwin-gharibi
    Labels
    risk: low confidence: 73.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 51.3% (MEDIUM) · Higher = larger blast radius
    51.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 73.8% · Lower = rushed or shallow review
    73.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 13.4% · Safe to merge
    13.4%