hermes-feishu-card2
Independent third-party Feishu / Lark Card JSON 2.0 & CardKit v1 streaming gateway platform plugin for Hermes Agent (Manifest v2, plugin ID feishu-card2, registered platform feishu_card2).
This plugin uses only the public Hermes plugin APIs (register_platform, public register_hook events, gateway.platforms._shared, and gateway.session_context) with zero runtime overrides or patches to Hermes core.
Why feishu-card2 vs. the bundled feishu-platform
- CardKit v1 native typewriter streaming: Uses
POST /open-apis/cardkit/v1/cards,PUT .../content, andPATCH .../settingsover a persistent keep-alivehttpx.AsyncClientto stream Markdown segments smoothly and write a non-emptyconfig.summary.contenton close. - On-demand collapsible thinking & tool timeline: Creates the collapsible thinking/tool panel dynamically only when reasoning deltas (
on_stream_delta) or tool calls (pre_tool_call/post_tool_call) actually occur, isolated per turn viagateway.session_context.get_session_envandsurface. - Card JSON 2.0 budget guard & Markdown-aware rollover:
- Enforces
config.width_mode: "fill"(prevents230099caused by legacywide_screen_mode). - Converts table #6+ to aligned code blocks to respect Feishu's 5-table card limit (
11310). - Splits cards cleanly at Markdown boundaries (closing/reopening code fences) before exceeding 28 KB or 180 elements, with fallback to static Card 2.0 or plain text.
- Enforces
- Rich interactive card callbacks (
card.action.trigger): Synchronous (<3 s) card updates for approval prompts, Clarify single/multi-select and free-text forms, paginated model pickers, and custom button/form forwarding withgateway.approval_actorauthorization checks.
Quick Install & Setup
# Install from the Hermes Plugin Catalog (once listed)
hermes plugins install feishu-card2
# Or install directly from GitHub
hermes plugins install HateYouLittle/hermes-feishu-card2
# Configure FEISHU_CARD2_* credentials interactively
hermes gateway setup
Note: Disable the built-in
feishuplatform if you runfeishu_card2with the same Feishu/Lark bot credentials to avoid duplicate WebSocket listeners.
Configuration: language Setting (English-First)
User-facing cards, approval buttons, picker navigation, callback toasts, and hermes gateway setup prompts default to English (en).
To switch all user-facing copy to Simplified Chinese (zh), set:
hermes config set plugins.entries.feishu-card2.settings.language zh
Supported values:
en(default; locales such asen-USnormalize toen)zh(locales such aszh-CN/zh_CNnormalize tozh; unrecognized values fall back toen)
Security & Behavior Disclosure
- External network connections: Establishes a background WebSocket long connection (
lark-oapi) and persistent HTTPS REST connections (httpx.AsyncClient) toopen.feishu.cn(oropen.larksuite.com, or a user-configured HTTPS domain) for bot probing, CardKit v1 streaming, IM messaging, interactive callbacks, and inbound/outbound media transfers. - Credentials & access control: Reads
FEISHU_CARD2_APP_ID,FEISHU_CARD2_APP_SECRET, and optionalFEISHU_CARD2_*settings exclusively via Hermes's profile-scoped config/secret helpers (extra_or_secret), never directly from.envfiles or other tools' credential stores. - File & media access: Downloads inbound Feishu images/files/audio into Hermes's temp/media cache directory, uploads explicit
MEDIA:/absolute/path/to/fileattachments referenced in agent replies, and fetches outbound image URLs through Hermes's SSRF-checked HTTP client (platform_http_client). - Telemetry & updates: Zero telemetry or usage reporting; no self-updating code; no runtime monkey-patching of Hermes core.
中文文档
Hermes Agent 的独立第三方 飞书 / Lark Card JSON 2.0 & CardKit v1 流式渠道插件(Manifest v2,插件 ID feishu-card2,注册平台名 feishu_card2)。
本插件完全遵循 Hermes 公开插件 API(plugin_api.json 白名单),无需修改 Hermes 核心源码即可安装启用。
核心特性
- CardKit v1 原生流式打字机卡片:基于
POST /open-apis/cardkit/v1/cards+PUT .../content+PATCH .../settings,按节流窗口刷新全量分段正文,自动删除占位节点,关闭流式时保证写入summary.content(防99992402)。 - 按需思考与工具折叠面板:默认不渲染空
thinking_panel,仅当实际收到on_stream_delta(delta_type="reasoning")或pre_tool_call/post_tool_call时动态POST .../elements插入折叠面板,并通过gateway.session_context.get_session_env+surface严格隔离跨平台串台。 - Card JSON 2.0 预算保护与自动拆卡:
- 统一使用
config.width_mode: "fill"(杜绝wide_screen_mode引发230099)。 - 表格数超过 5 张自动降级第 6 张及以后为对齐代码块(防
11310)。 - 单卡超 28 KB 或 180 元素 时按 Markdown 边界拆卡(自动闭合/重开代码块 fence 并更新
segment_start_offset),不可恢复时三级降级到静态 Card 2.0 或纯文本。
- 统一使用
- 完整交互卡片(3 秒内同步替换):
- 高危命令审批(
允许一次/本会话允许/始终允许/拒绝)。 - Clarify 单选、自定义文本追问与多选表单(顶层
form)。 - 分页模型选择器与通用选项选择器。
- 自定义 Card 2.0 按钮与
form_value表单转发(去前导/防命令注入,合法使用open_message_id锚点)。
- 高危命令审批(
- 多模态与 Cron 独立投递:支持入站图片/富文本/文件/语音下载缓存、SSRF 安全外链图片拉取(
platform_http_client)、以及standalone_sendCron Card 2.0 卡片投递。
模块结构
plugin.yaml/pyproject.toml:Manifest v2 声明与依赖上限声明(lark-oapi>=1.6.8,<2)__init__.py:轻量register(ctx)入口(无顶层 SDK 重导入)config.py:接入凭据(extra_or_secret)与config_schema展示开关分离解析transport.py:lark-oapi异步 REST 封装、/open-apis/bot/v3/info探针与后台线程 WebSocket 长连接adapter.py:FeishuCard2Adapter(收发、群@mention过滤、话题锚定、原生流式、交互卡片与媒体方法)card_budget.py:Schema 2.0 校验、代码块清洗、5 表格上限降级、28 KB / 180 元素预算与 Markdown-aware 拆卡card_builder.py:流式卡、思考工具折叠块、静态/Cron 卡、审批/Clarify/模型选择器模板card_stream.py:单卡asyncio.Lock、单调sequence、10 QPS 令牌桶、分段游标拆卡与错误码自愈turn_registry.py:基于get_session_env与surface的 Hook ↔ 流式会话隔离关联表card_actions.py:card.action.trigger3 秒同步响应与gateway.approval_actor越权拦截media.py:入站/出站媒体上传下载standalone.py:Cron /hermes send独立 Card 2.0 投递器setup_wizard.py:hermes gateway setup交互式配置向导scripts/feishu_smoke.py:离线 Schema 检验(--dry-run)与真实群聊冒烟脚本
飞书开放平台准备
- 在飞书开放平台(或 Lark)创建企业自建应用,启用机器人能力。
- 建议开通应用权限:
im:message、im:message:send_as_bot、im:message:readonly、im:message.group_at_msg:readonly、im:message.p2p_msg:readonlyim:resource(收发图片/文件/语音)im:chat:readonly(查询群名称/类型)cardkit:card:write、cardkit:card:read(CardKit v1 流式卡片必需)
- 在「事件与回调」中选择 使用长连接接收事件(WebSocket):
- 订阅事件:
im.message.receive_v1 - 订阅回调:
card.action.trigger
- 订阅事件:
- 发布应用版本使权限与事件订阅生效。
安装与配置
1. 运行交互配置向导
hermes gateway setup
选择 Feishu Card 2.0 (feishu_card2) 后依次输入:
FEISHU_CARD2_APP_ID/FEISHU_CARD2_APP_SECRETFEISHU_CARD2_DOMAIN(feishu或lark)FEISHU_CARD2_ALLOWED_USERS/FEISHU_CARD2_ALLOW_ALL_USERS/FEISHU_CARD2_GROUP_ALLOWED_CHATSFEISHU_CARD2_HOME_CHANNEL(用于hermes cron run与hermes send --deliver feishu_card2)
2. 调整插件卡片开关(config_schema)
hermes config set plugins.entries.feishu-card2.settings.streaming_enabled true
hermes config set plugins.entries.feishu-card2.settings.show_thinking true
hermes config set plugins.entries.feishu-card2.settings.show_tool_timeline true
hermes config set plugins.entries.feishu-card2.settings.throttle_ms 200
hermes config set plugins.entries.feishu-card2.settings.require_mention_in_group true
hermes config set plugins.entries.feishu-card2.settings.language zh # 可选:"en"(默认)或 "zh"(简体中文)
若要在思考折叠区中实时接收模型推理增量,请确认宿主配置开启:
hermes config set plugins.stream_reasoning_deltas true
开发测试与冒烟验证
# 插件目录静态规范与公开 API 白名单检查
hermes plugins validate .
hermes plugins doctor . --ci
# 离线单元测试
hermes --run-module unittest discover -s tests -p "test_*.py" -v
# 离线 Schema / 预算 / 拆卡自检(无需凭据)
python scripts/feishu_smoke.py --dry-run
# 真实飞书测试群端到端冒烟
FEISHU_E2E_APP_ID=cli_xxx \
FEISHU_E2E_APP_SECRET=xxx \
FEISHU_E2E_CHAT_ID=oc_xxx \
python scripts/feishu_smoke.py --scenario all
常见飞书错误码排查
| 错误码 | 原因说明 | 插件内建处理 / 排查建议 |
|---|---|---|
230099 | Card 2.0 中出现了旧版 1.0 wide_screen_mode | card_budget.sanitize_card_schema2 自动清理并强制 width_mode: "fill" |
11310 | 单张卡片内 Markdown 表格超过 5 个 | 自动保留前 5 个表格,第 6 个起转为对齐代码块 |
200860 | 单卡请求体超过 30 KB 平台硬上限 | 按 28 KB 软上限在 Markdown 边界触发分段拆卡(ROLLOVER) |
200850 | CardKit 流式模式超时自动关闭 | 自动尝试 PATCH /settings 重开流式,失败则封存旧卡并新开续答卡 |
200810 | 应用未开启 cardkit:card:write 或被限流 | 自动降级为静态 Card 2.0 或纯文本发送;请核对开放平台权限 |
300317 | 并发更新导致 sequence 乱序/重复 | 单卡 asyncio.Lock 串行写 + 冲突自动顺延重试 |
99992402 | 关流时 summary.content 为空或字段校验失败 | build_settings_payload 保证始终写入非空摘要 |
9499 | DELETE .../elements/:id 缺少请求体 sequence | card_stream._delete_element_safe 强制将 sequence 置于 JSON 请求体 |
99992354 | 回复锚点传入了非法 reply_to message_id | open_message_id 为空时不设回复锚点,直接走 send_message |
README from the reviewed commit b7a0e0e; it updates when the author re-pins.

HateYouLittle