Add git autosync functionality

This commit is contained in:
Alex Gleason committed 2025-12-29 16:00:23 -06:00
1 parent 0ee88f5968
commit 758e3ab261
7 files changed
+201 -51

No files matched your search

+8 -1
View File
@@ -12,6 +12,7 @@ export class GitCommitTool implements Tool<GitCommitParams> {
private fs: JSRuntimeFS;
private git: Git;
private cwd: string;
private onCommit?: () => void;
readonly description = "Commit changes to git with a commit message. Automatically adds all unstaged files.";
@@ -19,10 +20,11 @@ export class GitCommitTool implements Tool<GitCommitParams> {
message: z.string().describe('Commit message text'),
});
constructor(fs: JSRuntimeFS, cwd: string, git: Git) {
constructor(fs: JSRuntimeFS, cwd: string, git: Git, options?: { onCommit?: () => void }) {
this.fs = fs;
this.git = git;
this.cwd = cwd;
this.onCommit = options?.onCommit;
}
async execute(args: GitCommitParams): Promise<ToolResult> {
@@ -133,6 +135,11 @@ export class GitCommitTool implements Tool<GitCommitParams> {
if (modifiedFiles > 0) details += ` • ${modifiedFiles} file${modifiedFiles !== 1 ? 's' : ''} modified\n`;
if (deletedFiles > 0) details += ` • ${deletedFiles} file${deletedFiles !== 1 ? 's' : ''} deleted\n`;
// Trigger sync callback if provided
if (this.onCommit) {
this.onCommit();
}
return { content: `${summary}\n\n${details}` };
} catch (error) {
throw new Error(`❌ Error committing changes: ${String(error)}`);