diff --git a/agentmain.py b/agentmain.py index 937fb7eb..0f45b53f 100644 --- a/agentmain.py +++ b/agentmain.py @@ -41,7 +41,6 @@ def get_system_prompt(): class GeneraticAgent: def __init__(self): - script_dir = os.path.dirname(os.path.abspath(__file__)) os.makedirs(os.path.join(script_dir, 'temp'), exist_ok=True) self.lock = threading.Lock() self.task_dir = None @@ -137,7 +136,6 @@ class GeneraticAgent: self.history.append(f"[USER]: {rquery}") sys_prompt = get_system_prompt() + getattr(self.llmclient.backend, 'extra_sys_prompt', '') - script_dir = os.path.dirname(os.path.abspath(__file__)) handler = GenericAgentHandler(self, self.history, os.path.join(script_dir, 'temp')) if self.handler and 'key_info' in self.handler.working: ki = re.sub(r'\n\[SYSTEM\] 此为.*?工作记忆[。\n]*', '', self.handler.working['key_info']) # 去旧 diff --git a/ga.py b/ga.py index e6e7d9b4..d66dca94 100644 --- a/ga.py +++ b/ga.py @@ -7,6 +7,7 @@ if sys.stderr is None: sys.stderr = open(os.devnull, "w") sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from agent_loop import BaseHandler, StepOutcome, json_default +script_dir = os.path.dirname(os.path.abspath(__file__)) def code_run(code, code_type="python", timeout=60, cwd=None, code_cwd=None, stop_signal=[]): """代码执行器 @@ -15,7 +16,6 @@ def code_run(code, code_type="python", timeout=60, cwd=None, code_cwd=None, stop 优先使用python,仅在必要系统操作时使用powershell""" preview = (code[:60].replace('\n', ' ') + '...') if len(code) > 60 else code.strip() yield f"[Action] Running {code_type} in {os.path.basename(cwd)}: {preview}\n" - script_dir = os.path.dirname(os.path.abspath(__file__)) cwd = cwd or os.path.join(script_dir, 'temp'); tmp_path = None if code_type in ["python", "py"]: tmp_file = tempfile.NamedTemporaryFile(suffix=".ai.py", delete=False, mode='w', encoding='utf-8', dir=code_cwd) @@ -151,7 +151,6 @@ def format_error(e): def log_memory_access(path): if 'memory' not in path: return - script_dir = os.path.dirname(os.path.abspath(__file__)) stats_file = os.path.join(script_dir, 'memory/file_access_stats.json') try: with open(stats_file, 'r', encoding='utf-8') as f: stats = json.load(f) @@ -550,7 +549,6 @@ class GenericAgentHandler(BaseHandler): def get_global_memory(): prompt = "\n" try: - script_dir = os.path.dirname(os.path.abspath(__file__)) suffix = '_en' if os.environ.get('GA_LANG', '') == 'en' else '' with open(os.path.join(script_dir, 'memory/global_mem_insight.txt'), 'r', encoding='utf-8', errors='replace') as f: insight = f.read() with open(os.path.join(script_dir, f'assets/insight_fixed_structure{suffix}.txt'), 'r', encoding='utf-8') as f: structure = f.read() diff --git a/memory/procmem_scanner_sop.md b/memory/procmem_scanner_sop.md index 39393fcb..ebc8e8ee 100644 --- a/memory/procmem_scanner_sop.md +++ b/memory/procmem_scanner_sop.md @@ -34,49 +34,3 @@ python ../memory/procmem_scanner.py "pattern" --llm ## 4. CE式差集扫描定位动态字段 定位微信等自绘UI中随操作变化的内存字段(如当前会话标题)。核心:一次全量scan + 多次ReadProcessMemory筛选。 - -**流程(3个联系人A/B/C即可收敛):** -1. 取PID:Weixin.exe有多进程,用`win32gui.GetWindowThreadProcessId`取有窗口的 -2. 当前会话=A → `scan_memory(pid, "人名A", mode="string")` → 地址集S -3. 切到B → 读S全部地址 → 保留内容≠"人名A"的 → 候选C -4. 切到A → 读C全部地址 → 保留内容=="人名A"的 → 候选C'(通常1-3个) -5. 若C'>1 → 再切B/C重复 → 直到唯一 - -**切换会话+读地址 完整代码:** -```python -import sys; sys.path.append('../memory') -import ljqCtrl, pygetwindow as gw, pyperclip, time, ctypes - -def switch_chat(name): - win = gw.getWindowsWithTitle('微信')[0] - if win.isMinimized: win.restore() - win.activate(); time.sleep(0.3) - S = 1 / ljqCtrl.dpi_scale - ljqCtrl.Click(int((win.left+150)*S), int((win.top+40)*S)); time.sleep(0.5) - pyperclip.copy(name); ljqCtrl.Press('ctrl+v'); time.sleep(1.5) - ljqCtrl.Click(int((win.left+150)*S), int((win.top+130)*S)); time.sleep(0.8) - -def read_addrs(pid, addrs): - k32 = ctypes.windll.kernel32 - hp = k32.OpenProcess(0x10, False, pid) - buf = ctypes.create_string_buffer(256) - rd = ctypes.c_size_t() - result = {} - for a in addrs: - a = int(a, 16) if isinstance(a, str) else a - k32.ReadProcessMemory(hp, ctypes.c_void_p(a), buf, 256, ctypes.byref(rd)) - result[a] = buf.raw.split(b'\x00')[0].decode('utf-8', errors='ignore').strip() - k32.CloseHandle(hp) - return result # {addr: text} -``` - -**坑点:** -- 进程名Weixin.exe(非WeChat.exe);地址字符串先`int(addr,16)` -- 步骤3筛≠A(排除空/乱码),步骤4筛==A(正向确认),交替最快 -- **搜索切换会话完全可用**,大部分差集步骤直接搜索即可。注意:搜索结果首条可能是广告,粘贴后≥1.5s再点,确认是联系人再点(或点第2条) -- **仅最终消歧步骤需侧栏点击**:候选>1时,在侧栏点一个不同的人(不经搜索框),read_addrs看哪个地址跟随变化→那个就是标题栏 -- 切换后用read_addrs验证确实切成功了再继续 -- **步骤3/4必须用read_addrs读原始地址集,严禁重新scan**:重新scan只能找到静态残留(聊天记录等),动态地址已变不在结果中,会导致0候选 -- **选A/B联系人用wechat_db_utils.quick_connect查真人**,避免搜索触发广告弹窗(公众号/小程序名会弹广告) -- **scan_memory返回格式**:默认返回str列表(每项"Addr:0x...\nHex:..."),非dict。提取地址用`[int(r.split('\n')[0].split(':')[1],16) for r in results]` -- **侧栏点击禁止估算坐标**:会话列表顺序随消息变化。参考 vision_sop + wechat_send_sop 流程(截图→ask_vision→精确坐标→点击) \ No newline at end of file