Skip to content

Commit fa2cc8b

Browse files
committed
feat(command-blocker): ✨ Enhance git command handling
Updated the command blocker to allow additional read-only git commands. The changes include allowing `git log` and `git rev-parse` as valid commands while maintaining restrictions on write operations. - Added `git log` and `git rev-parse` to the list of allowed commands. - Updated error messages to reflect the new allowed commands. This enhancement improves the usability of the command blocker for users needing to access git history without compromising version control integrity.
1 parent b5aa08d commit fa2cc8b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

command-blocker.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,18 @@ describe("Command Blocker", () => {
575575
await expect(async () => {
576576
await plugin["tool.execute.before"](input3, output3);
577577
}).not.toThrow();
578+
579+
const input4 = { tool: "bash" };
580+
const output4 = { args: { command: "git rev-parse HEAD" } };
581+
await expect(async () => {
582+
await plugin["tool.execute.before"](input4, output4);
583+
}).not.toThrow();
584+
585+
const input5 = { tool: "bash" };
586+
const output5 = { args: { command: "git log --oneline -1" } };
587+
await expect(async () => {
588+
await plugin["tool.execute.before"](input5, output5);
589+
}).not.toThrow();
578590
});
579591

580592
it("should block write git commands", async () => {
@@ -583,7 +595,7 @@ describe("Command Blocker", () => {
583595
await expect(
584596
plugin["tool.execute.before"](input1, output1)
585597
).rejects.toThrow(
586-
"`git` write operations are blocked to prevent agents from managing version control. Only read-only commands are allowed: `git status`, `git diff`, `git show`."
598+
"`git` write operations are blocked to prevent agents from managing version control. Only read-only commands are allowed: `git status`, `git diff`, `git show`, `git log`, `git rev-parse`."
587599
);
588600

589601
const input2 = { tool: "bash" };
@@ -1449,7 +1461,7 @@ describe("Command Blocker", () => {
14491461

14501462
const hook = (plugin as PluginHook)["tool.execute.before"];
14511463
await expect(hook(input, output)).rejects.toThrow(
1452-
"`git` write operations are blocked to prevent agents from managing version control. Only read-only commands are allowed: `git status`, `git diff`, `git show`."
1464+
"`git` write operations are blocked to prevent agents from managing version control. Only read-only commands are allowed: `git status`, `git diff`, `git show`, `git log`, `git rev-parse`."
14531465
);
14541466
});
14551467

command-blocker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const BLOCKED_COMMAND_MESSAGES: BlockedCommandMessages = {
1818
"`python2` is blocked (Python 2 is deprecated). Use `uv` with Python 3 for modern dependency management. Virtual environment python2 commands are allowed if needed. Example: `uv run --python 3.8 python script.py`",
1919
python3:
2020
"`python3` is blocked to ensure environment isolation. Use `uv` for dependency management or `uvx` for running tools. Virtual environment python3 (e.g., `.venv/bin/python3`) is allowed. Example: `uv run python3 script.py`",
21-
git: "`git` write operations are blocked to prevent agents from managing version control. Only read-only commands are allowed: `git status`, `git diff`, `git show`.",
21+
git: "`git` write operations are blocked to prevent agents from managing version control. Only read-only commands are allowed: `git status`, `git diff`, `git show`, `git log`, `git rev-parse`.",
2222
nix: "Local flake paths without `path:` prefix are blocked to ensure reproducible builds. Use `path:` for local flakes (includes uncommitted changes), `github:` for remote repos, or `git+https:` for git URLs. Examples: `nix run path:./my-flake#output`, `nix run github:user/repo#output`",
2323
};
2424

@@ -56,6 +56,8 @@ const BLOCKED_COMMANDS: readonly string[] = Object.keys(
5656
);
5757
const ALLOWED_GIT_COMMANDS: readonly string[] = [
5858
"git diff",
59+
"git log",
60+
"git rev-parse",
5961
"git show",
6062
"git status",
6163
];

0 commit comments

Comments
 (0)