From 66e3ccbf0d190fd2a48124add9c2565e392e55f9 Mon Sep 17 00:00:00 2001 From: Jiaqing Liang Date: Fri, 27 Feb 2026 23:01:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96file=5Fread?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=80=BB=E8=BE=91=20-=20=E7=B4=A7=E5=87=91?= =?UTF-8?q?=E5=8C=96+=E8=B7=AF=E5=BE=84=E4=BF=AE=E5=A4=8D+=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E5=AE=89=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ga.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ga.py b/ga.py index 7e6b1e0..966dd21 100644 --- a/ga.py +++ b/ga.py @@ -1,4 +1,5 @@ import sys, os, re, json, time, threading +from datetime import datetime from pathlib import Path import tempfile, traceback, subprocess, itertools, collections if sys.stdout is None: sys.stdout = open(os.devnull, "w") @@ -129,8 +130,7 @@ def web_scan(tabs_only=False, switch_tab_id=None): result = { "status": "success", "metadata": { - "tabs_count": len(tabs), - "tabs": tabs, + "tabs_count": len(tabs), "tabs": tabs, "active_tab": driver.default_session_id } } @@ -148,6 +148,16 @@ def format_error(e): return f"{exc_type.__name__}: {str(e)} @ {fname}:{f.lineno}, {f.name} -> `{f.line}`" return f"{exc_type.__name__}: {str(e)}" +def log_memory_access(path): + if 'memory' not in path: return + stats_file = 'memory/file_access_stats.json' + try: + with open(stats_file, 'r', encoding='utf-8') as f: stats = json.load(f) + except: stats = {} + fname = os.path.basename(path) + stats[fname] = {'count': stats.get(fname, {}).get('count', 0) + 1, 'last': datetime.now().strftime('%Y-%m-%d')} + with open(stats_file, 'w', encoding='utf-8') as f: json.dump(stats, f, indent=2, ensure_ascii=False) + def web_execute_js(script, switch_tab_id=None): """ 执行 JS 脚本来控制浏览器,并捕获结果和页面变化。 @@ -384,6 +394,7 @@ class GenericAgentHandler(BaseHandler): if ' ... [TRUNCATED]' in result: result += '\n\n(某些行被截断,如需完整内容可改用 code_run 读取)' next_prompt = self._get_anchor_prompt() + log_memory_access(path) if 'memory' in path or 'sop' in path: next_prompt += "\n[SYSTEM TIPS] 正在读取记忆或SOP文件,若决定按sop执行请提取sop中的关键点(特别是靠后的)update working memory." return StepOutcome(result, next_prompt=next_prompt)