| 11 | |
| 12 | |
| 13 | class ApprovalTracker: |
| 14 | def __init__(self) -> None: |
| 15 | self._approved: set[str] = set() |
| 16 | |
| 17 | def fingerprint(self, operation: ApplyPatchOperation, relative_path: str) -> str: |
| 18 | hasher = hashlib.sha256() |
| 19 | hasher.update(operation.type.encode("utf-8")) |
| 20 | hasher.update(b"\0") |
| 21 | hasher.update(relative_path.encode("utf-8")) |
| 22 | hasher.update(b"\0") |
| 23 | hasher.update((operation.diff or "").encode("utf-8")) |
| 24 | return hasher.hexdigest() |
| 25 | |
| 26 | def remember(self, fingerprint: str) -> None: |
| 27 | self._approved.add(fingerprint) |
| 28 | |
| 29 | def is_approved(self, fingerprint: str) -> bool: |
| 30 | return fingerprint in self._approved |
| 31 | |
| 32 | |
| 33 | class WorkspaceEditor: |