feat(ralph): unified slash commands /p /a /l /k cu legacy aliases

Restructurează comenzile Ralph într-un dispatcher unificat (_try_ralph_dispatch)
care suportă atât comenzile noi scurte (/p /a /l /k) cât și aliasurile legacy
(!propose !approve !status !stop). Pe Discord adaugă slash commands native cu
autocomplete dinamic pentru pending (/a) și running (/k). Pe Telegram apar în
meniul /. WhatsApp le parsează ca text plain.

Activează cron jobs morning-report (08:30) și evening-report (21:00) și adaugă
night-execute (23:00) pentru execuția autonomă a proiectelor aprobate.

Foundation pentru W1 din planul "Echo Core conversational planning agent".

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-26 17:46:52 +00:00
parent 479fcc4356
commit 094c6be5a9
5 changed files with 296 additions and 106 deletions

View File

@@ -22,7 +22,13 @@ from src.claude_session import (
VALID_MODELS,
)
from src.fast_commands import dispatch as fast_dispatch
from src.router import route_message
from src.router import (
route_message,
_ralph_propose,
_ralph_approve,
_ralph_status,
_ralph_stop,
)
logger = logging.getLogger("echo-core.telegram")
_security_log = logging.getLogger("echo-core.security")
@@ -141,6 +147,12 @@ async def cmd_help(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"/logs [N] — Log lines",
"/doctor — Diagnostics",
"/heartbeat — Health checks",
"",
"*Ralph (autonomous projects)*",
"/p <slug> <descriere> — Propose new project",
"/a [slug] — Approve for tonight (no slug = list pending)",
"/l — List projects status",
"/k <slug> — Stop a running project",
]
await update.message.reply_text("\n".join(lines), parse_mode="Markdown")
@@ -299,6 +311,52 @@ async def cmd_register(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
)
# --- Ralph commands (autonomous project execution) ---
async def cmd_ralph_p(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""/p <slug> <descriere> — propune proiect Ralph."""
args = list(context.args or [])
if len(args) < 2:
await update.message.reply_text(
"Folosire: /p <slug> <descriere>\nEx: /p roa2web Homepage redesign cu hero section"
)
return
slug = args[0]
description = " ".join(args[1:])
result = await asyncio.to_thread(_ralph_propose, slug, description)
await update.message.reply_text(result)
async def cmd_ralph_a(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""/a [slug] — aprobă proiect (fără arg = listă pending)."""
args = list(context.args or [])
slugs: list[str] = []
if args:
for a in args:
slugs.extend(s.strip() for s in a.replace(",", " ").split() if s.strip())
result = await asyncio.to_thread(_ralph_approve, slugs)
await update.message.reply_text(result)
async def cmd_ralph_l(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""/l — status proiecte Ralph."""
args = list(context.args or [])
filter_slug = args[0].lower() if args else None
result = await asyncio.to_thread(_ralph_status, filter_slug)
await update.message.reply_text(result)
async def cmd_ralph_k(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""/k <slug> — oprește proiect Ralph."""
args = list(context.args or [])
if not args:
await update.message.reply_text("Folosire: /k <slug>")
return
result = await asyncio.to_thread(_ralph_stop, args[0])
await update.message.reply_text(result)
# --- Fast command handlers ---
@@ -529,6 +587,12 @@ def create_telegram_bot(config: Config, token: str) -> Application:
app.add_handler(CommandHandler("register", cmd_register))
app.add_handler(CallbackQueryHandler(callback_model, pattern="^model:"))
# Ralph commands
app.add_handler(CommandHandler("p", cmd_ralph_p))
app.add_handler(CommandHandler("a", cmd_ralph_a))
app.add_handler(CommandHandler("l", cmd_ralph_l))
app.add_handler(CommandHandler("k", cmd_ralph_k))
# Fast commands
app.add_handler(CommandHandler("email", cmd_email))
app.add_handler(CommandHandler("emailsend", cmd_emailsend))
@@ -579,6 +643,10 @@ def create_telegram_bot(config: Config, token: str) -> Application:
BotCommand("logs", "Show log lines"),
BotCommand("doctor", "Diagnostics"),
BotCommand("heartbeat", "Health checks"),
BotCommand("p", "Ralph: propose new project"),
BotCommand("a", "Ralph: approve project for tonight"),
BotCommand("l", "Ralph: list projects status"),
BotCommand("k", "Ralph: stop running project"),
])
app.post_init = post_init