Skip to content

Add a read-only "git" built-in toolset for structured repository inspection #3636

Description

@dwin-gharibi

Overview

Add a new built-in toolset, git, that gives an agent structured, read-only access to the working repository: status, history, branches, a commit's changes, and line-level authorship. It is implemented with go-git (already a project dependency), so it needs no git binary and is fully unit-testable.

Tools (all read-only):

Tool Returns
git_status current branch + changed files (staged / unstaged / untracked)
git_log recent commits (hash, author, date, subject); limit + optional path
git_branches local branches, with the current one marked
git_show one commit's metadata + changed files with +/- line counts
git_blame line-by-line authorship for a file

Motivation

Coding agents constantly need git context — "what changed?", "what's the recent history?", "who last touched this line?". Today the only way is to call the shell tool with raw git commands, which has three drawbacks:

  1. The model must parse free-form porcelain text, which is error-prone.
  2. shell is a powerful, stateful tool; git inspection should not require it, and should never risk a destructive command.
  3. It depends on a git binary being installed in the environment.

A dedicated read-only toolset returns clean, structured output, is safe by construction, and works without shell or the git binary.

Use cases

  1. Before editing, the agent runs git_status + git_diff-style review via git_show/git_log to understand the working state.
  2. "Summarize what changed in the last 5 commits" → git_log(limit=5) + git_show.
  3. "Who introduced this line and why?" → git_blame(path) + git_show(<hash>).
  4. Safe inspection in a hardened agent that deliberately does not enable shell.

Proposed solution

New toolset type git in pkg/tools/builtin/git/, registered in
pkg/teamloader/toolsets/toolsets.go and documented in the built-in toolset catalog (pkg/teamloader/toolsets/catalog.go) — the catalog drift-guard test forces the catalog entry.

  • Implemented with github.com/go-git/go-git/v5 (already a direct dependency) - pure Go, no git binary required.
  • The repository is opened at the agent's WorkingDir (like filesystem), with DetectDotGit so a subdirectory still resolves the repo root.
  • Read-only by design. No add/commit/checkout — write operations are intentionally out of scope for v1 (they are stateful, overlap shell, and raise permission questions). Noted as possible future work.

Alternatives

  • shell + git — works, but returns unstructured text, requires the git binary, and exposes the full (writable, arbitrary-command) shell surface.

Related issues

No response

Additional context

go-git's porcelain differs slightly from the CLI in some edge cases (rename detection, a few .gitignore nuances); this is acceptable for read-only inspection. Working-tree line diffs and write operations are deferred to keep v1 focused and safe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/toolsFor features/issues/fixes related to the usage of built-in and MCP tools

    Fields

    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions