Skip to content

feat: add drive create-shortcut#432

Merged
fangshuyu-768 merged 1 commit intolarksuite:mainfrom
ch-2026:feat/drive-create-shortcut
Apr 13, 2026
Merged

feat: add drive create-shortcut#432
fangshuyu-768 merged 1 commit intolarksuite:mainfrom
ch-2026:feat/drive-create-shortcut

Conversation

@ch-2026
Copy link
Copy Markdown
Contributor

@ch-2026 ch-2026 commented Apr 12, 2026

Summary

Add a new drive +create-shortcut shortcut for creating a Drive shortcut in a specified target folder. The command follows the existing shortcut framework, performs structured validation, checks required scopes through the shared runner, and returns machine-friendly output for both human users and AI Agents.

Changes

  • Add drive +create-shortcut shortcut under the drive domain
  • Require explicit --folder-token, --file-token, and --type inputs for safer write behavior
  • Build request payload using the documented API schema:
    • parent_token
    • refer_entity.refer_token
    • refer_entity.refer_type
  • Parse successful responses from data.succ_shortcut_node
    • surface shortcut_token
    • surface title
    • surface url
  • Use the correct shortcut scope declaration for permission pre-checking
  • Reject unsupported source types during validation, including wiki, folder, and unsupported values
  • Remove the previously allowed shortcut source type from validation because it is not listed in the API type contract
  • Add actionable classification for known Drive API constraint errors:
    • 1061045
    • 1064510
    • 1064511
  • Generalize the 1061045 hint text so it remains correct for shared error classification
  • Add and update documentation for the new shortcut in lark-drive references
  • Add docstrings for newly added functions and tests to satisfy docstring coverage checks

Test Plan

  • make unit-test
  • go test ./shortcuts/drive
  • go test ./shortcuts/drive ./internal/output
  • go test -coverprofile=/tmp/shortcuts-drive.cover.out -covermode=atomic ./shortcuts/drive
  • go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=main

Additional verification:

  • Verified dry-run output uses the updated request body schema
  • Verified execution tests cover data.succ_shortcut_node.token
  • Verified validation fails when --folder-token is omitted
  • Verified known Drive API constraint errors return structured error types and generalized hints

Related Issues

  • None

This command intentionally requires an explicit target folder to avoid silently creating shortcuts in the caller's root folder.

Summary by CodeRabbit

  • New Features

    • Added Drive shortcut creation command supporting multiple file types (file, docx, bitable, doc, sheet, mindnote, slides)
  • Improvements

    • Enhanced error messages for Drive API constraints including resource contention, cross-tenant, and cross-brand restriction scenarios
  • Tests

    • Added comprehensive test coverage for shortcut creation validation and API error classification
  • Documentation

    • Added command reference with usage examples, parameter requirements, and error handling guidance

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 12, 2026

CLA assistant check
All committers have signed the CLA.

@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 Apr 12, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c60b3d9d-9ddf-4144-a2ef-0de6ae63942e

📥 Commits

Reviewing files that changed from the base of the PR and between 59bdbc7 and 242a279.

📒 Files selected for processing (8)
  • internal/output/lark_errors.go
  • internal/output/lark_errors_test.go
  • shortcuts/drive/drive_create_shortcut.go
  • shortcuts/drive/drive_create_shortcut_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-create-shortcut.md
✅ Files skipped from review due to trivial changes (3)
  • skills/lark-drive/SKILL.md
  • shortcuts/drive/shortcuts.go
  • skills/lark-drive/references/lark-drive-create-shortcut.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • shortcuts/drive/shortcuts_test.go
  • internal/output/lark_errors_test.go
  • shortcuts/drive/drive_create_shortcut_test.go
  • internal/output/lark_errors.go

📝 Walkthrough

Walkthrough

Adds a new DriveCreateShortcut CLI command (validation, dry-run, execution, tests), registers it in the drive shortcuts registry, extends Lark error classification with three Drive-related error codes and tests, and adds documentation for the new command.

Changes

Cohort / File(s) Summary
Error Handling
internal/output/lark_errors.go, internal/output/lark_errors_test.go
Add three Lark Drive error-code constants (1061045, 1064510, 1064511) and extend ClassifyLarkError to map them to ExitAPI with specific errType (conflict, cross_tenant_unit, cross_brand) and non-empty hints; add tests for these mappings.
Drive Shortcut Command
shortcuts/drive/drive_create_shortcut.go, shortcuts/drive/drive_create_shortcut_test.go
Introduce DriveCreateShortcut command with flags --file-token, --type, --folder-token; implement validation (type allowlist, reject wiki/folder, token format checks), dry-run (POST preview), execution (POST /open-apis/drive/v1/files/create_shortcut), and tests covering validation, dry-run, execution, and API error classification.
Shortcuts Registry
shortcuts/drive/shortcuts.go, shortcuts/drive/shortcuts_test.go
Register DriveCreateShortcut in Shortcuts() and update tests to expect +create-shortcut.
Documentation
skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-create-shortcut.md
Add docs for +create-shortcut including usage, required flags, examples, dry-run behavior, limits, common error codes, and guidance on cross-tenant/brand constraints.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as DriveCreateShortcut Command
    participant RootAPI as GET /open-apis/drive/explorer/v2/root_folder/meta
    participant ShortcutAPI as POST /open-apis/drive/v1/files/create_shortcut

    User->>CLI: invoke with --file-token, --type (optional --folder-token)
    alt folder-token provided
        CLI->>ShortcutAPI: POST create_shortcut (parent_token = provided, refer_entity with refer_token/type)
    else folder-token omitted
        CLI->>RootAPI: GET root_folder/meta
        RootAPI-->>CLI: return root folder token
        CLI->>ShortcutAPI: POST create_shortcut (parent_token = root token, refer_entity ...)
    end
    ShortcutAPI-->>CLI: creation response (shortcut_token, url, title, ...)
    CLI-->>User: print structured result (created, shortcut_token, folder_token, source_*)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • liujinkun2025
  • fangshuyu-768

Poem

🐰 A tiny hop, a shortcut born,
Token tucked, through folders worn.
Root found or given, link takes flight,
CLI nudges onward in the night,
Hop—your Drive finds the perfect light.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new drive create-shortcut feature, which matches the core functionality across all modified files.
Description check ✅ Passed The description comprehensively covers all required template sections: a detailed Summary, extensive Changes list, complete Test Plan with checkmarks, and Related Issues statement.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%.

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

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

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

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 12, 2026

Greptile Summary

Adds drive +create-shortcut, a new write shortcut that creates a Drive shortcut in a target folder via POST /open-apis/drive/v1/files/create_shortcut. All three previously-flagged P1 concerns are resolved: the 1061045 hint is now generic, response parsing correctly uses common.GetString(data, "succ_shortcut_node", ...), and the duplicate firstNonEmpty helper was not carried forward.

Confidence Score: 5/5

Safe to merge; all prior P1 concerns addressed and remaining findings are P2 style nits.

All three blocking concerns from the previous review round were resolved. The only remaining findings are two missing t.Parallel() calls and a test function name that is too narrow — neither affects correctness or runtime behavior.

shortcuts/drive/drive_create_shortcut_test.go — two tests missing t.Parallel(); internal/output/lark_errors_test.go — test name overly scoped to create-shortcut.

Important Files Changed

Filename Overview
shortcuts/drive/drive_create_shortcut.go New +create-shortcut command: correct multi-key GetString path for succ_shortcut_node, proper type whitelist validation with targeted rejections for wiki/folder/shortcut, clean RequestBody builder.
shortcuts/drive/drive_create_shortcut_test.go Comprehensive tests covering dry-run, execution, validation, and API constraint classification; two top-level tests are missing t.Parallel() inconsistently.
internal/output/lark_errors.go Adds three Drive-specific error codes with generalized, command-agnostic hints; hint text for 1061045 is now correctly generic.
internal/output/lark_errors_test.go New test file validating the three Drive error codes; test function name is overly scoped to create-shortcut rather than the general Drive constraint classification.
shortcuts/drive/shortcuts.go DriveCreateShortcut registered in second position (between Upload and Download); no issues.
shortcuts/drive/shortcuts_test.go Adds +create-shortcut to the expected command list and adds a docstring; consistent with existing pattern.
skills/lark-drive/SKILL.md Adds +create-shortcut row to the shortcut table; correct placement and link.
skills/lark-drive/references/lark-drive-create-shortcut.md Comprehensive reference doc covering parameters, type table, constraints, permissions, and error codes including the three newly classified Drive errors.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as lark-cli drive +create-shortcut
    participant Validate as validateDriveCreateShortcutSpec
    participant API as POST /drive/v1/files/create_shortcut
    participant Classify as ClassifyLarkError

    User->>CLI: --file-token T --type docx --folder-token F
    CLI->>Validate: FileToken, FileType, FolderToken
    alt invalid type (wiki / folder / unknown)
        Validate-->>CLI: ErrValidation
        CLI-->>User: exit validation_error
    end
    Validate-->>CLI: nil
    CLI->>API: {parent_token, refer_entity{refer_token, refer_type}}
    alt API error (1061045 / 1064510 / 1064511)
        API-->>Classify: code, msg
        Classify-->>CLI: conflict / cross_tenant_unit / cross_brand + hint
        CLI-->>User: exit api_error (structured)
    end
    API-->>CLI: data.succ_shortcut_node {token, url, name}
    CLI-->>User: {created, shortcut_token, url, title, source_file_token, folder_token}
Loading

Reviews (4): Last reviewed commit: "feat: add drive create-shortcut shortcut" | Re-trigger Greptile

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 the current code and only fix it if needed.

Inline comments:
In `@shortcuts/drive/drive_create_shortcut.go`:
- Around line 56-61: The folder-token (and other flag inputs like type) must be
normalized (TrimSpace and lowercase for type) once when constructing the
driveCreateShortcutSpec so Validate, DryRun and Execute all see the same cleaned
values; update the Validate block (where driveCreateShortcutSpec is built) and
the analogous builders in DryRun and Execute to call strings.TrimSpace on
runtime.Str("folder-token") and
strings.ToLower(strings.TrimSpace(runtime.Str("type"))) and pass those into
validateDriveCreateShortcutSpec and subsequent logic so whitespace-only
folder-token no longer bypasses root-folder fallback and an invalid parent_token
is never sent to the API.
🪄 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: 25bab4a1-98e2-465c-8256-4e07dfa36dee

📥 Commits

Reviewing files that changed from the base of the PR and between f6b8091 and c93e2b6.

📒 Files selected for processing (8)
  • internal/output/lark_errors.go
  • internal/output/lark_errors_test.go
  • shortcuts/drive/drive_create_shortcut.go
  • shortcuts/drive/drive_create_shortcut_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-create-shortcut.md

@ch-2026 ch-2026 force-pushed the feat/drive-create-shortcut branch from c93e2b6 to 8878a64 Compare April 12, 2026 08:55
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.

♻️ Duplicate comments (1)
shortcuts/drive/drive_create_shortcut.go (1)

56-61: ⚠️ Potential issue | 🟠 Major

Normalize flags once to prevent whitespace --folder-token from bypassing root fallback.

FolderToken is read untrimmed into spec, so a whitespace-only value is treated as “provided” in Execute (Line 96) but effectively “empty” in validation gating (Line 152). This can send an invalid parent_token instead of resolving root folder.

Proposed fix
+func buildDriveCreateShortcutSpec(runtime *common.RuntimeContext) driveCreateShortcutSpec {
+	return driveCreateShortcutSpec{
+		FileToken:   strings.TrimSpace(runtime.Str("file-token")),
+		FileType:    strings.ToLower(strings.TrimSpace(runtime.Str("type"))),
+		FolderToken: strings.TrimSpace(runtime.Str("folder-token")),
+	}
+}
+
  Validate: func(ctx context.Context, runtime *common.RuntimeContext) error {
-		return validateDriveCreateShortcutSpec(driveCreateShortcutSpec{
-			FileToken:   runtime.Str("file-token"),
-			FileType:    strings.ToLower(runtime.Str("type")),
-			FolderToken: runtime.Str("folder-token"),
-		})
+		return validateDriveCreateShortcutSpec(buildDriveCreateShortcutSpec(runtime))
  },
  DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
-		spec := driveCreateShortcutSpec{
-			FileToken:   runtime.Str("file-token"),
-			FileType:    strings.ToLower(runtime.Str("type")),
-			FolderToken: runtime.Str("folder-token"),
-		}
+		spec := buildDriveCreateShortcutSpec(runtime)
@@
  Execute: func(ctx context.Context, runtime *common.RuntimeContext) error {
-		spec := driveCreateShortcutSpec{
-			FileToken:   runtime.Str("file-token"),
-			FileType:    strings.ToLower(runtime.Str("type")),
-			FolderToken: runtime.Str("folder-token"),
-		}
+		spec := buildDriveCreateShortcutSpec(runtime)
@@
-	if strings.TrimSpace(spec.FolderToken) != "" {
+	if spec.FolderToken != "" {
 		if err := validate.ResourceName(spec.FolderToken, "--folder-token"); err != nil {
 			return output.ErrValidation("%s", err)
 		}
 	}

Also applies to: 64-68, 90-97, 148-156

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/drive/drive_create_shortcut.go` around lines 56 - 61,
Trim/normalize flag values once when building the driveCreateShortcutSpec so
whitespace-only flags don't bypass fallbacks: update the places that construct
driveCreateShortcutSpec (the Validate block and the Execute block where
runtime.Str is read) to call strings.TrimSpace on FolderToken (and other
flag-derived fields like FileType/FileToken as needed) before passing into
validateDriveCreateShortcutSpec or using parent_token resolution; ensure
FolderToken is compared against empty string after trimming in Execute and in
validateDriveCreateShortcutSpec so a whitespace-only --folder-token triggers the
root fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@shortcuts/drive/drive_create_shortcut.go`:
- Around line 56-61: Trim/normalize flag values once when building the
driveCreateShortcutSpec so whitespace-only flags don't bypass fallbacks: update
the places that construct driveCreateShortcutSpec (the Validate block and the
Execute block where runtime.Str is read) to call strings.TrimSpace on
FolderToken (and other flag-derived fields like FileType/FileToken as needed)
before passing into validateDriveCreateShortcutSpec or using parent_token
resolution; ensure FolderToken is compared against empty string after trimming
in Execute and in validateDriveCreateShortcutSpec so a whitespace-only
--folder-token triggers the root fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 56dd97ac-c508-4343-8ae7-591da73fa5a9

📥 Commits

Reviewing files that changed from the base of the PR and between c93e2b6 and 8878a64.

📒 Files selected for processing (8)
  • internal/output/lark_errors.go
  • internal/output/lark_errors_test.go
  • shortcuts/drive/drive_create_shortcut.go
  • shortcuts/drive/drive_create_shortcut_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-create-shortcut.md
✅ Files skipped from review due to trivial changes (3)
  • shortcuts/drive/shortcuts.go
  • internal/output/lark_errors_test.go
  • skills/lark-drive/references/lark-drive-create-shortcut.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md

@ch-2026 ch-2026 force-pushed the feat/drive-create-shortcut branch from 8878a64 to 59bdbc7 Compare April 12, 2026 09:54
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.

♻️ Duplicate comments (1)
shortcuts/drive/drive_create_shortcut.go (1)

54-55: ⚠️ Potential issue | 🟠 Major

--folder-token is implemented as required, but the feature objective says it must be optional with root-folder fallback.

This currently blocks the “omit folder and fallback to root” flow, and dry-run cannot preview root resolution as described in the PR objective.

🛠️ Proposed fix (core changes)
-		{Name: "folder-token", Desc: "target folder token for the new shortcut", Required: true},
+		{Name: "folder-token", Desc: "target folder token for the new shortcut", Required: false},
@@
-	if err := validate.ResourceName(spec.FolderToken, "--folder-token"); err != nil {
-		return output.ErrValidation("%s", err)
-	}
+	if strings.TrimSpace(spec.FolderToken) != "" {
+		if err := validate.ResourceName(spec.FolderToken, "--folder-token"); err != nil {
+			return output.ErrValidation("%s", err)
+		}
+	}

Then add the root-folder resolution path when spec.FolderToken == "" in DryRun and Execute, and include the resolved folder token in dry-run preview/output.

Also applies to: 63-75, 76-81, 127-129

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/drive/drive_create_shortcut.go` around lines 54 - 55, The
--folder-token CLI flag is currently marked Required but must be optional with a
root-folder fallback; update the flag definition (the entry with Name:
"folder-token") to remove Required: true so it’s optional, then add logic in the
DryRun and Execute methods to detect when spec.FolderToken == "" and resolve the
root folder token (assign the resolved token back to spec.FolderToken), include
that resolved token in the DryRun preview/output, and ensure any help text
reflects the optional nature and fallback behavior; touch the functions/methods
named DryRun, Execute and the flag definition for "folder-token" to implement
these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@shortcuts/drive/drive_create_shortcut.go`:
- Around line 54-55: The --folder-token CLI flag is currently marked Required
but must be optional with a root-folder fallback; update the flag definition
(the entry with Name: "folder-token") to remove Required: true so it’s optional,
then add logic in the DryRun and Execute methods to detect when spec.FolderToken
== "" and resolve the root folder token (assign the resolved token back to
spec.FolderToken), include that resolved token in the DryRun preview/output, and
ensure any help text reflects the optional nature and fallback behavior; touch
the functions/methods named DryRun, Execute and the flag definition for
"folder-token" to implement these changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d647d7ba-a579-491c-b043-3ddd5346e036

📥 Commits

Reviewing files that changed from the base of the PR and between 8878a64 and 59bdbc7.

📒 Files selected for processing (8)
  • internal/output/lark_errors.go
  • internal/output/lark_errors_test.go
  • shortcuts/drive/drive_create_shortcut.go
  • shortcuts/drive/drive_create_shortcut_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-create-shortcut.md
✅ Files skipped from review due to trivial changes (3)
  • shortcuts/drive/shortcuts_test.go
  • skills/lark-drive/SKILL.md
  • shortcuts/drive/shortcuts.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/output/lark_errors.go
  • shortcuts/drive/drive_create_shortcut_test.go

@ch-2026 ch-2026 force-pushed the feat/drive-create-shortcut branch from 1b1170f to 242a279 Compare April 12, 2026 10:22
@ch-2026
Copy link
Copy Markdown
Contributor Author

ch-2026 commented Apr 12, 2026

image 实测没啥问题,命令为“drive +create-shortcut”

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add ch-2026/lark_cli#feat/drive-create-shortcut -y -g

@fangshuyu-768
Copy link
Copy Markdown
Collaborator

Thanks a lot for the high-quality PR, we really appreciate the thoughtful implementation and test coverage.

We’re glad to have your contribution, and you’re very welcome to continue sharing suggestions or submitting PRs in the future.

@fangshuyu-768 fangshuyu-768 merged commit 3917b77 into larksuite:main Apr 13, 2026
14 checks passed
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.

3 participants