mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 01:50:44 +08:00
重构仓库目录为统一的 runtime 分层并清理历史 openclaw 残留。
本次迁移将网关/通道/工具/技能/脚本与协议资源集中到新结构,统一路径常量与脚本转发机制,减少顶层噪音并保证运行与测试行为一致。 Made-with: Cursor
This commit is contained in:
parent
ba3836f00f
commit
4a23b715a2
498 changed files with 2760 additions and 2200 deletions
46
runtime/command_parser.py
Normal file
46
runtime/command_parser.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Literal
|
||||
|
||||
CommandAction = Literal["new", "reset"]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ParsedCommand:
|
||||
action: CommandAction
|
||||
raw: str
|
||||
command: str
|
||||
args: tuple[str, ...]
|
||||
|
||||
|
||||
def parse_internal_command(text: str) -> ParsedCommand | None:
|
||||
"""
|
||||
Parse top-level slash/plain reset commands.
|
||||
|
||||
Supported:
|
||||
- /new, new
|
||||
- /reset, reset
|
||||
"""
|
||||
t = str(text or "").strip()
|
||||
if not t:
|
||||
return None
|
||||
parts = [x for x in t.split() if str(x or "").strip()]
|
||||
if not parts:
|
||||
return None
|
||||
first_raw = parts[0].strip()
|
||||
first_norm = first_raw.lower()
|
||||
if first_norm.startswith(("/", "/")):
|
||||
first_norm = first_norm[1:]
|
||||
# English aliases + localized aliases
|
||||
new_aliases = {"new", "n", "新建", "重开"}
|
||||
reset_aliases = {"reset", "r", "重置", "清空"}
|
||||
if first_norm in new_aliases:
|
||||
return ParsedCommand(action="new", raw=t, command=first_norm, args=tuple(parts[1:]))
|
||||
if first_norm in reset_aliases:
|
||||
return ParsedCommand(action="reset", raw=t, command=first_norm, args=tuple(parts[1:]))
|
||||
return None
|
||||
|
||||
|
||||
__all__ = ["ParsedCommand", "parse_internal_command"]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue