feat(herdr): complete Herdr 0.8.0 adaptation and sanitize module

This commit is contained in:
2026-08-14 23:09:08 +09:00
parent 1c24732be0
commit 301ff5bb1f
7 changed files with 117 additions and 111 deletions
+33 -42
View File
@@ -193,6 +193,12 @@ if cmd1 == "workspace":
elif args[i] == "--cwd":
cwd = args[i+1]
i += 2
elif args[i] == "--env":
env_val = args[i+1]
if "=" in env_val:
k, v = env_val.split("=", 1)
os.environ[k] = v
i += 2
else:
i += 1
workspaces = state.get("workspaces", [])
@@ -250,7 +256,17 @@ elif cmd1 == "pane":
print(json.dumps({"result": {"panes": panes_list}}))
sys.exit(0)
elif cmd2 == "split":
# W11: pane split handler
# W11: pane split handler with --env support
i = 2
while i < len(args):
if args[i] == "--env":
env_val = args[i+1]
if "=" in env_val:
k, v = env_val.split("=", 1)
os.environ[k] = v
i += 2
else:
i += 1
print(json.dumps({"result": {"type": "pane_split", "pane": {"pane_id": "w1:p_split"}}}))
sys.exit(0)
elif cmd2 == "layout":
@@ -351,6 +367,7 @@ elif cmd1 == "agent":
ws = ""
cwd = ""
pane = ""
agent_type = ""
# Find where -- is
try:
double_dash_idx = args.index("--")
@@ -360,8 +377,8 @@ elif cmd1 == "agent":
agent_cmd = []
opts = args[3:]
# Whitelist herdr allowed flags (0.7.4 + 0.8.0)
whitelist = {"--cwd", "--workspace", "--tab", "--split", "--env", "--focus", "--no-focus", "--kind", "--pane", "--timeout"}
# Whitelist herdr 0.8.0 allowed flags for agent start
whitelist = {"--kind", "--pane", "--timeout"}
i = 0
unknown_flags = []
while i < len(opts):
@@ -370,13 +387,7 @@ elif cmd1 == "agent":
unknown_flags.append(opt)
i += 1
continue
if opt == "--workspace":
ws = opts[i+1]
i += 2
elif opt == "--cwd":
cwd = opts[i+1]
i += 2
elif opt == "--kind":
if opt == "--kind":
agent_type = opts[i+1]
i += 2
elif opt == "--pane":
@@ -384,42 +395,22 @@ elif cmd1 == "agent":
i += 2
elif opt == "--timeout":
i += 2
elif opt == "--env":
env_val = opts[i+1]
if "=" in env_val:
k, v = env_val.split("=", 1)
os.environ[k] = v
i += 2
elif opt in ("--split", "--tab"):
i += 2
else:
i += 1
if unknown_flags:
print(f"usage: herdr agent start <name> [--cwd PATH] [--workspace ID] [--tab ID] [--split right|down] [--env KEY=VALUE] [--focus|--no-focus] -- <argv...> (unknown flag: {unknown_flags[0]})")
sys.exit(0)
# Determine the agent type (claude, agy, hermes, cline)
agent_type = "claude"
if agent_cmd:
if "claude" in agent_cmd[0]:
agent_type = "claude"
elif "agy" in agent_cmd[0]:
agent_type = "agy"
elif "hermes" in agent_cmd[0]:
agent_type = "hermes"
elif "cline" in agent_cmd[0]:
agent_type = "cline"
else:
# guess from name
if "claude" in name:
agent_type = "claude"
elif "agy" in name:
agent_type = "agy"
elif "hermes" in name:
agent_type = "hermes"
elif "cline" in name:
agent_type = "cline"
sys.stderr.write("error: unexpected argument '" + str(unknown_flags[0]) + "' found\\\\n\\\\nUsage: herdr agent start <NAME> --kind <KIND> --pane <ID> [OPTIONS] [-- [AGENT_ARG]...]\\\\n")
sys.exit(1)
if not agent_type or not pane:
sys.stderr.write("error: the following required arguments were not provided:\\\\n --kind <KIND>\\\\n --pane <ID>\\\\n")
sys.exit(1)
# Name validation: ^[a-z][a-z0-9_-]{0,31}$
import re
if not re.match(r'^[a-z][a-z0-9_-]{0,31}$', name):
print(f"error: invalid value '{name}' for '<NAME>': agent name must start with a lowercase letter and contain only lowercase letters, digits, '-' or '_' (1-32 characters)", file=sys.stderr)
sys.exit(1)
# TUI Welcome Tokens definition to prevent TUI readiness check timeout
buffer_content = {