From 4acb51c270e387f03d065ffeebca8f0c00248dc2 Mon Sep 17 00:00:00 2001 From: nns <278048682+nurdotnet@users.noreply.github.com> Date: Sun, 26 Apr 2026 14:59:05 +0500 Subject: [PATCH] =?UTF-8?q?feat(bridge):=20/quiet=20=D0=B8=20/loud=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20PreToolUse=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B5=D1=81?= =?UTF-8?q?=D1=81-=D0=BB=D0=B5=D0=BD=D1=82=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /quiet → создаёт /tmp/cc-tg-quiet, pretool-hook сразу выходит, Stop hook продолжает работать (финальные ответы летят). - /loud → удаляет flag, прогресс-лента возобновляется. - /ping без изменений. На стенде bridge перезапущен, setWebhook 200. Co-Authored-By: Claude Opus 4.7 (1M context) --- deploy/telegram-bridge/bridge.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/deploy/telegram-bridge/bridge.py b/deploy/telegram-bridge/bridge.py index 1a3ac0e..fe3f588 100644 --- a/deploy/telegram-bridge/bridge.py +++ b/deploy/telegram-bridge/bridge.py @@ -92,6 +92,34 @@ async def cmd_ping(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text(f"pong — webhook mode, tmux session «{TMUX_SESSION}»") +QUIET_FLAG = "/tmp/cc-tg-quiet" + + +async def cmd_quiet(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Заткнуть PreToolUse прогресс-ленту (Stop hook продолжает работать).""" + if not _allowed(update, context): + return + try: + open(QUIET_FLAG, "w").close() + await update.message.reply_text("🔕 Прогресс-лента отключена. Включить — /loud") + except Exception as exc: # noqa: BLE001 + await update.message.reply_text(f"⚠️ {exc}") + + +async def cmd_loud(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Включить обратно PreToolUse прогресс-ленту.""" + if not _allowed(update, context): + return + try: + os.unlink(QUIET_FLAG) + except FileNotFoundError: + pass + except Exception as exc: # noqa: BLE001 + await update.message.reply_text(f"⚠️ {exc}") + return + await update.message.reply_text("🔔 Прогресс-лента включена.") + + async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: if not _allowed(update, context): return @@ -130,6 +158,8 @@ def main() -> int: application = ApplicationBuilder().token(token).build() application.bot_data["chat_id"] = chat_id application.add_handler(CommandHandler("ping", cmd_ping)) + application.add_handler(CommandHandler("quiet", cmd_quiet)) + application.add_handler(CommandHandler("loud", cmd_loud)) application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message)) logger.info("starting webhook listener on %s:%d → %s", LISTEN_HOST, LISTEN_PORT, webhook_url)