This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """Claude Code PreToolUse hook: auto-approve read-only Bash commands. | |
| Deny-first, then allowlist. Unknown commands fall through to user prompt. | |
| Returns JSON with permissionDecision and reason for better diagnostics. | |
| """ | |
| import json | |
| import re | |
| import sys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # FGM class | |
| class FGM(): | |
| def __init__(self, model): | |
| self.model = model | |
| self.backup = {} | |
| def attack(self, epsilon=1., emb_name='word_embeddings'): | |
| for name, param in self.model.named_parameters(): | |
| if param.requires_grad and emb_name in name: | |
| self.backup[name] = param.data.clone() |