Fix reflect loop throttling
This commit is contained in:
1 parent
9405d3fe09
commit
63128dd5bb
3 files changed
+18
-20
No files matched your search
+18
-18
@@ -264,24 +264,24 @@ if __name__ == '__main__':
|
||||
except Exception as e:
|
||||
print(f'[Reflect] check() error: {e}'); task = None
|
||||
if task and task == '/exit': break
|
||||
if not task:
|
||||
time.sleep(getattr(mod, 'INTERVAL', 5)); continue
|
||||
print(f'[Reflect] triggered: {task[:80]}')
|
||||
dq = agent.put_task(task, source='reflect')
|
||||
try:
|
||||
while 'done' not in (item := dq.get(timeout=1200)): pass
|
||||
result = item['done']
|
||||
print(result)
|
||||
except Exception as e:
|
||||
if getattr(mod, 'ONCE', False): raise
|
||||
print(f'[Reflect] drain error: {e}'); result = f'[ERROR] {e}'
|
||||
log_dir = os.path.join(script_dir, 'temp/reflect_logs'); os.makedirs(log_dir, exist_ok=True)
|
||||
script_name = os.path.splitext(os.path.basename(args.reflect))[0]
|
||||
open(os.path.join(log_dir, f'{script_name}_{datetime.now():%Y-%m-%d}.log'), 'a', encoding='utf-8').write(f'[{datetime.now():%m-%d %H:%M}]\n{result}\n\n')
|
||||
if (on_done := getattr(mod, 'on_done', None)):
|
||||
try: on_done(result)
|
||||
except Exception as e: print(f'[Reflect] on_done error: {e}')
|
||||
if getattr(mod, 'ONCE', False): print('[Reflect] ONCE=True, exiting.'); break
|
||||
if task:
|
||||
print(f'[Reflect] triggered: {task[:80]}')
|
||||
dq = agent.put_task(task, source='reflect')
|
||||
try:
|
||||
while 'done' not in (item := dq.get(timeout=1200)): pass
|
||||
result = item['done']
|
||||
print(result)
|
||||
except Exception as e:
|
||||
if getattr(mod, 'ONCE', False): raise
|
||||
print(f'[Reflect] drain error: {e}'); result = f'[ERROR] {e}'
|
||||
log_dir = os.path.join(script_dir, 'temp/reflect_logs'); os.makedirs(log_dir, exist_ok=True)
|
||||
script_name = os.path.splitext(os.path.basename(args.reflect))[0]
|
||||
open(os.path.join(log_dir, f'{script_name}_{datetime.now():%Y-%m-%d}.log'), 'a', encoding='utf-8').write(f'[{datetime.now():%m-%d %H:%M}]\n{result}\n\n')
|
||||
if (on_done := getattr(mod, 'on_done', None)):
|
||||
try: on_done(result)
|
||||
except Exception as e: print(f'[Reflect] on_done error: {e}')
|
||||
if getattr(mod, 'ONCE', False): print('[Reflect] ONCE=True, exiting.'); break
|
||||
time.sleep(getattr(mod, 'INTERVAL', 5))
|
||||
else:
|
||||
try: import readline
|
||||
except Exception: pass
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
"path": {"type": "string", "description": "Relative or absolute"},
|
||||
"start": {"type": "integer", "description": "Start line number (1-based)"},
|
||||
"count": {"type": "integer", "description": "Number of lines to read", "default": 200},
|
||||
"keyword": {"type": "string", "description": "[Optional] If provided, returns first match (case-insensitive) with context"},
|
||||
"show_linenos": {"type": "boolean", "description": "Show line numbers", "default": true}}}
|
||||
}},
|
||||
{"type": "function", "function": {
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
"path": {"type": "string", "description": "文件相对或绝对路径"},
|
||||
"start": {"type": "integer", "description": "起始行号(从 1 开始)"},
|
||||
"count": {"type": "integer", "description": "读取的行数", "default": 200},
|
||||
"keyword": {"type": "string", "description": "可选搜索关键字。如果提供,将返回第一个匹配项(忽略大小写)及其周边的内容"},
|
||||
"show_linenos": {"type": "boolean", "description": "是否显示行号,建议开启以辅助 file_patch 定位", "default": true}}}
|
||||
}},
|
||||
{"type": "function", "function": {
|
||||
|
||||
Reference in new issue
Block a user