You've already forked agentic-coding-workflow
bugfix
This commit is contained in:
@@ -35,6 +35,7 @@ func registerWorkspaceTools(srv *mcpsdk.Server, deps ServerDeps) {
|
||||
registerGitStatus(srv, deps)
|
||||
registerGitCommit(srv, deps)
|
||||
registerGitPush(srv, deps)
|
||||
registerGitDiff(srv, deps)
|
||||
}
|
||||
|
||||
// ===== 共用 DTO / helper =====
|
||||
@@ -581,6 +582,59 @@ func registerGitCommit(srv *mcpsdk.Server, deps ServerDeps) {
|
||||
})
|
||||
}
|
||||
|
||||
// ===== git_diff (read-only) =====
|
||||
|
||||
type gitDiffIn struct {
|
||||
WorkspaceID string `json:"workspace_id" jsonschema:"workspace UUID"`
|
||||
WorktreeID string `json:"worktree_id,omitempty" jsonschema:"optional worktree UUID; omit to target the main worktree"`
|
||||
Ref string `json:"ref,omitempty" jsonschema:"base ref; empty diffs working tree against HEAD"`
|
||||
Against string `json:"against,omitempty" jsonschema:"second ref; when set with ref produces ref..against"`
|
||||
Staged bool `json:"staged,omitempty" jsonschema:"diff the staged index (--cached) instead of the working tree"`
|
||||
Paths []string `json:"paths,omitempty" jsonschema:"optional pathspecs to restrict the diff"`
|
||||
ContextLines int `json:"context_lines,omitempty" jsonschema:"unified context lines (git default 3 when omitted)"`
|
||||
}
|
||||
type gitDiffOut struct {
|
||||
Diff string `json:"diff"`
|
||||
Truncated bool `json:"truncated"`
|
||||
}
|
||||
|
||||
func registerGitDiff(srv *mcpsdk.Server, deps ServerDeps) {
|
||||
mcpsdk.AddTool(srv,
|
||||
&mcpsdk.Tool{Name: "git_diff", Description: "Show the unified git diff of the main worktree or a branch worktree. Returns raw diff text (capped at 1 MiB)."},
|
||||
func(ctx context.Context, _ *mcpsdk.CallToolRequest, in gitDiffIn) (*mcpsdk.CallToolResult, gitDiffOut, error) {
|
||||
if err := CheckToolFromCtx(ctx, "git_diff"); err != nil {
|
||||
return nil, gitDiffOut{}, err
|
||||
}
|
||||
c, err := deps.Caller.Resolve(ctx)
|
||||
if err != nil {
|
||||
return nil, gitDiffOut{}, err
|
||||
}
|
||||
w, wc, err := scopedWorkspace(ctx, deps, c, in.WorkspaceID)
|
||||
if err != nil {
|
||||
return nil, gitDiffOut{}, err
|
||||
}
|
||||
opts := git.DiffOptions{
|
||||
Ref: in.Ref, Against: in.Against, Staged: in.Staged,
|
||||
Paths: in.Paths, ContextLines: in.ContextLines,
|
||||
}
|
||||
var res git.DiffResult
|
||||
if in.WorktreeID == "" {
|
||||
res, err = deps.GitOps.DiffOnMain(ctx, wc, w.ID, opts)
|
||||
} else {
|
||||
var wt *workspace.Worktree
|
||||
wt, err = worktreeInWorkspace(ctx, deps, wc, w.ID, in.WorktreeID)
|
||||
if err != nil {
|
||||
return nil, gitDiffOut{}, err
|
||||
}
|
||||
res, err = deps.GitOps.DiffOnWorktree(ctx, wc, wt.ID, opts)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, gitDiffOut{}, err
|
||||
}
|
||||
return nil, gitDiffOut{Diff: res.Diff, Truncated: res.Truncated}, nil
|
||||
})
|
||||
}
|
||||
|
||||
func registerGitPush(srv *mcpsdk.Server, deps ServerDeps) {
|
||||
mcpsdk.AddTool(srv,
|
||||
&mcpsdk.Tool{Name: "git_push", Description: "Push the main worktree or a branch worktree to the remote."},
|
||||
|
||||
Reference in New Issue
Block a user