feat: add --char CLI argument for character selection
- Pre-parse --char before config import via argparse - Falls back to config.yaml agent.character if not provided - Replaces manual sys.argv parsing with proper argparse - Retains existing -w/--workspace argument
This commit is contained in:
parent
f72533dcc3
commit
414f94811a
31
hendrik.py
31
hendrik.py
@ -1,4 +1,14 @@
|
|||||||
import os, sys, threading, time, signal
|
import os, sys
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
# Pre-parse --char BEFORE config import (config reads os.environ at import time)
|
||||||
|
_pre = argparse.ArgumentParser(add_help=False)
|
||||||
|
_pre.add_argument('--char', type=str, default=None)
|
||||||
|
_pre_args, _ = _pre.parse_known_args()
|
||||||
|
if _pre_args.char:
|
||||||
|
os.environ['AGENT_CHARACTER'] = _pre_args.char
|
||||||
|
|
||||||
|
import threading, time, signal
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
@ -58,23 +68,20 @@ TOOLS = gadget.tool_schemas (tools_definition)
|
|||||||
TOOL_HANDLERS = gadget.tool_handlers (tools_definition)
|
TOOL_HANDLERS = gadget.tool_handlers (tools_definition)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
llm_client = LLMClient(config.llm_baseurl, config.llm_model, config.llm_api_key, config.llm_timeout)
|
parser = argparse.ArgumentParser(description="Hendrik AI Agent")
|
||||||
|
parser.add_argument('--char', type=str, default=None, help='Character name (overrides config.yaml)')
|
||||||
|
parser.add_argument('-w', '--workspace', type=str, default=None, help='Working directory')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
workspace = None
|
if args.workspace:
|
||||||
i = 1
|
resolved = os.path.abspath(args.workspace)
|
||||||
while i < len(sys.argv):
|
|
||||||
if sys.argv[i] in ('-w', '--workspace') and i + 1 < len(sys.argv):
|
|
||||||
workspace = sys.argv[i + 1]
|
|
||||||
i += 2
|
|
||||||
else:
|
|
||||||
i += 1
|
|
||||||
if workspace:
|
|
||||||
resolved = os.path.abspath(workspace)
|
|
||||||
if not os.path.isdir(resolved):
|
if not os.path.isdir(resolved):
|
||||||
print(f"Error: '{resolved}' is not a valid directory", flush=True)
|
print(f"Error: '{resolved}' is not a valid directory", flush=True)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
os.chdir(resolved)
|
os.chdir(resolved)
|
||||||
|
|
||||||
|
llm_client = LLMClient(config.llm_baseurl, config.llm_model, config.llm_api_key, config.llm_timeout)
|
||||||
|
|
||||||
services = []
|
services = []
|
||||||
|
|
||||||
if config.XMPP_ENABLED:
|
if config.XMPP_ENABLED:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user