Skip to content

Commit fe6b4ca

Browse files
committed
feat(command-blocker): ✨ Allow nix registry references
Enhanced the command blocker to permit nix registry references in commands. This change ensures that commands using the nix package manager can be executed without being blocked, improving compatibility with nix-based workflows. - Added test cases for allowing nix registry references. - Updated the command blocking logic to accommodate nix commands. Fixes #<issue-number>
1 parent 23c837b commit fe6b4ca

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

command-blocker.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,20 @@ describe("Command Blocker", () => {
901901
await expect(
902902
plugin["tool.execute.before"](input3, output3)
903903
).rejects.toThrow();
904+
});
904905

905-
const input4 = { tool: "bash" };
906-
const output4 = { args: { command: "nix run my-flake#output" } };
907-
await expect(
908-
plugin["tool.execute.before"](input4, output4)
909-
).rejects.toThrow();
906+
it("should allow nix registry references", async () => {
907+
const input1 = { tool: "bash" };
908+
const output1 = { args: { command: "nix run nixpkgs#yq" } };
909+
await expect(async () => {
910+
await plugin["tool.execute.before"](input1, output1);
911+
}).not.toThrow();
912+
913+
const input2 = { tool: "bash" };
914+
const output2 = { args: { command: "nix run nixpkgs/unstable#hello" } };
915+
await expect(async () => {
916+
await plugin["tool.execute.before"](input2, output2);
917+
}).not.toThrow();
910918
});
911919

912920
it("should allow non-nix commands", async () => {

command-blocker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,7 @@ function checkNixCommand(command: string): void {
284284
!flakeArg.match(/^git\+https:/) &&
285285
(flakeArg.startsWith("./") ||
286286
flakeArg.startsWith("../") ||
287-
flakeArg.startsWith("/") ||
288-
/^[a-zA-Z0-9._-]+$/.test(flakeArg.split("#")[0]))
287+
flakeArg.startsWith("/"))
289288
) {
290289
throw new Error(BLOCKED_COMMAND_MESSAGES["nix"]);
291290
}
@@ -316,8 +315,7 @@ function checkNixCommand(command: string): void {
316315
!flakeArg.match(/^git\+https:/) &&
317316
(flakeArg.startsWith("./") ||
318317
flakeArg.startsWith("../") ||
319-
flakeArg.startsWith("/") ||
320-
/^[a-zA-Z0-9._-]+$/.test(flakeArg.split("#")[0]))
318+
flakeArg.startsWith("/"))
321319
) {
322320
throw new Error(BLOCKED_COMMAND_MESSAGES["nix"]);
323321
}

0 commit comments

Comments
 (0)