Repository navigation
refactor(bot): one message pipeline for all chat platforms (code-shape 2/5) - #19
Merged
Merged
Conversation
emanuilo
force-pushed
the
refactor/2-chat-pipeline
branch
from
November 22, 2026 16:25
d3ae754 to
1d6d9c2
Compare
Drives each platform at its SDK boundary with fakes (agent, OpenAI, web page, chat SDKs) and pins what the agent receives and what the user sees: plain text, a link, a photo with a captioned link, a failed and a working voice note, a stranger, /new, a reminder, long replies, found images, plus the per-platform quirks (empty allowlists, self-chat only, download errors). Written against the current layout so the coming refactor of the three handlers into one pipeline can prove it changes nothing: only the "where the code lives" block at the top may change.
…ient.py - OpenAIClient offers the three calls Memclaw makes: embed() (index.py), transcribe() (the three chat handlers' Whisper call) and chat() (link summaries). Same models, parameters and errors as before. - The `memclaw doctor` probe (was openai_health.py) lives there too and uses those calls; printing its report moved to setup.py, next to the wizard that also shows it. - New guard: an import-linter contract (and the kit's banned_api) lets only memclaw.openai_client import `openai`. It sits in its own layer, below index and above config. The parity test passes unchanged except for how it hands the bots their OpenAI client.
Each chat app re-implemented the same steps: voice to text, link summaries, the prompts, the agent call, reminder delivery. Now: - bot/inbound.py does those once, for every platform. The prompt texts and the transcription-failed reply are written there once (they were copied 9 and 3 times). - bot/telegram.py, slack.py and whatsapp.py (were handlers.py, slack_handlers.py, whatsapp_handlers.py) only do their app's I/O: receive, download, send, plus Telegram's /model and /effort menus. Each has a run(config) with what cli.py's _run_<platform> launchers did. - bot/__init__.py has the PLATFORMS registry. `memclaw` starts a platform through it and the setup wizard lists the platforms from it, so a new platform is one module plus one registry line. A platform's module (and its SDK) is still only imported when that platform starts. - bot/commands.py: the /model and /effort replies (Telegram adds buttons). - bot/links.py was link_processor.py. Guards: only memclaw.bot imports the platform modules; only the platform modules import their chat SDK; the independence contract names the new modules. The setup layer now sits above bot (it reads the registry). Behaviour is unchanged, including where the platforms differ (access rules, reply formats, media handling): the parity test passes with only its module paths updated, and `memclaw` prints the same start-up errors.
emanuilo
force-pushed
the
refactor/2-chat-pipeline
branch
from
November 22, 2026 19:21
1d6d9c2 to
0ffa834
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stack 2/5 of the code-shape restructuring (base: #18). Telegram, Slack and WhatsApp share one message pipeline; OpenAI is reached through one adapter.
Adding a platform: one file + one
PLATFORMSline (+ its settings inconfig.py, + its module name in three import contracts).New guards:
openaiprotected tomemclaw.openai_client(import-linter + kit banned API); chat-platform contracts updated for the renamed modules;setupnow sits abovebot(the wizard readsPLATFORMS).Evidence
tests/bot/test_parity.py(47 cases): the same scenarios through all three platforms — text, link, unfetchable page, photo with/without caption, voice ok/failed, stranger,/new, reminder, long reply, found images, plus each platform's quirks. Asserts the exact prompt the agent gets, the exact Whisper/summary calls, and what the user sees.memclawold vs new with a temp HOME:--help, missing-token errors for every platform,status, terminal fallback print identically.openaiimporters 7 → 1; baseline 63 → 39;cli.py424 → 320 lines; Slack/WhatsApp files 358/321 → 279/246.pytest: 501 passed, 20 skipped (was 451).ruff,lint-imports,code-shape checkclean.Merge Danger
Door: two-way
Blast Radius: chat platforms
memclaw.bot.handlers→memclaw.bot.telegram,MessageHandlers→TelegramBot,SlackHandlers→SlackBot,memclaw.openai_healthremoved).neonize.*has no type hints (ignore_missing_imports).🤖 Generated with Claude Code