feat(ralph): interactive UX layer pe Discord și Telegram (W1)
Adaugă straturile interactive peste slash commands flat: **Discord (`src/adapters/discord_views.py`):** - `RalphRootView` — listă proiecte workspace cu emoji status + Refresh + Close - `RalphProjectView` — Propose / Vezi PRD / Aprobă tonight / Status / Stop / Înapoi - `RalphProposeModal` — TextInput pentru descriere feature - Critical pattern: `await interaction.response.defer(ephemeral=True)` în orice button callback cu I/O (eng review concern #2 — "Discord 3s timeout") - `/p slug` autocomplete din `~/workspace/` - `/l` afișează `RalphRootView` ephemeral **Telegram (`src/adapters/telegram_bot.py`):** - `cmd_ralph_l` (fără arg) trimite `InlineKeyboardMarkup` cu workspace + active - `callback_ralph` cu pattern `^ralph:` rutează: project, menu, refresh, close, propose, prd, status, approve, stop - Pentru "Propose feature" → set ralph_flow state cu step=input_description + `ForceReply()`; `handle_message` detectează state și rutează la `_ralph_propose` - Pasează `adapter_name="telegram"` la `route_message` **State management (`src/ralph_flow.py`):** - Atomic JSON peste `sessions/ralph_flow.json` (pattern reusat din claude_session) - Schema per (adapter, chat, user): `{step, project?, expires_at, ...}` - TTL 10 min default; `cleanup_expired()` și auto-drop la `get_state` pe expirate **Router (`src/router.py`):** - `route_message` primește `adapter_name` keyword arg - `_maybe_whatsapp_redirect` adaugă "💡 Pentru meniu interactiv folosește Discord sau Telegram" la mesajele de usage când adapter_name="whatsapp" - WhatsApp `_handle_chat` pasează `adapter_name="whatsapp"` **Tests:** - `test_ralph_flow.py` — 10 teste (round-trip, isolation, expiry, atomic write) - `test_router.py::TestRalphDispatch` — 3 teste (whatsapp redirect, discord no-redirect, usage message) Foundation pentru W2 (planning agent — STEP_IN_PLANNING reservat). Spike Step 0 PASS: skill subprocess + AskUserQuestion→text serialization confirmat empiric (vezi tasks/spike-planning-findings.md). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,7 @@ from src.router import (
|
||||
_ralph_stop,
|
||||
_load_approved_tasks,
|
||||
)
|
||||
from src.adapters.discord_views import RalphRootView
|
||||
|
||||
logger = logging.getLogger("echo-core.discord")
|
||||
_security_log = logging.getLogger("echo-core.security")
|
||||
@@ -933,8 +934,28 @@ def create_bot(config: Config) -> discord.Client:
|
||||
) -> list[app_commands.Choice[str]]:
|
||||
return await _autocomplete_by_status(interaction, current, ("running", "approved"))
|
||||
|
||||
async def _ralph_autocomplete_workspace(
|
||||
interaction: discord.Interaction, current: str
|
||||
) -> list[app_commands.Choice[str]]:
|
||||
from pathlib import Path
|
||||
ws = Path("/home/moltbot/workspace")
|
||||
if not ws.exists():
|
||||
return []
|
||||
current_low = (current or "").lower()
|
||||
choices: list[app_commands.Choice[str]] = []
|
||||
for p in sorted(ws.iterdir()):
|
||||
if not p.is_dir() or p.name.startswith("."):
|
||||
continue
|
||||
if current_low and current_low not in p.name.lower():
|
||||
continue
|
||||
choices.append(app_commands.Choice(name=p.name, value=p.name))
|
||||
if len(choices) >= 25:
|
||||
break
|
||||
return choices
|
||||
|
||||
@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")
|
||||
@app_commands.autocomplete(slug=_ralph_autocomplete_workspace)
|
||||
async def ralph_p(
|
||||
interaction: discord.Interaction, slug: str, description: str
|
||||
) -> None:
|
||||
@@ -949,9 +970,12 @@ def create_bot(config: Config) -> discord.Client:
|
||||
slugs = [slug] if slug else []
|
||||
await interaction.response.send_message(_ralph_approve(slugs))
|
||||
|
||||
@tree.command(name="l", description="List Ralph projects status")
|
||||
@tree.command(name="l", description="List Ralph projects (interactive)")
|
||||
async def ralph_l(interaction: discord.Interaction) -> None:
|
||||
await interaction.response.send_message(_ralph_status())
|
||||
view = RalphRootView()
|
||||
await interaction.response.send_message(
|
||||
view.render_summary(), view=view, ephemeral=True
|
||||
)
|
||||
|
||||
@tree.command(name="k", description="Stop a running Ralph project")
|
||||
@app_commands.describe(slug="Project slug to stop")
|
||||
|
||||
Reference in New Issue
Block a user