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:
@@ -41,6 +41,7 @@ def route_message(
|
||||
text: str,
|
||||
model: str | None = None,
|
||||
on_text: Callable[[str], None] | None = None,
|
||||
adapter_name: str | None = None,
|
||||
) -> tuple[str, bool]:
|
||||
"""Route an incoming message. Returns (response_text, is_command).
|
||||
|
||||
@@ -49,11 +50,14 @@ def route_message(
|
||||
|
||||
*on_text* — optional callback invoked with each intermediate text block
|
||||
from Claude, enabling real-time streaming to the adapter.
|
||||
|
||||
*adapter_name* — "discord" / "telegram" / "whatsapp" / None. Used for
|
||||
adapter-specific response shaping (e.g., redirect line on WhatsApp).
|
||||
"""
|
||||
text = text.strip()
|
||||
|
||||
# Ralph commands — short form (/p /a /l /k) and legacy aliases (!propose !approve !status !stop)
|
||||
ralph_response = _try_ralph_dispatch(text)
|
||||
ralph_response = _try_ralph_dispatch(text, adapter_name=adapter_name)
|
||||
if ralph_response is not None:
|
||||
return ralph_response, True
|
||||
|
||||
@@ -168,7 +172,19 @@ RALPH_CMDS = {
|
||||
}
|
||||
|
||||
|
||||
def _try_ralph_dispatch(text: str) -> str | None:
|
||||
_WHATSAPP_REDIRECT = (
|
||||
"\n\n💡 Pentru meniu interactiv folosește Discord sau Telegram."
|
||||
)
|
||||
|
||||
|
||||
def _maybe_whatsapp_redirect(text: str, adapter_name: str | None) -> str:
|
||||
"""Append a redirect hint for WhatsApp users so they discover the rich UX."""
|
||||
if adapter_name == "whatsapp":
|
||||
return text + _WHATSAPP_REDIRECT
|
||||
return text
|
||||
|
||||
|
||||
def _try_ralph_dispatch(text: str, adapter_name: str | None = None) -> str | None:
|
||||
"""Parse and dispatch Ralph commands. Returns response string or None if no match."""
|
||||
low = text.lower()
|
||||
first = low.split(None, 1)[0] if low else ""
|
||||
@@ -176,7 +192,10 @@ def _try_ralph_dispatch(text: str) -> str | None:
|
||||
if first in ("/p", "!propose"):
|
||||
parts = text.split(None, 2)
|
||||
if len(parts) < 3:
|
||||
return "Folosire: /p <slug> <descriere>\nEx: /p roa2web Homepage redesign cu hero section"
|
||||
return _maybe_whatsapp_redirect(
|
||||
"Folosire: /p <slug> <descriere>\nEx: /p roa2web Homepage redesign cu hero section",
|
||||
adapter_name,
|
||||
)
|
||||
return _ralph_propose(parts[1].strip(), parts[2].strip())
|
||||
|
||||
if first in ("/a", "!approve"):
|
||||
@@ -189,7 +208,7 @@ def _try_ralph_dispatch(text: str) -> str | None:
|
||||
if first in ("/l", "!status"):
|
||||
parts = text.split(None, 1)
|
||||
filter_slug = parts[1].strip().lower() if len(parts) > 1 else None
|
||||
return _ralph_status(filter_slug)
|
||||
return _maybe_whatsapp_redirect(_ralph_status(filter_slug), adapter_name)
|
||||
|
||||
if first in ("/k", "!stop"):
|
||||
parts = text.split(None, 1)
|
||||
|
||||
Reference in New Issue
Block a user