refactor(gateway): shared exec-approval/picker formatting cores in base adapter

- base._format_exec_approval(command, description, smart_denied): shared
  header/fence/reason/smart-deny assembly driven by _EA_* template attrs and
  an _ea_escape() hook; base._format_choice_page(options, page, per_page):
  shared pagination core returning (page_options, meta) incl. the
  ' (N-M of T)' page_info suffix; base._truncate_preview: the shared
  truncate-with-ellipsis idiom.
- telegram (HTML attrs + _html.escape hook), feishu (card markdown attrs),
  matrix (head-only; local reaction-legend tail) rewired; telegram's
  provider/model keyboard pagination and slash-confirm preview use the
  shared cores. All user-visible strings byte-identical (parity-tested).
- slack/discord/teams left untouched: their formatting interleaves
  platform-specific budget arithmetic (Slack 3000-char section budget
  subtraction, Discord mention-prefix + dual content/embed budgets, Teams
  adaptive-card blocks) beyond template params.
- tests/gateway/test_interactive_prompt_base.py covers the cores + parity.
This commit is contained in:
teknium1 2026-07-29 09:49:01 -07:00 committed by Teknium
parent 4fe5410d57
commit 1f45ff9e8a
5 changed files with 341 additions and 36 deletions

View file

@ -1999,6 +1999,13 @@ class FeishuAdapter(BasePlatformAdapter):
logger.error("[Feishu] Failed to edit message %s: %s", message_id, exc, exc_info=True)
return SendResult(success=False, error=str(exc))
# Template attrs for the shared _format_exec_approval core. The card
# header carries the title, so the text core starts at the code fence.
_EA_HEADER = ""
_EA_REASON_LABEL = "**Reason:** "
_EA_SMART_DENY_LINE = "\n\n**Smart DENY:** owner override applies to this one operation only."
_EA_CMD_BUDGET = 3000
async def send_exec_approval(
self, chat_id: str, command: str, session_key: str,
description: str = "dangerous command",
@ -2018,7 +2025,6 @@ class FeishuAdapter(BasePlatformAdapter):
try:
approval_id = next(self._approval_counter)
cmd_preview = command[:3000] + "..." if len(command) > 3000 else command
def _btn(label: str, action_name: str, btn_type: str = "default") -> dict:
return {
@ -2034,7 +2040,6 @@ class FeishuAdapter(BasePlatformAdapter):
if allow_permanent:
actions.append(_btn("✅ Always", "approve_always"))
actions.append(_btn("❌ Deny", "deny", "danger"))
scope_note = "\n\n**Smart DENY:** owner override applies to this one operation only." if smart_denied else ""
card = {
"config": {"wide_screen_mode": True},
"header": {
@ -2044,7 +2049,7 @@ class FeishuAdapter(BasePlatformAdapter):
"elements": [
{
"tag": "markdown",
"content": f"```\n{cmd_preview}\n```\n**Reason:** {description}{scope_note}",
"content": self._format_exec_approval(command, description, smart_denied),
},
{
"tag": "action",