Skip to content

feat(im): complete audio/post rendering and add opt-in --download-resources#1245

Merged
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
sammi-bytedance:feat/im-info-completion
Jun 10, 2026
Merged

feat(im): complete audio/post rendering and add opt-in --download-resources#1245
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
sammi-bytedance:feat/im-info-completion

Conversation

@sammi-bytedance

@sammi-bytedance sammi-bytedance commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Complete IM message rendering (audio file_key + post emotion/text.style/md) and add an opt-in --download-resources flag that auto-downloads message resources into ./lark-im-resources/. Default behavior and request count are unchanged when the flag is off.

Changes

  • convertlib field completion: audio<audio key="..." duration="Xs"/> (falls back to [Voice: Xs]/[Voice]); post renders emotion:emoji_type:, applies text.style (bold/italic/underline/lineThrough), passes through md; sticker unchanged.
  • New --download-resources flag on +chat-messages-list, +messages-mget, +threads-messages-list: extracts downloadable resource refs (image/file/audio/video/media + post-embedded; sticker excluded) during formatting, then a bounded-concurrency (=3) engine downloads each distinct (message_id, file_key) once into ./lark-im-resources/, filling back local_path/size_bytes. Single-resource failures are isolated (error:true + stderr warning).
  • Path safety reuses existing normalizeDownloadOutputPath + ResolveSavePath (rejects separators / .. / absolute paths).
  • New files: shortcuts/im/convert_lib/resource_extract.go, resource_download.go, shortcuts/im/im_download_resources.go. Back-compat gated wrappers added in content_convert.go / thread.go.
  • Docs: updated skills/lark-im (SKILL.md, message-enrichment + 3 command references), CHANGELOG.md.

Test Plan

  • Unit tests pass (go test ./shortcuts/im/convert_lib/ ./shortcuts/im/, incl. -race on the download engine)
  • Manual local verification confirms the lark-cli im +chat-messages-list dry-run flow works as expected (go test ./tests/cli_e2e/im/ -run TestIM_DownloadResourcesDryRun); golangci-lint v2.1.6 0 issues, gofmt/go vet clean

Summary by CodeRabbit

  • New Features

    • Added optional --download-resources flag to +chat-messages-list, +messages-mget, and +threads-messages-list to opt into downloading eligible message resources (images/files/audio/video, excluding stickers) into ./lark-im-resources/ and attach a per-message resources array with local_path and size_bytes. Downloads are off by default, deduplicated by message ID+file key, bounded to 3 concurrent fetches, and isolate per-resource failures.
  • Documentation

    • Updated command references and Skill docs to describe the new flag, dry-run behavior, and resource-enrichment contract.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds opt-in IM message resource extraction and bounded-concurrency downloads, threads resource refs through formatting and thread expansion, wires a --download-resources CLI flag into three shortcuts with safe local paths, and includes tests and docs; also updates post styling and audio rendering tests.

Changes

IM resource extraction and download flow

Layer / File(s) Summary
Extract downloadable resource references
shortcuts/im/convert_lib/resource_extract.go, shortcuts/im/convert_lib/resource_extract_test.go
Introduces ResourceRef and ExtractResourceRefs that dispatch by msg type, parse post bodies, and recurse merge_forward sub-items; unit tests cover expected and invalid shapes.
Attach resources during message and thread formatting
shortcuts/im/convert_lib/content_convert.go, shortcuts/im/convert_lib/thread.go, shortcuts/im/convert_lib/content_media_misc_test.go, shortcuts/im/convert_lib/thread_test.go
Adds FormatMessageItemWithMergePrefetchOpts(extractResources bool), threads the flag into reply expansion via ExpandThreadRepliesWithResources, and conditionally attaches resources arrays to formatted messages; existing wrappers preserve backward compatibility with extractResources=false.
Download and fill resource metadata
shortcuts/im/convert_lib/resource_download.go, shortcuts/im/convert_lib/resource_download_test.go
Implements EnrichResourceDownloads to collect resources refs, deduplicate by (message_id, key), download each unique resource once (bounded concurrency = 3), fill local_path/size_bytes for successes, and mark only failing groups with error: true.
Wire downloads into IM shortcuts and safe paths
shortcuts/im/im_download_resources.go, shortcuts/im/im_chat_messages_list.go, shortcuts/im/im_messages_mget.go, shortcuts/im/im_threads_messages_list.go, shortcuts/im/im_resource_download_test.go, tests/cli_e2e/im/im_download_resources_dryrun_test.go, .gitignore
Adds --download-resources flag to three IM shortcuts, dry-run descriptions, resolveResourceDownloadPath safety checks under lark-im-resources/, execution wiring to call enrichMessageResourceDownloads when enabled, path-safety tests, and .gitignore entries.
Document resource download behavior
skills/lark-im/SKILL.md, skills/lark-im/references/*, skill-template/domains/im.md
Documents the opt-in --download-resources behavior, eligible resource types (excluding stickers), download destination (./lark-im-resources/), per-message resources metadata, deduplication, bounded concurrency, and per-resource failure isolation.

Message rendering updates

Layer / File(s) Summary
Apply post element styles in rendered text
shortcuts/im/convert_lib/text.go, shortcuts/im/convert_lib/text_test.go
Adds applyPostStyle to deterministically wrap text/links/mentions with markdown emphasis in fixed order; adds table-driven tests for style composition and passthrough.
Render audio file keys and keep sticker output unchanged
shortcuts/im/convert_lib/media.go, shortcuts/im/convert_lib/content_media_misc_test.go
Emits <audio key="..."/> when file_key exists and appends duration="...s" when present; preserves prior [Voice...] fallback and adds tests for file_key/duration combinations and sticker behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • larksuite/cli#536: Touches IM resource download path resolution used by this PR's download flow.

Suggested reviewers

  • YangJunzhou-01
  • jackie3927
  • MaxHuang22

Poem

🐰 I nibble bytes and follow threads,
I fetch the images, audio, and meds.
Batches bounded, paths kept neat,
Resources saved — a tidy feat.
Hop, download, safely spread.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.10% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: completing audio/post rendering and adding an opt-in --download-resources flag, which are the primary objectives of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description includes all major required template sections: a clear summary, comprehensive changes list, and test plan with verification checkboxes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added domain/im PR touches the im domain size/L Large or sensitive change across domains or core paths labels Jun 3, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shortcuts/im/convert_lib/resource_download.go`:
- Line 14: The inline comment containing "在地写盘" should be changed to English for
consistency—replace that phrase in the comment line "// the reactions
batch_query fan-out (4): each download is a GET +在地写盘, and" with a clear English
equivalent such as "write to local disk" (resulting comment: "// the reactions
batch_query fan-out (4): each download is a GET + write to local disk, and") so
the comment reads entirely in English.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3a188b41-3aa9-4b6d-a66c-86cf5ad396fd

📥 Commits

Reviewing files that changed from the base of the PR and between 85c7280 and c8a9a59.

📒 Files selected for processing (18)
  • .gitignore
  • shortcuts/im/convert_lib/content_convert.go
  • shortcuts/im/convert_lib/content_media_misc_test.go
  • shortcuts/im/convert_lib/media.go
  • shortcuts/im/convert_lib/resource_download.go
  • shortcuts/im/convert_lib/resource_download_test.go
  • shortcuts/im/convert_lib/resource_extract.go
  • shortcuts/im/convert_lib/resource_extract_test.go
  • shortcuts/im/convert_lib/text.go
  • shortcuts/im/convert_lib/text_test.go
  • shortcuts/im/convert_lib/thread.go
  • shortcuts/im/convert_lib/thread_test.go
  • shortcuts/im/im_chat_messages_list.go
  • shortcuts/im/im_download_resources.go
  • shortcuts/im/im_messages_mget.go
  • shortcuts/im/im_resource_download_test.go
  • shortcuts/im/im_threads_messages_list.go
  • tests/cli_e2e/im/im_download_resources_dryrun_test.go

Comment thread shortcuts/im/convert_lib/resource_download.go Outdated
@sammi-bytedance
sammi-bytedance force-pushed the feat/im-info-completion branch 6 times, most recently from d07320b to 9f67c35 Compare June 9, 2026 12:39
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.91837% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.99%. Comparing base (98173ae) to head (9d95d5d).
⚠️ Report is 70 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/im/convert_lib/resource_download.go 73.91% 14 Missing and 4 partials ⚠️
shortcuts/im/convert_lib/text.go 83.33% 6 Missing and 2 partials ⚠️
shortcuts/im/im_download_resources.go 20.00% 8 Missing ⚠️
shortcuts/im/convert_lib/resource_extract.go 91.04% 3 Missing and 3 partials ⚠️
shortcuts/im/im_chat_messages_list.go 0.00% 5 Missing and 1 partial ⚠️
shortcuts/im/im_messages_mget.go 0.00% 5 Missing and 1 partial ⚠️
shortcuts/im/im_threads_messages_list.go 0.00% 4 Missing and 1 partial ⚠️
shortcuts/im/im_messages_resources_download.go 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1245      +/-   ##
==========================================
+ Coverage   69.19%   71.99%   +2.80%     
==========================================
  Files         637      702      +65     
  Lines       59753    66502    +6749     
==========================================
+ Hits        41345    47880    +6535     
+ Misses      15067    14905     -162     
- Partials     3341     3717     +376     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@9d95d5d7e3dca1f8b35eb3f69329139ab57888e0

🧩 Skill update

npx skills add sammi-bytedance/larksuite-cli#feat/im-info-completion -y -g

@sammi-bytedance
sammi-bytedance force-pushed the feat/im-info-completion branch from c2343da to 4d1f9f0 Compare June 10, 2026 08:10
…ources

Block 1 — field completion: audio renders <audio key="..." duration="Xs"/>
(falls back to [Voice: Xs]/[Voice]); post renders emotion -> :emoji_type:,
applies text.style (bold/italic/underline/lineThrough), passes through md;
sticker unchanged.

Block 2 — opt-in --download-resources (default off) on +chat-messages-list,
+messages-mget, +threads-messages-list: extract downloadable resource refs
during formatting (image/file/audio/video/media + post-embedded; sticker
excluded; merge_forward sub-items carry the top-level container message_id,
since the resources endpoint rejects sub-item ids with "234003 File not in
msg" and can only fetch a forwarded resource through the container; thread
replies get their own block), then download each distinct (message_id,
file_key) once into ./lark-im-resources/ with bounded concurrency (3), filling
back local_path/size_bytes; single-resource failures are isolated (error:true +
stderr warning). Path safety reuses normalizeDownloadOutputPath +
ResolveSavePath.

Batch download keys each file on disk by its unique file_key basename and only
appends an extension (from the Content-Disposition filename or MIME type) —
it does NOT substitute the server's Content-Disposition filename. Otherwise two
resources whose servers return the same filename (e.g. download.bin) would
resolve to the same ./lark-im-resources/ path and clobber each other
concurrently. The friendly "adopt the server filename" behavior is kept only
for an explicit +messages-resources-download with no --output.

Resource ref extraction guards against self-referential / cyclic merge_forward
prefetch maps (a real API sub-item list can include the container's own id or a
back-pointing merge_forward) via a visited set, so extraction terminates instead
of overflowing the stack. The container message_id is threaded through nested
merge_forwards as the download owner.

Also: document the feature (including the im:message:readonly scope requirement)
in skills/lark-im — SKILL.md is generated from skill-template/domains/im.md
(edit the source), plus the hand-written message-enrichment + 3 command
references.

Change-Id: I3a71d7d1b193130f551aaa2ec180ac1500d59ac4
Meego: https://meego.larkoffice.com/5e96d7bff4e7c525510f9156/story/detail/7331555925
@sammi-bytedance
sammi-bytedance force-pushed the feat/im-info-completion branch from 4d1f9f0 to 9d95d5d Compare June 10, 2026 08:44
@YangJunzhou-01
YangJunzhou-01 merged commit 501bf53 into larksuite:main Jun 10, 2026
18 checks passed
luozhixiong01 added a commit that referenced this pull request Jun 16, 2026
Rebased onto main v1.0.54, which added IM content after this branch forked.
Fold main's new facts into the slimmed/gotcha-only form and fix drift:

- SKILL.md: compact the newly-merged chat.user_setting / chat.managers /
  chat.moderation API resources to the api_compact `action`(identity) form
  (consistent with the rest; regen-equivalent), and note the opt-in
  `--download-resources` flag on the three message-pulling shortcuts.
- chat-search: fix stale `--sort-by` -> `--sort`, add `--chat-modes`, and
  fold the "`--sort` is always descending" caution (#1302/#1317).
- chat-messages-list: note `--order` is the only sort axis (no field sort).
- messages-send: split @mention by message type; interactive cards are not
  normalized and need card-native `<at>` syntax (#1419).
- flag-cancel: document best-effort double-cancel (feed layer skipped with a
  stderr warning when chat type is undeterminable).
- feed-group-list-item / query-item: p2p cards omit chat_name; resolve via
  chats/batch_query -> p2p_target_id -> contact lookup.
- message-enrichment: add the `--download-resources` contract (merge_forward
  container-id 234003 trap, fail-silent isolation, no extra scope) (#1245).

Docs only; no Go/--help/Desc changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/im PR touches the im domain size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants