蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

用真实CLI核对独立目录中的非密钥配置

PYTHONWindows、本站Python3.12控制器、独立原生Python3.14.9与固定Hermes源码;Desktop未运行。cli_probe.py
cli_probe.py60 行
"""Observe actual Hermes metadata and nonsecret config in two owned temporary profiles."""
import argparse,json,os,subprocess
from pathlib import Path
from tempfile import TemporaryDirectory
def exercise(python,root):
 python=Path(python).resolve();root=Path(root).resolve()
 if not python.is_file():raise ValueError("explicit Python executable is required")
 home=root/"user";data=root/"profile-a";other=root/"profile-b";temp=root/"temp"
 for p in [home,home/"local",home/"roaming",data,other,temp]:p.mkdir(parents=True,exist_ok=True)
 initial=b"model: ''\nupdates:\n  check: false\nsecurity:\n  allow_lazy_installs: false\ndesktop:\n  repo_scan_enabled: false\nterminal:\n  backend: local\n"
 for p in [data,other]:(p/"config.yaml").write_bytes(initial)
 env={k:os.environ[k] for k in ["SystemRoot","WINDIR"] if k in os.environ}
 env.update(USERPROFILE=str(home),HOME=str(home),LOCALAPPDATA=str(home/"local"),APPDATA=str(home/"roaming"),
  TEMP=str(temp),TMP=str(temp),HERMES_HOME=str(data),PYTHONIOENCODING="utf-8",HERMES_NONINTERACTIVE="1",
  UV_PYTHON_DOWNLOADS="never",UV_HTTP_RETRIES="0",
  PATH=str(python.parent)+os.pathsep+str(Path(env["SystemRoot"])/"System32")+os.pathsep+str(Path(env["SystemRoot"])))
 calls=[]
 def invoke(arguments,profile=data):
  evidence=root/("network-"+str(len(calls))+".json");childenv=dict(env,HERMES_HOME=str(profile))
  result=subprocess.run([str(python),"-I","-B","-X","utf8",str(Path(__file__).with_name("native_driver.py")),str(evidence),*arguments],
   cwd=root,env=childenv,stdin=subprocess.DEVNULL,capture_output=True,encoding="utf8",timeout=35,
   creationflags=subprocess.CREATE_NO_WINDOW)
  record=dict(arguments=arguments,exit_code=result.returncode,stdout=result.stdout,stderr=result.stderr,
   profile=profile.name,network=json.loads(evidence.read_bytes()) if evidence.exists() else None)
  calls.append(record)
  if result.returncode:raise RuntimeError(json.dumps(record,ensure_ascii=False))
  return result.stdout
 rows=[]
 def check(name,inputs,operation,expected,actual):
  assert expected==actual,(name,expected,actual)
  rows.append(dict(name=name,input=inputs,operation=operation,expected=expected,actual=actual))
 version=invoke(["--version"])
 check("native_version","--version","run genuine metadata path; preserve the complete version output",
  [True,True],["Hermes Agent " in version,"Python: 3.14" in version])
 helptext=invoke(["--help"])
 check("native_help","--help","run genuine parser; command availability is not GUI execution",
  [True,True],["config" in helptext,"desktop" in helptext])
 before=invoke(["config","get","terminal.backend"])
 invoke(["config","set","terminal.backend","docker"]);after=invoke(["config","get","terminal.backend"])
 check("native_dotted_roundtrip","terminal.backend local to docker","write through CLI, then reread using another real process",
  ["local\n","docker\n"],[before,after])
 invoke(["config","set","HERMES_TIMEZONE","UTC"]);value=invoke(["config","get","HERMES_TIMEZONE"])
 envraw=(data/".env").read_bytes();yamlraw=(data/"config.yaml").read_bytes()
 check("native_environment_route","ordinary nonsecret HERMES_TIMEZONE","write/read natively and inspect destination file bytes",
  ["UTC\n",True,False],[value,b"HERMES_TIMEZONE" in envraw,b"HERMES_TIMEZONE" in yamlraw])
 separate=invoke(["config","get","terminal.backend"],other)
 check("native_profile_directory","second fresh HERMES_HOME","reread the second owned directory after changing the first",
  ["local\n",False],[separate,(other/".env").exists()])
 check("python_socket_guard","all observed native calls","inspect driver audit records; this is a Python-level guard, not an OS firewall",
  True,all(c["network"] is not None and c["network"]["blocked_connections"]==[] for c in calls))
 return dict(cases=rows,native_commands=calls,native_version_output=version,
  scope="Actual Hermes CLI metadata/help and nonsecret configuration only in owned temporary homes; package installation, Desktop, TUI, Docker, models and cloud authentication not verified",
  native_Hermes_CLI_executed=True,native_Desktop_executed=False,existing_credentials_read=False,
  protected_tutorial_scripts_executed=False,source_site_requests=0,model_requests=0,external_messages_sent=0)
if __name__=="__main__":
 p=argparse.ArgumentParser(description=__doc__);p.add_argument("--python",required=True)
 a=p.parse_args()
 with TemporaryDirectory(prefix="mbsky-owned-hermes-cli-") as directory:result=exercise(a.python,Path(directory))
 print(json.dumps(result,ensure_ascii=False))
本例需在 Windows、本站Python3.12控制器、独立原生Python3.14.9与固定Hermes源码;Desktop未运行。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows、本站Python3.12控制器、独立原生Python3.14.9与固定Hermes源码;Desktop未运行。

入口文件:projects/hermes-desktop-cli/cli_probe.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 cli_probe.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows、本站Python3.12控制器、独立原生Python3.14.9与固定Hermes源码;Desktop未运行。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Hermes Agent

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a190.zip

下载课程关联工程包:Hermes Agent

课程关联工程包(登记关联20章) · 含当前章节或实例 · mbskycom202612a184.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习