qwen_agent/skills/developing/user-context-loader/hooks/pre_save.py
朱潮 425f3c5bb4 chore: replace Chinese comments and log messages with English
Convert all Chinese comments, docstrings, logger/print output,
HTTPException detail messages, and API response messages to English
across the entire codebase. Functional zh/ja localized strings
(e.g. prompt templates, timezone display names, date formats) are
preserved as-is.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-30 19:45:35 +08:00

40 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""
PreSave Hook - Pre-save message processing example
Executed before messages are saved to the database; can be used for content
filtering, sensitive information masking, etc.
"""
import os
import sys
def main():
"""Read parameters from environment variables and process them."""
content = os.environ.get('CONTENT', '')
role = os.environ.get('ROLE', '')
# Example: add sensitive information masking logic here
# e.g.: remove phone numbers, emails, and other sensitive information
# Output the processed content (output original content if no modification needed)
print(content)
# Only logging here; content is not modified
if content:
# Example: masking (commented out; enable as needed in production)
# import re
# processed = content
# # Simple phone number masking
# processed = re.sub(r'1[3-9]\d{9}', '[PHONE]', processed)
# # Email masking
# processed = re.sub(r'\b[\w.-]+@[\w.-]+\.\w+\b', '[EMAIL]', processed)
# print(processed)
pass
return 0
if __name__ == '__main__':
sys.exit(main())