fix: preserve multi-word topics in CLI generate command

split(maxsplit=2) was splitting "honeypot Kubernetes Security" into
three parts, losing the full topic string. Now splits once to get the
method keyword, then handles remainder per subcommand — honeypot takes
the entire remainder as topic, skill splits it into name + category.
This commit is contained in:
kigland
2026-03-10 01:18:27 +08:00
parent 077371e643
commit 45cf3df4ed
+7 -5
View File
@@ -62,27 +62,29 @@ class PwnKitCLI(cmd.Cmd):
def do_generate(self, arg):
"""Usage: generate honeypot [topic] | generate skill [name] [category]"""
parts = arg.strip().split(maxsplit=2)
parts = arg.strip().split(maxsplit=1)
if not parts or parts[0].lower() not in ["honeypot", "skill"]:
console.print("[red]Usage: generate honeypot [topic] | generate skill [name] [category][/red]")
console.print("[dim] topic — optional, enables LLM-generated content (requires OPENAI_API_KEY)[/dim]")
console.print("[dim] topic — optional free-text, enables LLM-generated content (requires OPENAI_API_KEY)[/dim]")
console.print("[dim] name — skill name (default: sys-tool)[/dim]")
console.print("[dim] category — code-review|data-analysis|copywriting|ui-review|devops|database[/dim]")
return
method = parts[0].lower()
remainder = parts[1].strip() if len(parts) > 1 else ""
api_key = os.getenv("OPENAI_API_KEY")
payload = self._get_mixed_payload()
if method == "honeypot":
topic = parts[1] if len(parts) > 1 else None
topic = remainder or None
if topic and not api_key:
console.print("[yellow][!] OPENAI_API_KEY not set, falling back to template mode.[/yellow]")
topic = None
generate_nginx_honeypot(payload, topic=topic, api_key=api_key)
elif method == "skill":
skill_name = parts[1] if len(parts) > 1 else "sys-tool"
category = parts[2] if len(parts) > 2 else None
skill_parts = remainder.split(maxsplit=1)
skill_name = skill_parts[0] if skill_parts else "sys-tool"
category = skill_parts[1].strip() if len(skill_parts) > 1 else None
if api_key:
generate_poisoned_skill(skill_name, payload, api_key=api_key, category=category)
else: