Project Files
QWEN.md
LM Studio Git Plugin ā an LM Studio plugin that exposes git operations to local LLMs. The LLM can inspect any git repository within the working directory, or clone new repositories for inspection.
src/ āāā index.ts # Plugin entry point (named main export, called by LM Studio host) āāā tools-provider.ts # ToolsProvider ā aggregates all git tools, injects working directory āāā path/ ā āāā validation.ts # Security: validates all paths stay within the working directory āāā git/ ā āāā error-formatting.ts # formatGitError() ā cleans simple-git errors with operation context ā āāā grep-parsing.ts # parseGrepOutput() ā parses NUL-delimited git grep output ā āāā parameter-schemas.ts # gitSafeString() ā zod string schema rejecting leading-dash flag injection āāā tools/ āāā git-status-tool.ts # git_status ā staged/unstaged/untracked files āāā git-diff-tool.ts # git_diff ā staged or unstaged diff, optional file scope āāā git-log-tool.ts # git_log ā commit history with count/branch āāā git-branch-tool.ts # git_branch ā local/remote branches + current + repo root āāā git-show-tool.ts # git_show ā commit/file content at any ref, with offset/limit pagination and 10 MB cap āāā git-ls-files-tool.ts # git_ls_files ā list tracked files, optional pathspec, paginated āāā git-grep-tool.ts # git_grep ā content search across tracked files, paginated āāā git-clone-tool.ts # git_clone ā clone a remote repo into the working directory
All path validation runs through src/path/validation.ts before any git operation:
| Package | Purpose |
|---|---|
@lmstudio/sdk | LM Studio plugin API (tool(), PluginContext, ToolsProvider) |
simple-git | Git command wrapper |
zod | Runtime parameter validation |
noImplicitOverride.d.ts, .d.ts.map, and files| Command | Description |
|---|---|
npm run build | Compile TypeScript to dist/ |
npm run dev | Run in LM Studio dev mode (requires LM Studio running) |
npm run push | Push published plugin to LM Studio |
npm run lint | Lint with ESLint |
npm run lint:fix | Auto-fix lint issues |
npm run format | Format with Prettier |
npm run format:check | Check formatting without writing |
npm run knip | Detect unused dependencies/exports |
const declarations must have JSDoc@param and @returns tags required for functions@param descriptionany is forbiddenimport type { ... })=== true, typeof x === "string")The project uses a heavy ESLint configuration with these plugins: @typescript-eslint, @stylistic, prettier, sonarjs, import-x, jsdoc, n, regexp, security, unicorn, unused-imports. Running npm run lint must pass with zero errors before committing.
create*Tool() factory in src/tools/*-tool.tstool() factory from @lmstudio/sdk with Zod schemas for parameter validationsimple-git library wraps all git commands ā no shell spawningPluginContext.withToolsProvider()workingDirectory from the ToolsProviderController and validate paths before executionsimple-git calls in try/catch and route caught errors through formatGitError() so the model receives consistent, actionable error strings (per the SDK guidance to return recoverable errors as strings rather than throwing)JSON.stringify(..., undefined, 2) for structured payloads) ā ToolCallResult.content is typed as string in the SDKrepoPath and clone destination is resolved and validated to be a child of controller.getWorkingDirectory(). Paths escaping the working directory throw (this is the only kind of error that throws rather than being caught ā the harness surfaces it to the user).git_status, git_diff, git_log, git_branch, git_show, git_ls_files, and git_grep invoke only read git subcommands.git_clone is the only tool that modifies the filesystem. Its destination is path-validated. No commit, push, branch, or merge operations are exposed.simple-git spawns processes with discrete argument arrays, never shell-interpreted strings.git_show, git_ls_files, and git_grep route their string parameters through the shared gitSafeString schema, which rejects values that start with - so they cannot be reinterpreted as git flags.git_show checks cat-file -s before loading file blobs and also caps git show output at 10 MB post-load to defend against huge commit diffs..js.mapsrc/ ā compiled output in dist/src/tools/*-tool.tscreate*Tool()src/ ā currently src/path/ for filesystem-path concerns and src/git/ for git-output concerns. ESLint forbids non-*-tool.ts files inside src/tools/.constants.ts or types.ts are banned ā co-locate declarations with the module that owns the behaviorsrc/index.ts which is required by the LM Studio host)null ā use undefined instead