Skip to content

docs: trim lark-im skill doc token cost (~40% across 3 files)#1554

Open
zhangheng023 wants to merge 1 commit into
mainfrom
docs/opt-lark-im-token-trim
Open

docs: trim lark-im skill doc token cost (~40% across 3 files)#1554
zhangheng023 wants to merge 1 commit into
mainfrom
docs/opt-lark-im-token-trim

Conversation

@zhangheng023

@zhangheng023 zhangheng023 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

The lark-im skill docs carried a large amount of runtime-recoverable and repeated content that inflated the agent's context cost on every invocation. This PR trims the lark-im doc surface by ~4455 tiktoken (cl100k) tokens — about 40% across three files — without removing any capability or guardrail. The change was driven and validated by the opt-workflow eval harness.

Changes

  • skills/lark-im/SKILL.md: fold the per-method API Resources identity index and the full permission-scope table into a short Native-API schema pointer (resident 4960 -> 2986 tok, -40%, loaded on every invocation); migrate the reactions and feed-groups entry points into the Shortcuts table so those references stay runtime-discoverable.
  • skills/lark-im/references/lark-im-messages-send.md: consolidate the content-flag selection rule (previously repeated across 4 sections) into one table; compress the all-media-form Commands enumeration and the --help-mirroring Parameters/Notes into pointers (3869 -> 1799 tok, -53%).
  • skills/lark-im/references/lark-im-chat-create.md: dedup the Commands <-> Usage Scenarios overlap; compress the --help-mirroring Common Errors into pointers (2125 -> 1714 tok, -19%).

Removed content is runtime-recoverable (schema / --help / deterministic CLI validation errors). All routing, identity/scope mapping, flag mutual-exclusivity rules, safety constraints, and GOTCHA lines were preserved (grep-confirmed).

Test Plan

  • skipped: make unit-test — docs-only change, no Go code touched
  • skipped: validate — docs-only, no shortcut / CLI behavior changed
  • opt-workflow sealed eval passed: skillave 3/3 at K=5, effect guard not regressed (sealed-eval verdict PASS)
  • each of the 3 changes passed an independent adversarial review (opt-reviewer): no semantic regression, no reward-hacking, single-root-cause
  • manual verification: static token measurement (tiktoken cl100k) confirms -4455 tok / -40.7% across the 3 files; all identity/scope/routing/safety/guardrail lines grep-confirmed present in the post-change files

Note: this eval set (3 cases) is dominated by sandbox user-auth noise, so the runtime per-task token delta could not be cleanly isolated. The durable token saving here is the static doc-surface reduction, independently verified by review + token count; the eval's role was to confirm the effect guard is not regressed.

Related Issues

N/A

Summary by CodeRabbit

  • Documentation
    • Streamlined Native API guidance with clearer invocation patterns and scope requirements.
    • Consolidated and simplified command examples for chat creation and messaging.
    • Reorganized prerequisites and parameters for better clarity.
    • Added new section demonstrating group creation followed by welcome message workflow.
    • Introduced content flag selection guidance with explicit mutual exclusivity rules.
    • Revised troubleshooting and error handling documentation.

Reduce the lark-im skill doc surface by ~4455 tiktoken (cl100k) tokens
across three files, with no capability or guardrail removed:

- SKILL.md: fold the per-method API Resources identity index and the full
  permission-scope table into a short Native-API schema pointer
  (resident 4960->2986 tok, -40%, loaded every invocation); migrate the
  reactions and feed-groups entry points into the Shortcuts table so those
  references stay runtime-discoverable.
- references/lark-im-messages-send.md: consolidate the content-flag
  selection rule (previously repeated 4x) into one table; compress the
  all-media-form Commands enumeration and the --help-mirroring
  Parameters/Notes into pointers (3869->1799 tok, -53%).
- references/lark-im-chat-create.md: dedup the Commands<->Usage Scenarios
  overlap; compress the --help-mirroring Common Errors into pointers
  (2125->1714 tok, -19%).

Removed content is runtime-recoverable (schema / --help / deterministic
CLI validation errors). All routing, identity/scope mapping, flag
mutual-exclusivity rules, safety constraints, and GOTCHA lines preserved.

Validated via the opt-workflow eval harness: each change passed an
independent adversarial review (no semantic regression, no reward-hacking)
and the combined result passed a K=5 sealed evaluation with the effect
guard not regressing.
@zhangheng023 zhangheng023 added documentation Improvements or additions to documentation domain/im PR touches the im domain size/S Low-risk docs, CI, test, or chore only changes labels Jun 23, 2026
@github-actions github-actions Bot added size/L Large or sensitive change across domains or core paths and removed size/S Low-risk docs, CI, test, or chore only changes labels Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Three documentation files in the skills/lark-im directory are revised: SKILL.md condenses the native API section to enumerate reactions.* and feed.groups.* with a generic two-step invocation pattern; lark-im-chat-create.md streamlines command examples and rewrites troubleshooting; lark-im-messages-send.md substantially restructures identity, content-flag, and Markdown guidance.

Changes

Lark IM Documentation Revisions

Layer / File(s) Summary
SKILL.md native API section rewrite
skills/lark-im/SKILL.md
Removes the long resource listing and scope table; introduces a short block naming reactions.* and feed.groups.*, a generic lark-cli schema + lark-cli im invocation template, and a MUST requirement to run schema first with console_url error-handling reference.
chat-create examples and troubleshooting
skills/lark-im/references/lark-im-chat-create.md
Condenses Commands to representative private/public/topic/invite/bot-identity examples; adds a create-then-send-welcome composite example using --format json and jq; rewrites the troubleshooting section to a validation note plus a single permission-denied (99991672) table entry.
messages-send prerequisite, content, and markdown guidance
skills/lark-im/references/lark-im-messages-send.md
Updates prerequisite pointer to ../lark-shared/SKILL.md; rewrites the page body with --as identity/scope behavior, a content-flag selection table with mutual exclusivity rules, --markdown gotchas (forced msg_type=post, heading rewriting, remote URL auto-upload with fallback), ANSI-C quoting, consolidated examples, msg_type payload reference, @Mention normalization differences, and return value.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • larksuite/cli#180: Introduced --as user/--as bot identity split and DoAPIAsBot for +messages-send, directly related to the identity and scope documentation rewritten in this PR.
  • larksuite/cli#1237: Updated the same lark-im-messages-send.md "Choose The Right Content Flag" section and --markdown vs --text default-selection rules that are rewritten here.

Suggested labels

size/M

Suggested reviewers

  • YangJunzhou-01
  • fangshuyu-768

Poem

🐇 Hop, hop — the docs are trim!
Old tables pruned on every whim,
schema first, then native call,
Markdown gotchas — noted all.
Fewer lines, but clearer still —
This bunny's had its documentation fill! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: trimming documentation token cost across 3 lark-im files by ~40%.
Description check ✅ Passed The description is comprehensive, covering summary, specific changes per file, test plan with validation details, and related issues as per template requirements.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/opt-lark-im-token-trim

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.

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.03%. Comparing base (736b131) to head (bffdd6f).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1554      +/-   ##
==========================================
+ Coverage   73.97%   74.03%   +0.06%     
==========================================
  Files         787      787              
  Lines       76293    76328      +35     
==========================================
+ Hits        56436    56509      +73     
+ Misses      15625    15572      -53     
- Partials     4232     4247      +15     

☔ 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

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#docs/opt-lark-im-token-trim -y -g

@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 `@skills/lark-im/SKILL.md`:
- Around line 113-114: The entries for `reactions.*` and `feed.groups.*` are
currently placed in the Shortcuts section (lines 113-114) but they use raw API
pattern with dot notation rather than shortcut wrappers with the plus prefix.
Move both of these entries from their current location in the Shortcuts table to
the "Native API (beyond shortcuts)" section (lines 116-125) where they belong
alongside other raw API entries like `chats.*` and `chat.members.*`, so users
correctly understand they require the schema-first pattern and are not
high-level shortcut abstractions.
🪄 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: 857ed24e-0525-4e18-9e31-46a88ddd863e

📥 Commits

Reviewing files that changed from the base of the PR and between d11a6e9 and bffdd6f.

📒 Files selected for processing (3)
  • skills/lark-im/SKILL.md
  • skills/lark-im/references/lark-im-chat-create.md
  • skills/lark-im/references/lark-im-messages-send.md

Comment thread skills/lark-im/SKILL.md
Comment on lines +113 to +114
| `reactions.*` (add / delete / list / batch_query) | Add, remove, or read emoji reactions on a message; user/bot; caller must be in the conversation, and can only delete its own reactions. Read first: [`lark-im-reactions.md`](references/lark-im-reactions.md) |
| `feed.groups.*` (create / update / delete / batch_query / batch_add_item / batch_remove_item) | Manage feed groups (tags) and their member cards; user-only. Read first: [`lark-im-feed-groups.md`](references/lark-im-feed-groups.md) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check whether reactions.* and feed.groups.* have registered shortcut wrappers (+ prefix) or are native API only
ast-grep outline skills/lark-im/ --match reactions --view expanded | head -20
rg -n 'reactions-add|feed-groups-create' skills/lark-im/references/ || echo "No +reactions-* or +feed-groups-* shortcuts found"
rg -n 'Add, remove, or read emoji reactions' skills/lark-im/references/

Repository: larksuite/cli

Length of output: 215


🏁 Script executed:

#!/bin/bash
# Read the SKILL.md file around the contested lines to see the table structure
cat -n skills/lark-im/SKILL.md | sed -n '100,135p'

Repository: larksuite/cli

Length of output: 4650


🏁 Script executed:

#!/bin/bash
# Search for how shortcuts are defined elsewhere in the file (look for + prefix patterns)
rg -n '\+[a-z\-]+' skills/lark-im/SKILL.md | head -20

Repository: larksuite/cli

Length of output: 5816


🏁 Script executed:

#!/bin/bash
# Check the references directory structure to understand what docs exist
ls -la skills/lark-im/references/

Repository: larksuite/cli

Length of output: 2113


Move reactions.* and feed.groups.* from Shortcuts to Native API section — they use raw API pattern, not shortcut wrappers.

All other entries in the Shortcuts table (lines 100–112) use the + prefix (e.g., +messages-send, +flag-create) indicating shortcut wrappers. Lines 113–114 use dot notation (reactions.*, feed.groups.*) matching the raw native API pattern (lark-cli schema im.<resource>.<method> then lark-cli im <resource> <method>). These do not have corresponding shortcut wrappers (no +reactions-* or +feed-groups-* commands exist), and placing them in a table introduced as high-level abstractions is misleading.

Move both entries into the "Native API (beyond shortcuts)" section (lines 116–125) as examples alongside chats.*, chat.members.*, etc., so users understand they require the schema-first pattern.

🤖 Prompt for 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.

In `@skills/lark-im/SKILL.md` around lines 113 - 114, The entries for
`reactions.*` and `feed.groups.*` are currently placed in the Shortcuts section
(lines 113-114) but they use raw API pattern with dot notation rather than
shortcut wrappers with the plus prefix. Move both of these entries from their
current location in the Shortcuts table to the "Native API (beyond shortcuts)"
section (lines 116-125) where they belong alongside other raw API entries like
`chats.*` and `chat.members.*`, so users correctly understand they require the
schema-first pattern and are not high-level shortcut abstractions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation 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.

1 participant