#2772·cli

feat(im): add --output / --output-dir to +chat-messages-list (parity with base +record-list / minutes +detail)

Author: qiubai12Created Sep 24, 2026Updated Sep 28, 2026
Labelsenhancementdomain/basedomain/imdomain/minutesdomain/core

Is your feature request related to a problem?

AI agents (using the official agent skills, npx skills add larksuite/cli) increasingly drive lark-cli for read-only bulk extraction, e.g. building personal knowledge bases / RAG corpora from chat history. With --page-all, im +chat-messages-list can return thousands of messages in one run — but it only prints to stdout. To persist results, the full payload must flow through the agent's context window, which forces truncation/sampling of large chats and spreads extraction across many runs. Additionally, many agent sandboxes deliberately block shell redirection (>, tee) for security, so "just redirect stdout" is not always available.

Describe the solution you'd like

--output <path>: write the exact JSON envelope (identical to stdout, honoring --format) to a file. Optional --output-dir for per-chat files named by chat_id. No behavior change when the flag is absent.

Proposed invocation:

bash
lark-cli im +chat-messages-list --chat-id oc_xxx --start 2025-01-01 --order asc \
  --page-size 50 --no-reactions --page-all --page-limit 1000 --output ./raw/im/oc_xxx.json

Nice-to-have: emit a one-line manifest (path, bytes, page count, has_more) alongside the file, mirroring the ndjson artifact pattern already used by base +record-list.

Describe alternatives you've considered

base +record-list --output ./records.ndjson already solves exactly this for Base records — its help text even recommends it "to keep long user data out of model context". minutes +detail likewise has --output-dir. This request is mainly about bringing im +chat-messages-list (and ideally other paginated read commands) to parity. Piping stdout through filters works, but still routes the full payload through the agent's context.

Additional context

中文摘要:im +chat-messages-list 配合 --page-all 单次可返回数千条消息,但只能输出到 stdout。AI Agent 场景(官方 agent skills)需要把完整结果落盘:受上下文窗口限制只能截断/分批抽取,且不少 Agent 沙箱出于安全禁止 shell 重定向。base +record-list --output 与 minutes +detail --output-dir 已解决同类问题(帮助文档明确建议用文件输出避免长数据经过模型上下文),希望 IM 消息命令对齐补齐,供所有分页读取类命令统一考虑。