This repository has been archived on 2026-03-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AIMisc/Global/welcome.py
T
2026-01-29 01:04:19 +08:00

105 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
import json
import sys
import os
import subprocess
from datetime import datetime
# 颜色代码(ANSI)
class Colors:
HEADER = '\033[95m'
BLUE = '\033[94m'
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
END = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def print_welcome_message():
"""在启动时显示欢迎信息"""
user = os.path.expanduser("~").split("\\")[-1]
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"\n{Colors.CYAN}{'═' * 60}{Colors.END}")
print(f"{Colors.BOLD}{Colors.HEADER}🚀 Claude Code 会话已启动{Colors.END}")
print(f"{Colors.CYAN}{'═' * 60}{Colors.END}")
print(f"{Colors.GREEN}👤 用户: {Colors.END}{user}")
print(f"{Colors.GREEN}🕐 时间: {Colors.END}{current_time}")
# 获取当前目录
cwd = os.getcwd()
print(f"{Colors.GREEN}📁 目录: {Colors.END}{cwd}")
# Git 信息
try:
result = subprocess.run(["git", "branch", "--show-current"],
capture_output=True, text=True, cwd=cwd)
if result.returncode == 0:
branch = result.stdout.strip()
print(f"{Colors.GREEN}🌿 分支: {Colors.END}{branch}")
# 检查是否有未提交的更改
status_result = subprocess.run(["git", "status", "--porcelain"],
capture_output=True, text=True, cwd=cwd)
if status_result.returncode == 0:
if status_result.stdout.strip():
print(f"{Colors.YELLOW}⚠️ 有未提交的更改{Colors.END}")
else:
print(f"{Colors.GREEN}✓ 工作目录干净{Colors.END}")
except:
pass
print(f"{Colors.CYAN}{'═' * 60}{Colors.END}\n")
def load_input():
"""加载输入数据"""
try:
input_data = json.load(sys.stdin)
return input_data
except json.JSONDecodeError as e:
print(f"Error: Invalid JSON input: {e}", file=sys.stderr)
sys.exit(1)
def main():
# 显示欢迎信息(输出到 stderr,这样不会干扰 JSON 输出)
import io
old_stderr = sys.stderr
sys.stderr = io.StringIO()
print_welcome_message()
# 获取欢迎信息并输出到真正的 stderr
welcome_output = sys.stderr.getvalue()
sys.stderr = old_stderr
print(welcome_output, file=sys.stderr, end='')
# 加载输入数据
input_data = load_input()
# 构建 AI 上下文
home_claude_dir = os.path.expanduser("~/.claude")
context = f"""回答我的问题的时候开头必须是'好的!!!!大先生!!!'
重要配置信息:
- 全局 Claude 配置目录路径:{home_claude_dir}
- 当你需要修改或查找全局 Claude 配置时,请始终使用此目录:{home_claude_dir}
- 不要使用 AppData\\Roaming\\.claude,该目录在此系统上不存在
会话信息:
- 当前工作目录:{os.getcwd()}
- 会话开始时间:{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}"""
# 返回 JSON 输出
output = {
"hookSpecificOutput": {
"hookEventName": "SessionStart",
"additionalContext": context
}
}
print(json.dumps(output))
if __name__ == "__main__":
main()