-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommands.py
More file actions
50 lines (36 loc) · 1.1 KB
/
commands.py
File metadata and controls
50 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Closed slash-command grammar for the plan-and-task example."""
from dataclasses import dataclass
@dataclass(slots=True)
class Command:
"""Represents a parsed slash command with its name, raw text, and arguments."""
name: str
raw: str
args: list[str]
_COMMANDS_WITH_ARGS = {
"/plan:start",
"/plan:resume",
"/plan:qa_review",
"/task:start",
"/task:resume",
"/task:replan",
}
_COMMANDS_WITHOUT_ARGS = {
"/plan:status",
"/plan:finalize",
"/plan:write",
"/task:status",
"/task:abort",
}
_SUPPORTED_COMMANDS = _COMMANDS_WITH_ARGS | _COMMANDS_WITHOUT_ARGS
def parse_command(text: str) -> Command:
normalized = text.strip()
if not normalized:
raise ValueError("Command input cannot be empty.")
parts = normalized.split()
name = parts[0]
args = parts[1:]
if name not in _SUPPORTED_COMMANDS:
raise ValueError(f"Unsupported command: {name}")
if name in _COMMANDS_WITHOUT_ARGS and args:
raise ValueError(f"Command does not accept arguments: {name}")
return Command(name=name, raw=normalized, args=args)