onboard_passport.py
1 import json 2 import os 3 import sys 4 import argparse 5 6 # Ensure local imports work 7 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 8 9 from src.registry_manager import RegistryManager 10 11 def onboard_passport(passport_path: str, matrix_id: str, irc_account: str = ""): 12 """ 13 Takes a browser-downloaded envoy_passport.json and adds it to the registry. 14 """ 15 if not os.path.exists(passport_path): 16 print(f"Error: Passport file not found at {passport_path}") 17 return 18 19 with open(passport_path, "r") as f: 20 passport = json.load(f) 21 22 # Extract info 23 pub_key = passport.get("did") # We treat DID as the key for this shim 24 logic_hash = passport.get("logic_checksum") 25 26 if not pub_key or not logic_hash: 27 print("Error: Invalid passport format.") 28 return 29 30 repo_path = "projects/ENVOY/xray" 31 registry = RegistryManager(repo_path) 32 33 # In V4, we don't recalculate logic hash on onboarding if we trust the source, 34 # but we DO calculate the agent_id to ensure consistency. 35 agent_id = registry.register_agent( 36 public_key=pub_key, 37 system_prompt="User-defined via Passport", 38 tools=[], 39 config={"identity": "normie-browser"}, 40 matrix_id=matrix_id, 41 irc_account=irc_account 42 ) 43 44 print(f"\n[ENVOY] Onboarding Successful!") 45 print(f" ✓ Agent ID: {agent_id}") 46 print(f" ✓ Profile added to envoy/registry/agents.json") 47 print(f" ✓ Network status: TRUSTED") 48 49 if __name__ == "__main__": 50 parser = argparse.ArgumentParser(description="Onboard an ENVOY Passport to the Registry") 51 parser.add_argument("passport", help="Path to the envoy_passport.json file") 52 parser.add_argument("--matrix", default="@user:matrix.org", help="Matrix ID for coordination") 53 parser.add_argument("--irc", default="", help="IRC Nick for side-channel") 54 55 args = parser.parse_args() 56 onboard_passport(args.passport, args.matrix, args.irc)