chore: Remove obsolete scripts and enhance path configuration

- Deleted `check_md_files.py` and `fix_cursor_md_issue.py` as they are no longer needed.
- Added new functions in `path_config.py` for better path management, including actions log and run_cli paths.
- Updated various modules to utilize the unified path configuration, ensuring backward compatibility and improved maintainability.
- Enhanced documentation in `README.md` to reflect changes in path management and project structure.
This commit is contained in:
Your Name committed 2025-12-28 20:47:30 +08:00
1 parent a0162e3b81
commit b9849b9f5a
9 files changed
+264 -344

No files matched your search

+77 -5
View File
@@ -5,10 +5,11 @@
from __future__ import annotations
from typing import Any, Callable, Tuple
from typing import Any, Callable, Tuple, Optional
import tkinter as tk
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
import os
try:
from ttkbootstrap.scrolled import ScrolledText as TBSrolledText
@@ -18,12 +19,14 @@ except ImportError:
def create_actions_log_viewer(
parent: Any
parent: Any,
filter_var: Optional[tk.StringVar] = None
):
"""创建行为日志查看器组件。
参数:
parent: 父容器
filter_var: 可选的筛选关键字变量(StringVar),如果提供则用于筛选日志
返回:
(actions_log_text, refresh_actions_log_func)
@@ -37,9 +40,78 @@ def create_actions_log_viewer(
pass
def refresh_actions_log() -> None:
"""刷新行为日志。"""
# TODO: 从原文件迁移函数实现
pass
"""刷新行为日志:读取 logs/actions.log 的尾部若干行,在 GUI 中展示关键行为日志(支持简单关键字筛选)。"""
# 使用统一的路径配置
try:
import path_config
path = path_config.get_actions_log_path()
except Exception:
# 回退到旧路径(向后兼容)
path = os.path.join(os.path.dirname(__file__), "..", "logs", "actions.log")
path = os.path.abspath(path)
try:
if os.path.exists(path):
# 仿照 web_gui 的实现:只读最后一小段,避免文件巨大
size = os.path.getsize(path)
if size == 0:
actions_log_text.delete("1.0", "end")
actions_log_text.insert("1.0", "行为日志文件为空")
return
read_bytes = min(size, 65536)
with open(path, "rb") as f:
if read_bytes < size:
f.seek(-read_bytes, os.SEEK_END)
data = f.read()
# 尝试多种编码方式
try:
# 先尝试 utf-8-sig(带BOM)
text = data.decode("utf-8-sig", errors="replace")
except Exception:
try:
# 再尝试 utf-8
text = data.decode("utf-8", errors="replace")
except Exception:
# 最后尝试 gbk(Windows常见编码)
text = data.decode("gbk", errors="replace")
lines = text.splitlines()
# 只取最近 300 行
tail = lines[-300:]
# 关键字筛选:若提供了筛选变量且填写了筛选词,只保留包含该关键字的行
if filter_var is not None:
kw = filter_var.get().strip()
if kw:
tail = [ln for ln in tail if kw in ln]
# 保存当前滚动位置,避免刷新时自动置顶
try:
scroll_position = actions_log_text.yview()[0] # 获取当前滚动位置(顶部可见位置的比例)
except Exception:
scroll_position = 0.0
actions_log_text.delete("1.0", "end")
if tail:
actions_log_text.insert("1.0", "\n".join(tail))
else:
actions_log_text.insert("1.0", "暂无匹配的行为日志")
# 恢复之前的滚动位置,避免自动置顶
try:
actions_log_text.yview_moveto(scroll_position)
except Exception:
pass
else:
actions_log_text.delete("1.0", "end")
actions_log_text.insert(
"1.0", "暂无行为日志(logs/actions.log 不存在)"
)
except Exception as e:
actions_log_text.delete("1.0", "end")
actions_log_text.insert(
"1.0", f"读取行为日志失败: {str(e)}"
)
return actions_log_text, refresh_actions_log