mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-06 05:17:15 +00:00
`hermes -z` has run through the gateway (`_run_oneshot_from_args` -> `launch_gateway_chat`) at every dispatch site for a while, but the old in-process runner stayed behind: `hermes_cli.oneshot.run_oneshot` / `_run_agent` built a bare AIAgent outside the session authority, and `hermes_cli.main._run_and_exit_oneshot` (with its `_cleanup_oneshot_runtime` cleanup table) was its only caller. Nothing outside tests reached any of it. Delete that path. `hermes_cli.main._exit_after_oneshot` stays exactly as it is: `--cpu-profile` names it as the one-shot hard-exit path and it writes the profile before `os._exit`; only its docstring loses the pointer to the removed cleanup helper. `hermes_cli/oneshot.py` keeps only what the gateway path and gateway CLI turns still import: the exit-code mapping, the `--usage-file` ledger with its auxiliary-usage delta, and `--toolsets` normalization. The process-receipt eval probe now calls `process_registry.wait_for_pending_completions` directly. Tests that only exercised the deleted runner are removed; the exit-code and usage-file tests now call the kept helpers directly; the cost-guard test patches the gateway launcher instead of the removed function. A new test pins that `hermes -z` dispatches to `launch_gateway_chat`. Refs #145171 (EP-11a)
59 lines
2.7 KiB
Python
59 lines
2.7 KiB
Python
"""Live process I/O proof, without model calls: python probe.py REPO OUT_DIR."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
repo, out = map(Path, sys.argv[1:3])
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
producer = '''
|
|
import json, shlex, sys
|
|
from gateway.session_context import scoped_current_session_id
|
|
from tools.terminal_tool import terminal_tool
|
|
from tools.process_registry import process_registry
|
|
with scoped_current_session_id("receipt-owner"):
|
|
code = "import sys,time; time.sleep(.2); print('RECEIPT_STDOUT'); print('RECEIPT_STDERR',file=sys.stderr); sys.exit(7)"
|
|
result = json.loads(terminal_tool(shlex.join([sys.executable, '-c', code]), background=True,
|
|
notify_on_complete=True, task_id='receipt-task'))
|
|
process_registry.wait_for_pending_completions(None)
|
|
session = process_registry.get(result['session_id'])
|
|
session._reader_thread.join(timeout=10)
|
|
print(json.dumps({'spawn': result, 'live': process_registry.read_log(session.id)}))
|
|
'''
|
|
consumer = '''
|
|
import json,sys
|
|
from gateway.session_context import scoped_current_session_id
|
|
from tools.process_registry import process_registry
|
|
with scoped_current_session_id(sys.argv[2]):
|
|
print(json.dumps({'log':process_registry.read_log(sys.argv[1]),
|
|
'poll':process_registry.poll(sys.argv[1]),
|
|
'replayed':process_registry.completion_queue.qsize()}))
|
|
'''
|
|
env = {key: value for key, value in os.environ.items()
|
|
if not key.startswith(('HERMES_', 'OPENAI_', 'ANTHROPIC_', 'TERMINAL_'))
|
|
and not key.endswith(('_API_KEY', '_TOKEN', '_SECRET'))}
|
|
env.update(HOME=str(out), HERMES_HOME=str(out / 'profile'), PYTHONPATH=str(repo),
|
|
TERMINAL_CWD=str(out), PYTHONDONTWRITEBYTECODE='1')
|
|
|
|
def run(code, *args, profile=None):
|
|
child_env = dict(env)
|
|
if profile:
|
|
child_env['HERMES_HOME'] = str(out / profile)
|
|
result = subprocess.run([sys.executable, '-c', code, *args], cwd=repo,
|
|
env=child_env, stdin=subprocess.DEVNULL,
|
|
capture_output=True, text=True, encoding='utf-8', timeout=45, check=False)
|
|
if result.returncode:
|
|
raise RuntimeError(result.stdout + result.stderr)
|
|
return json.loads(result.stdout.splitlines()[-1])
|
|
|
|
before_exit = run(producer)
|
|
sid = before_exit['spawn']['session_id']
|
|
result = {'repo': str(repo), 'before_exit': before_exit,
|
|
'owner': run(consumer, sid, 'receipt-owner'),
|
|
'stranger': run(consumer, sid, 'receipt-stranger'),
|
|
'unbound': run(consumer, sid, ''),
|
|
'other_profile': run(consumer, sid, 'receipt-owner', profile='other-profile')}
|
|
(out / 'result.json').write_text(json.dumps(result, indent=2), encoding='utf-8')
|
|
print(json.dumps(result, indent=2))
|