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

@@ -16,7 +16,14 @@ 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,
_load_approved_tasks,
)
logger = logging.getLogger("echo-core.discord")
_security_log = logging.getLogger("echo-core.security")
@@ -150,6 +157,12 @@ def create_bot(config: Config) -> discord.Client:
"`/heartbeat` — Health checks",
"`/restart` — Restart bot (owner)",
"",
"**Ralph (autonomous projects)**",
"`/p <slug> <description>` — Propose new project",
"`/a [slug]` — Approve for tonight (autocomplete)",
"`/l` — List projects status",
"`/k <slug>` — Stop a running project (autocomplete)",
"",
"**Admin**",
"`/setup` — Claim ownership",
"`/channel add <alias>` — Register channel",
@@ -886,6 +899,68 @@ def create_bot(config: Config) -> discord.Client:
f"Error reading logs: {e}", ephemeral=True
)
# --- Ralph commands (autonomous project execution) ---
async def _autocomplete_by_status(
interaction: discord.Interaction, current: str, statuses: tuple[str, ...]
) -> list[app_commands.Choice[str]]:
try:
data = _load_approved_tasks()
except Exception:
return []
current_low = (current or "").lower()
choices: list[app_commands.Choice[str]] = []
for p in data.get("projects", []):
if p.get("status") not in statuses:
continue
name = p.get("name", "")
if current_low and current_low not in name.lower():
continue
desc = (p.get("description") or "").strip()
label = f"{name} — {desc}"[:100] if desc else name
choices.append(app_commands.Choice(name=label, value=name))
if len(choices) >= 25:
break
return choices
async def _ralph_autocomplete_pending(
interaction: discord.Interaction, current: str
) -> list[app_commands.Choice[str]]:
return await _autocomplete_by_status(interaction, current, ("pending",))
async def _ralph_autocomplete_running(
interaction: discord.Interaction, current: str
) -> list[app_commands.Choice[str]]:
return await _autocomplete_by_status(interaction, current, ("running", "approved"))
@tree.command(name="p", description="Propose new Ralph project")
@app_commands.describe(slug="Project slug (e.g. game-library)", description="Short description of what to do")
async def ralph_p(
interaction: discord.Interaction, slug: str, description: str
) -> None:
await interaction.response.send_message(_ralph_propose(slug, description))
@tree.command(name="a", description="Approve Ralph project for tonight (no slug = list pending)")
@app_commands.describe(slug="Project slug to approve (leave empty to list pending)")
@app_commands.autocomplete(slug=_ralph_autocomplete_pending)
async def ralph_a(
interaction: discord.Interaction, slug: str | None = None
) -> None:
slugs = [slug] if slug else []
await interaction.response.send_message(_ralph_approve(slugs))
@tree.command(name="l", description="List Ralph projects status")
async def ralph_l(interaction: discord.Interaction) -> None:
await interaction.response.send_message(_ralph_status())
@tree.command(name="k", description="Stop a running Ralph project")
@app_commands.describe(slug="Project slug to stop")
@app_commands.autocomplete(slug=_ralph_autocomplete_running)
async def ralph_k(
interaction: discord.Interaction, slug: str
) -> None:
await interaction.response.send_message(_ralph_stop(slug))
# --- Events ---
@client.event

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