---
name: lark-group-summary-pdf
description: Install and configure the Feishu/Lark CLI, obtain the broadest available user authorization scopes, summarize Feishu/Lark group chat messages including downloaded images/files, generate a Chinese PDF report, and send the PDF or a Drive fallback link back to the group. Use when the user asks to connect Codex to Feishu/Lark groups, grant all possible permissions, summarize group chat content, create a PDF group summary, or send the summary back into a Feishu/Lark chat.
---

# Lark Group Summary PDF

## Core Workflow

Use the bundled script `scripts/lark_group_summary_pdf.py` for repeatable CLI work. PDF production uses the fully vendored Kami skill at `vendor/kami/` by default: parchment canvas, ink-blue accent, serif-led hierarchy, and Chinese-first typography. Prefer the Codex bundled Python when available because it usually includes PDF dependencies:

```bash
PY=/Users/macbook/.cache/codex-runtimes/codex-primary-runtime/dependencies/python/bin/python3
test -x "$PY" || PY=python3
```

The agent still owns judgment: read command output, inspect downloaded images, rewrite the summary JSON into a clean human summary, and handle authorization prompts.

## Kami PDF Backend

Kami is copied into this skill under `vendor/kami/`, including its `SKILL.md`, `CHEATSHEET.md`, references, scripts, templates, assets, and package artifacts. Bundled font files are intentionally removed; PDF rendering uses native system fallback fonts such as Songti SC, STSong, Hiragino Mincho ProN, and available Noto/Source Han fonts.

When making the PDF:

- Read `vendor/kami/SKILL.md` and `vendor/kami/CHEATSHEET.md` if design decisions are needed beyond the default renderer.
- Treat the group summary as a Chinese one-pager / concise report.
- Apply Kami rules: parchment `#f5f4ed`, ink-blue `#1B365D`, serif-led hierarchy, native serif fallback fonts, no placeholder text, no invented facts.
- Insert `assets/header-logo.png` at the fixed top-right header position in generated PDFs. Override with `summary_json.header_logo` only when the user explicitly provides a different logo path.
- Use `--engine auto` by default. This tries Kami/WeasyPrint first, then falls back to ReportLab if WeasyPrint is missing.
- Use `--engine kami` only when a Kami PDF is required and failure is preferable to fallback.
- Do not update the vendored Kami copy unless the user explicitly asks to refresh it.

1. Install and configure the CLI:
   ```bash
   "$PY" /Users/macbook/.codex/skills/lark-group-summary-pdf/scripts/lark_group_summary_pdf.py install-deps
   "$PY" /Users/macbook/.codex/skills/lark-group-summary-pdf/scripts/lark_group_summary_pdf.py setup
   ```
   `install-deps` installs/checks `lark-cli`, `weasyprint`, `reportlab`, `pypdf`, `PyYAML`, `pillow`, and Poppler (`pdftoppm`, via Homebrew on macOS when available). If `setup` prints a QR code or verification URL, show the user the URL and wait for them to finish in Feishu/Lark.

2. Request the broadest available authorization:
   ```bash
   "$PY" /Users/macbook/.codex/skills/lark-group-summary-pdf/scripts/lark_group_summary_pdf.py auth-all
   ```
   Select all domains and "全部权限" when prompted. Feishu/Lark may still refuse scopes due to app, tenant, or admin policy. Do not claim every possible scope was granted until `lark-cli auth status` confirms it.

3. Locate the target group:
   ```bash
   lark-cli im +chat-list --page-size 50
   lark-cli im +chat-search --query "<group name>" --page-size 20
   ```
   Prefer `chat_id` (`oc_...`) when known.

4. Collect messages and resources. Default scope is both today and the last seven days:
   ```bash
   "$PY" /Users/macbook/.codex/skills/lark-group-summary-pdf/scripts/lark_group_summary_pdf.py collect --chat-id oc_xxx --page-size 50 --period both --out work/lark-summary
   ```
   The script writes `messages.today.json`, `messages.7d.json`, and a deduplicated merged `messages.json`; it also downloads image/file resources when the CLI can access them. Use `--period today`, `--period 7d`, or `--period custom --start ... --end ...` only when the user requests a different window.

5. Inspect downloaded images/files when relevant. Use `view_image` for images. Summarize what is actually visible; do not invent unreadable text.

6. Write a compact summary JSON:
   ```json
   {
     "title": "飞书群消息摘要",
     "chat_name": "群名",
     "range": "今日与近七日可见消息",
     "overview": "一段总述。",
     "key_points": ["要点 1", "要点 2"],
     "todos": ["待办 1"],
     "timeline": ["09:06 - 系统消息：创建群聊。"],
     "image_notes": [
       {
         "path": "/absolute/path/to/image.jpg",
         "summary": "图片内容摘要。"
       }
     ],
     "footer": "本摘要仅覆盖当前授权可见消息。"
   }
   ```
   If using `draft-summary`, treat the output as a scaffold only. Replace raw message payloads, URLs, XML snippets, and placeholder image notes with a readable summary before creating the PDF.

7. Generate and send the PDF:
   ```bash
   "$PY" /Users/macbook/.codex/skills/lark-group-summary-pdf/scripts/lark_group_summary_pdf.py send-summary --chat-id oc_xxx --summary-json work/lark-summary/summary.json --pdf outputs/lark_group_summary.pdf --engine auto
   ```
   The script first tries to send the PDF as an IM file. If `im:resource:upload` or a chat membership rule blocks file sending, it uploads to Drive and sends the link as text.

   To preview without sending:
   ```bash
   "$PY" /Users/macbook/.codex/skills/lark-group-summary-pdf/scripts/lark_group_summary_pdf.py build-pdf --summary-json work/lark-summary/summary.json --pdf outputs/lark_group_summary.pdf --engine auto --render-check
   ```

## Authorization Notes

Read `references/scopes.md` when diagnosing missing scopes or explaining why an operation is blocked.

Important behaviors:

- `im:message.send_as_user` is needed to send text as the user.
- `im:resource:upload` plus `im:resource` may be needed to send a local PDF as an IM file.
- `drive:file:upload` and `drive:drive.metadata:readonly` allow the Drive fallback.
- Bot identity can upload/send only if the bot is in the target chat.
- User identity can read/send only within the user's authorized and visible resources.

## Quality Bar

Generate a PDF that is legible in Chinese, includes enough context to stand alone, and clearly separates overview, key points, todos, timeline, and image/file notes. Prefer Kami output. Use `build-pdf --render-check` or `send-summary --render-check` when `pdftoppm` is available before sending.
