/** Git operator tool — safe git operations. Mirrors `tools/git/git_operator.rs`. */ import type { JsonValue } from "@zesdex/domain"; import { type Tool, type ToolCtx } from "../mod.ts"; import { argStr, executeCmd, optStrArray } from "../util.ts"; import { checkGitDestructive } from "../shell/git.ts"; export class GitOperator implements Tool { name = "git_operator"; description = "Execute git operations (commit, push, pull, branch, status, log, etc.)"; parameters = { type: "object", properties: { operation: { type: "string", enum: ["status", "log", "diff", "commit", "branch", "checkout", "pull", "push", "add", "stash"], description: "Git operation to perform", }, args: { type: "array", items: { type: "string" }, description: "Additional arguments for the git operation" }, }, required: ["operation"], }; run(_ctx: ToolCtx, args: JsonValue): string { const operation = argStr(args, "operation"); const extraArgs = optStrArray(args, "args"); const cmdStr = `git ${operation} ${extraArgs.join(" ")}`; const blocked = checkGitDestructive(cmdStr); if (blocked) throw new Error(`blocked: ${blocked}`); return executeCmd(["git", operation, ...extraArgs]); } }