src / promptPreprocessor.ts
import { type ChatMessage, type PromptPreprocessorController } from "@lmstudio/sdk";
const SYSTEM_RULES = `\
[System: Git Plugin]
⢠git_status ā working tree state, staged/unstaged changes, branch info
⢠git_log ā commit history with optional filters (author, date, file, message search)
⢠git_show ā full diff and metadata for a specific commit
⢠git_diff ā diff between refs, branches, or working tree (staged or unstaged)
⢠git_blame ā line-by-line authorship for a file section
⢠git_branch ā list all branches with last commit
⢠git_stash ā list stashed changes
⢠git_file_history ā all commits that touched a specific file
Always call git_status first to establish the current repo state.
When asked about recent changes, call git_log then git_show on relevant commits.
When asked "who wrote this" or "why was this changed", use git_blame + git_show.
On tool_error, read the error field and verify the repo_path or ref before retrying.`;
export async function promptPreprocessor(
ctl: PromptPreprocessorController,
userMessage: ChatMessage,
): Promise<string | ChatMessage> {
const history = await ctl.pullHistory();
if (history.length !== 0) return userMessage;
return `${SYSTEM_RULES}\n\n${userMessage.getText()}`;
}