feat: add drive create-shortcut#432
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughAdds 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
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_*)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Greptile SummaryAdds Confidence Score: 5/5Safe 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
Sequence DiagramsequenceDiagram
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}
Reviews (4): Last reviewed commit: "feat: add drive create-shortcut shortcut" | Re-trigger Greptile |
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
internal/output/lark_errors.gointernal/output/lark_errors_test.goshortcuts/drive/drive_create_shortcut.goshortcuts/drive/drive_create_shortcut_test.goshortcuts/drive/shortcuts.goshortcuts/drive/shortcuts_test.goskills/lark-drive/SKILL.mdskills/lark-drive/references/lark-drive-create-shortcut.md
c93e2b6 to
8878a64
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
shortcuts/drive/drive_create_shortcut.go (1)
56-61:⚠️ Potential issue | 🟠 MajorNormalize flags once to prevent whitespace
--folder-tokenfrom bypassing root fallback.
FolderTokenis 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 invalidparent_tokeninstead 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
📒 Files selected for processing (8)
internal/output/lark_errors.gointernal/output/lark_errors_test.goshortcuts/drive/drive_create_shortcut.goshortcuts/drive/drive_create_shortcut_test.goshortcuts/drive/shortcuts.goshortcuts/drive/shortcuts_test.goskills/lark-drive/SKILL.mdskills/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
8878a64 to
59bdbc7
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
shortcuts/drive/drive_create_shortcut.go (1)
54-55:⚠️ Potential issue | 🟠 Major
--folder-tokenis 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 == ""inDryRunandExecute, 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
📒 Files selected for processing (8)
internal/output/lark_errors.gointernal/output/lark_errors_test.goshortcuts/drive/drive_create_shortcut.goshortcuts/drive/drive_create_shortcut_test.goshortcuts/drive/shortcuts.goshortcuts/drive/shortcuts_test.goskills/lark-drive/SKILL.mdskills/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
1b1170f to
242a279
Compare
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@242a279e314b58acba46e367fd25512f286e6d76🧩 Skill updatenpx skills add ch-2026/lark_cli#feat/drive-create-shortcut -y -g |
|
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. |

Summary
Add a new
drive +create-shortcutshortcut 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
drive +create-shortcutshortcut under thedrivedomain--folder-token,--file-token, and--typeinputs for safer write behaviorparent_tokenrefer_entity.refer_tokenrefer_entity.refer_typedata.succ_shortcut_nodeshortcut_tokentitleurlwiki,folder, and unsupported valuesshortcutsource type from validation because it is not listed in the API type contract1061045106451010645111061045hint text so it remains correct for shared error classificationlark-drivereferencesTest Plan
make unit-testgo test ./shortcuts/drivego test ./shortcuts/drive ./internal/outputgo test -coverprofile=/tmp/shortcuts-drive.cover.out -covermode=atomic ./shortcuts/drivego run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run --new-from-rev=mainAdditional verification:
data.succ_shortcut_node.token--folder-tokenis omittedRelated Issues
This command intentionally requires an explicit target folder to avoid silently creating shortcuts in the caller's root folder.
Summary by CodeRabbit
New Features
Improvements
Tests
Documentation