Skip to content

feat: support files in drive +add-comment#975

Open
wittam-01 wants to merge 3 commits into
mainfrom
feat/drive-add-comment-support-md-files
Open

feat: support files in drive +add-comment#975
wittam-01 wants to merge 3 commits into
mainfrom
feat/drive-add-comment-support-md-files

Conversation

@wittam-01
Copy link
Copy Markdown
Collaborator

@wittam-01 wittam-01 commented May 19, 2026

Summary

Extend Drive file support in drive +add-comment. File targets are limited to full comments on supported Drive file extensions, with metadata validation before calling the comment API.

Changes

  • Support Drive file URLs and bare file tokens via --type file in drive +add-comment.
  • Maintain a supported file-extension whitelist for file comments: .md, .txt, .json, .csv, .go, .js, .py, .pptx, .png, .jpg, .zip, .mp3, .mp4.
  • Add a metas.batch_query preflight to read the target file title and verify its extension is supported.
  • Reject unsupported file types, including .pdf, .docx, and .xlsx, before calling the comment API because those page previews currently display comments incorrectly.
  • Reject file comments that try to use --block-id or --selection-with-ellipsis, since Drive file targets only support full comments.
  • Create Drive file comments with file_type=file and a fixed placeholder anchor.block_id value of test.
  • Return the validated file_extension in the shortcut output.
  • Update lark-drive skill documentation with file comment examples, supported-extension constraints, and the full-comment-only limitation.
  • Add unit coverage, dry-run E2E coverage, and a gated live E2E workflow for file comments.

Test Plan

  • make build
  • go test ./shortcuts/drive -count=1
  • go test ./tests/cli_e2e/drive -run TestDriveAddCommentDryRun_File -count=1

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • drive +add-comment now accepts Drive file targets (file URLs/tokens) for supported extensions and only allows full-document comments; block-level or selection comments are rejected.
  • Documentation

    • Command reference and examples updated with file-target rules, supported-extension whitelist, and validation notes.
  • Tests

    • Added unit, dry-run, coverage, and gated e2e tests covering file-target flows, validation, and execution.

Review Change Stack

Change-Id: Id9a87706a1e43756d8142637be9ec1e0748d4ddf
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

📝 Walkthrough

Walkthrough

Adds Drive Markdown .md file support to drive +add-comment (full-document-only comments, extension whitelist, placeholder anchor, dedicated execute/dry-run flows), updates Feishu Open/Accounts endpoint defaults to pre.cn, and includes unit, e2e tests, and docs/coverage updates.

Changes

Endpoint Configuration

Layer / File(s) Summary
Default endpoint configuration
internal/core/types.go
Feishu Open and Accounts endpoint defaults changed from *.feishu.cn to *.feishu-pre.cn domains.

Drive Markdown File Comment Support

Layer / File(s) Summary
Command contract and metadata
shortcuts/drive/drive_add_comment.go
Add file target support to shortcut metadata/flags, add drive:drive.metadata:readonly scope, and introduce placeholder anchor constant and file-extension whitelist.
Input parsing and messages
shortcuts/drive/drive_add_comment.go
Recognize /file/ URLs and update unsupported/enum/bare-token error messages to include file.
Validation constraints for file targets
shortcuts/drive/drive_add_comment.go
Validation rejects --block-id and --selection-with-ellipsis when target is file, enforcing full-document-only comments.
Wiki-node resolution and target mapping
shortcuts/drive/drive_add_comment.go
Extend wiki-node resolution to accept obj_type == "file" and return resolved targets with FileType: "file", applying local-vs-full constraints.
Dry-run orchestration & request building
shortcuts/drive/drive_add_comment.go
Dry-run plans metas/batch_query for file metadata then previews files/:file_token/new_comments V2 request; file V2 requests include placeholder anchor.block_id.
Metadata helpers and execution handler
shortcuts/drive/drive_add_comment.go
Helpers to fetch/validate Drive file title and extension; executeFileComment validates extension, posts full new_comments, and returns file_name, file_extension, and comment_mode=full.
Unit and dry-run tests
shortcuts/drive/drive_add_comment_test.go, tests/cli_e2e/drive/drive_add_comment_dryrun_test.go
Tests for parsing file refs, building requests with placeholder anchor, validation rejection of block/selection flags, execute success/failure for supported/unsupported extensions, supported-extension lists, and dry-run preview verification.
Docs, coverage, and E2E workflows
skills/lark-drive/references/lark-drive-add-comment.md, skills/lark-drive/SKILL.md, tests/cli_e2e/drive/coverage.md, tests/cli_e2e/drive/drive_add_comment_workflow_test.go
Docs updated with file usage/limits and examples; coverage updated; added gated live Markdown-file E2E workflow that creates a file, posts a comment, and validates returned fields.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • larksuite/cli#518: Overlapping edits to parsing/resolution and V2 comment request construction for additional target types.
  • larksuite/cli#674: Related changes adding other Drive target kinds and altering request building/validation paths.

Suggested reviewers

  • fangshuyu-768
  • liangshuo-1

Poem

🐰 I nibble tokens, check the title’s end,
Full-text comments, no snippets to bend.
Metadata asked, .md must be true,
A placeholder anchor keeps the API due.
Pre.cn whispers guide the route anew. 🌱

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% 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
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.
Title check ✅ Passed The title 'feat: support files in drive +add-comment' accurately summarizes the main change: adding file support to the drive +add-comment command.
Description check ✅ Passed The PR description follows the template structure with all required sections: Summary, Changes, Test Plan, and Related Issues are present and substantively filled out.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/drive-add-comment-support-md-files

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths labels May 19, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/core/types.go (1)

27-28: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update stale endpoint examples in comments.

The comments still reference the old *.feishu.cn domain format, but the actual default values now use *-pre.cn domains. The examples should reflect the current implementation.

📝 Proposed fix to update comment examples
 type Endpoints struct {
-	Open     string // e.g. "https://open.feishu.cn"
-	Accounts string // e.g. "https://accounts.feishu.cn"
+	Open     string // e.g. "https://open.feishu-pre.cn"
+	Accounts string // e.g. "https://accounts.feishu-pre.cn"
 	MCP      string // e.g. "https://mcp.feishu.cn"
 	AppLink  string // e.g. "https://applink.feishu.cn"
 }
🤖 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 `@internal/core/types.go` around lines 27 - 28, Update the stale example
comments for the Open and Accounts fields to match the current default domain
format: change the examples from the old "*.feishu.cn" to the new "*-pre.cn"
style and ensure the comment text alongside the Open and Accounts fields (the
Open and Accounts fields in the types.go diff) reflect the exact current default
hostnames used by the implementation.
🤖 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 `@internal/core/types.go`:
- Around line 45-48: Restore consistent production domains or align tests:
revert the two changed endpoints in internal/core/types.go so Open and Accounts
use "https://open.feishu.cn" and "https://accounts.feishu.cn" (to match MCP and
AppLink and the TestResolveEndpoints_Feishu expectation), or if the intent was
to switch to pre-production, change all four endpoints (Open, Accounts, MCP,
AppLink) to the -pre variants and update TestResolveEndpoints_Feishu to assert
the new values; ensure the code symbols ep.Open, ep.Accounts, MCP and AppLink
are updated together and the test TestResolveEndpoints_Feishu is updated
accordingly.

---

Outside diff comments:
In `@internal/core/types.go`:
- Around line 27-28: Update the stale example comments for the Open and Accounts
fields to match the current default domain format: change the examples from the
old "*.feishu.cn" to the new "*-pre.cn" style and ensure the comment text
alongside the Open and Accounts fields (the Open and Accounts fields in the
types.go diff) reflect the exact current default hostnames used by the
implementation.
🪄 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: 89e09742-fe49-47bf-9742-be4063d8159f

📥 Commits

Reviewing files that changed from the base of the PR and between 13411d9 and 7d2b567.

📒 Files selected for processing (7)
  • internal/core/types.go
  • shortcuts/drive/drive_add_comment.go
  • shortcuts/drive/drive_add_comment_test.go
  • skills/lark-drive/references/lark-drive-add-comment.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_add_comment_dryrun_test.go
  • tests/cli_e2e/drive/drive_add_comment_workflow_test.go

Comment thread internal/core/types.go
Comment on lines +45 to 48
Open: "https://open.feishu-pre.cn",
Accounts: "https://accounts.feishu-pre.cn",
MCP: "https://mcp.feishu.cn",
AppLink: "https://applink.feishu.cn",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the new -pre domains are reachable and check for related config

echo "=== Testing endpoint reachability ==="
for url in "https://open.feishu-pre.cn" "https://accounts.feishu-pre.cn"; do
  echo "Testing $url"
  curl -s -o /dev/null -w "HTTP %{http_code}\n" --connect-timeout 5 "$url" || echo "Failed to connect"
done

echo -e "\n=== Searching for endpoint configuration documentation ==="
rg -n -C3 'feishu-pre' --type=md

echo -e "\n=== Searching for other references to -pre domains ==="
rg -n 'feishu-pre'

echo -e "\n=== Checking for environment-specific configuration ==="
rg -n -C3 'ResolveEndpoints|BrandFeishu' --type=go

Repository: larksuite/cli

Length of output: 50370


Endpoint changes break existing unit tests.

The code change to use -pre domains (https://open.feishu-pre.cn, https://accounts.feishu-pre.cn) directly conflicts with existing test expectations in internal/core/types_test.go. The test TestResolveEndpoints_Feishu (line 10) explicitly asserts that ep.Open should equal "https://open.feishu.cn", which will fail with this change.

Additionally:

  • Only 2 of 4 endpoints were migrated to -pre domains (Open and Accounts remain changed; MCP and AppLink remain on regular .feishu.cn). This inconsistency may cause runtime issues.
  • -pre domain suffix typically indicates pre-production/staging environments, not production-ready endpoints. Verify this is intentional for the default Feishu brand.
  • No PR description or comments explain why this endpoint migration is needed or related to the Markdown file support feature.

Either update the tests to match the new endpoints, or revert to .feishu.cn domains and explain the rationale if a domain change is truly required.

🤖 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 `@internal/core/types.go` around lines 45 - 48, Restore consistent production
domains or align tests: revert the two changed endpoints in
internal/core/types.go so Open and Accounts use "https://open.feishu.cn" and
"https://accounts.feishu.cn" (to match MCP and AppLink and the
TestResolveEndpoints_Feishu expectation), or if the intent was to switch to
pre-production, change all four endpoints (Open, Accounts, MCP, AppLink) to the
-pre variants and update TestResolveEndpoints_Feishu to assert the new values;
ensure the code symbols ep.Open, ep.Accounts, MCP and AppLink are updated
together and the test TestResolveEndpoints_Feishu is updated accordingly.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/drive-add-comment-support-md-files -y -g

wittam-01 added 2 commits May 19, 2026 20:41
Change-Id: Ifffc4cdd963c13e53f4cad154aebe11ae309df9e
Change-Id: Ie6c7f38dbbea1f87a81600da71180627b53a2355
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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-drive/SKILL.md`:
- Around line 142-143: Update the SKILL.md text that currently says "仅支持 `docx`"
to accurately describe supported partial-comment scopes: explain that the CLI
flag `--block-id` enables partial comments; `docx` supports both text- and
block-level定位 (定位/块定位), `sheet` and `slides` support only block-level 定位 via
their respective `--block-id` formats, and generic Drive `file` types do not
support 局部评论; also adjust the whitelist paragraph to keep full-file comment
limitations unchanged for the Drive file types list (e.g., `.pdf`, `.docx`,
`.xlsx` remain unsupported for partial comments).
🪄 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: f89521f5-04ce-4539-b0ff-3882f4c40e56

📥 Commits

Reviewing files that changed from the base of the PR and between 8c48f18 and 3f3bd13.

📒 Files selected for processing (7)
  • shortcuts/drive/drive_add_comment.go
  • shortcuts/drive/drive_add_comment_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-add-comment.md
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_add_comment_dryrun_test.go
  • tests/cli_e2e/drive/drive_add_comment_workflow_test.go
✅ Files skipped from review due to trivial changes (1)
  • tests/cli_e2e/drive/coverage.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/cli_e2e/drive/drive_add_comment_workflow_test.go

Comment on lines +142 to +143
- 局部评论:传 `--block-id` 时启用;仅支持 `docx`,以及最终解析为 `docx` 的 wiki URL。block ID 可通过 `docs +fetch --api-version v2 --detail with-ids` 获取。Drive file 本次只支持全文评论,不支持局部评论。
- Drive file 评论仅支持白名单扩展名:`.md`、`.txt`、`.json`、`.csv`、`.go`、`.js`、`.py`、`.pptx`、`.png`、`.jpg`、`.zip`、`.mp3`、`.mp4`。`.pdf`、`.docx`、`.xlsx` 等未在白名单内的普通文件暂不支持,CLI 会直接报错提示当前还不支持这种类型的评论。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

局部评论支持范围描述与当前能力不一致

这里写成“仅支持 docx”,但该命令同时支持 sheetslides 的定位评论(通过各自格式的 --block-id)。建议改成区分:docx 支持文本定位/块定位,sheet/slides 仅支持块定位,file 不支持局部评论。

🤖 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-drive/SKILL.md` around lines 142 - 143, Update the SKILL.md text
that currently says "仅支持 `docx`" to accurately describe supported
partial-comment scopes: explain that the CLI flag `--block-id` enables partial
comments; `docx` supports both text- and block-level定位 (定位/块定位), `sheet` and
`slides` support only block-level 定位 via their respective `--block-id` formats,
and generic Drive `file` types do not support 局部评论; also adjust the whitelist
paragraph to keep full-file comment limitations unchanged for the Drive file
types list (e.g., `.pdf`, `.docx`, `.xlsx` remain unsupported for partial
comments).

@wittam-01 wittam-01 changed the title feat: support markdown files in drive +add-comment feat: support files in drive +add-comment May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm 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