Project Files
src / tools / git-status-tool.ts
import { tool } from "@lmstudio/sdk"
import { simpleGit } from "simple-git"
import { z } from "zod"
import { formatGitError } from "../git/error-formatting"
import { resolveAndValidateRepoPath } from "../path/validation"
import type { Tool, ToolsProviderController } from "@lmstudio/sdk"
/**
* Create the git status tool.
*
* @param ctl Tools provider controller supplied by the LM Studio SDK.
* @returns The configured git status tool.
*/
export function createGitStatusTool(ctl: ToolsProviderController): Tool {
return tool({
name: "git_status",
description: "View the current status of staged, unstaged, and untracked files for a cloned git repository.",
parameters: {
repoName: z.string().describe("Directory name of the cloned git repository."),
},
/**
* Executes the git status command.
*
* @param arguments_ Validated tool parameters.
* @param arguments_.repoName Repository directory name relative to the working directory.
* @param context Runtime tool context supplied by the SDK.
* @returns The git status as JSON, or a user-facing error string.
*/
implementation: async (arguments_, context) => {
const { repoName } = arguments_
const repoPath = resolveAndValidateRepoPath(repoName, ctl.getWorkingDirectory())
const git = simpleGit(repoPath)
context.status(`Reading git status for "${repoName}"…`)
try {
const status = await git.status()
return JSON.stringify(status, undefined, 2)
} catch (error) {
return formatGitError("git_status", repoName, error)
}
},
})
}