Skip to content

Commit 5e19567

Browse files
committed
Extract git tool group into agent-tools/git.ts
Moves git_status/git_diff/git_log/git_commit out of agent-tools.ts. Pure move, executeTool's dispatch is unchanged.
1 parent cc31140 commit 5e19567

2 files changed

Lines changed: 28 additions & 25 deletions

File tree

‎app/src/agent-tools.ts‎

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getAccountToken } from "./accounts";
22
import { capturePageScreenshot } from "./browser-capture";
3-
import { shellQuote } from "./command-sandbox";
43
import * as settingsStore from "./settings-store";
54
import * as terminalManager from "./terminal-manager";
65
import { AGENT_TOOLS } from "./agent-tools/schema";
@@ -35,6 +34,7 @@ import {
3534
killAllBackgroundCommands,
3635
killBackgroundCommandsForWorkspace,
3736
} from "./agent-tools/execution";
37+
import { gitStatus, gitDiff, gitLog, gitCommit } from "./agent-tools/git";
3838

3939
export { AGENT_TOOLS };
4040
export {
@@ -67,30 +67,7 @@ export {
6767
killAllBackgroundCommands,
6868
killBackgroundCommandsForWorkspace,
6969
};
70-
71-
function gitCommand(workspaceRoot: string, args: string): Promise<string> {
72-
return runCommand(workspaceRoot, `git ${args}`, ".");
73-
}
74-
75-
export function gitStatus(workspaceRoot: string): Promise<string> {
76-
return gitCommand(workspaceRoot, "status");
77-
}
78-
79-
export function gitDiff(workspaceRoot: string, staged = false, relativePath?: string): Promise<string> {
80-
const target = relativePath ? ` -- ${shellQuote(relativePath)}` : "";
81-
return gitCommand(workspaceRoot, `diff${staged ? " --staged" : ""}${target}`);
82-
}
83-
84-
export function gitLog(workspaceRoot: string, count = 10): Promise<string> {
85-
return gitCommand(workspaceRoot, `log -n ${Math.max(1, Math.min(count, 100))} --oneline`);
86-
}
87-
88-
export async function gitCommit(workspaceRoot: string, message: string): Promise<string> {
89-
await gitCommand(workspaceRoot, "add -A");
90-
// JSON.stringify escapes `"` and `\` but not `$` or backticks, and the
91-
// result is handed to `sh -c` — so it is not a shell-quoting function.
92-
return gitCommand(workspaceRoot, `commit -m ${shellQuote(message)}`);
93-
}
70+
export { gitStatus, gitDiff, gitLog, gitCommit };
9471

9572
const WEB_FETCH_TIMEOUT_MS = 15_000;
9673
const MAX_FETCH_CHARS = 30_000;

‎app/src/agent-tools/git.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { shellQuote } from "../command-sandbox";
2+
import { runCommand } from "./execution";
3+
4+
function gitCommand(workspaceRoot: string, args: string): Promise<string> {
5+
return runCommand(workspaceRoot, `git ${args}`, ".");
6+
}
7+
8+
export function gitStatus(workspaceRoot: string): Promise<string> {
9+
return gitCommand(workspaceRoot, "status");
10+
}
11+
12+
export function gitDiff(workspaceRoot: string, staged = false, relativePath?: string): Promise<string> {
13+
const target = relativePath ? ` -- ${shellQuote(relativePath)}` : "";
14+
return gitCommand(workspaceRoot, `diff${staged ? " --staged" : ""}${target}`);
15+
}
16+
17+
export function gitLog(workspaceRoot: string, count = 10): Promise<string> {
18+
return gitCommand(workspaceRoot, `log -n ${Math.max(1, Math.min(count, 100))} --oneline`);
19+
}
20+
21+
export async function gitCommit(workspaceRoot: string, message: string): Promise<string> {
22+
await gitCommand(workspaceRoot, "add -A");
23+
// JSON.stringify escapes `"` and `\` but not `$` or backticks, and the
24+
// result is handed to `sh -c` — so it is not a shell-quoting function.
25+
return gitCommand(workspaceRoot, `commit -m ${shellQuote(message)}`);
26+
}

0 commit comments

Comments
 (0)