feat: add drive create-folder shortcut and wiki node auto-grant#470
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
📝 WalkthroughWalkthroughThis PR adds a new Drive shortcut Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI (Bot Mode)
participant DriveAPI as Drive API /create_folder
participant PermAPI as Drive API /permissions
CLI->>DriveAPI: POST /open-apis/drive/v1/files/create_folder<br/>{name, folder_token}
DriveAPI-->>CLI: {folder_token, url, name, parent_folder_token}
alt CLI running as bot
CLI->>PermAPI: POST /open-apis/drive/v1/permissions<br/>{member_type, member_id, perm}
PermAPI-->>CLI: {status, user_open_id, message}
CLI->>CLI: Augment output with permission_grant
end
CLI->>CLI: Emit final JSON output (created, name, folder_token, parent_folder_token, url?, permission_grant?)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@70cc9ff13a3923659c492e272d1917b6d49a9316🧩 Skill updatenpx skills add larksuite/cli#feat/drive-create-folder-wiki-node-auto-grant -y -g |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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_folder.go`:
- Around line 85-97: The code currently treats an empty folder token as success;
before constructing the response map in DriveCreateFolder (where folderToken :=
common.GetString(data, "token")), validate that folderToken is non-empty and
return an error (or fail fast) if it is empty/null; do this check prior to
building the out map and before calling
common.AutoGrantCurrentUserDrivePermission/runtime logic so you don't emit
created=true or run permission grants for a malformed response.
In `@shortcuts/wiki/wiki_node_create.go`:
- Around line 470-473: The code calls wikiNodeCreateOutput(execution) before
checking if execution is nil, which can panic; modify
augmentWikiNodeCreateOutput so you first guard execution (and execution.Node as
needed) before calling wikiNodeCreateOutput, e.g., check execution != nil (and
execution.Node != nil where used) and only then call
wikiNodeCreateOutput(execution) and run
common.AutoGrantCurrentUserDrivePermission(runtime, execution.Node.NodeToken,
"wiki") so all dereferences are safe; keep the function name
augmentWikiNodeCreateOutput and the call sites to wikiNodeCreateOutput and
AutoGrantCurrentUserDrivePermission unchanged aside from reordering.
In `@skills/lark-drive/references/lark-drive-create-folder.md`:
- Line 5: 在描述创建文件夹的文案中,将措辞“会尝试把新文件夹的可管理权限自动授予当前 CLI
用户”改为更通顺的“会尝试将新文件夹的可管理权限自动授予当前 CLI 用户”;具体在 lark-drive-create-folder.md
中包含“--folder-token”、“--as bot”和“drive files create_folder” 的那段说明里替换该短语以提升可读性。
🪄 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: efa97a78-dce0-49fc-9d13-064bcd9440d3
📒 Files selected for processing (11)
shortcuts/drive/drive_create_folder.goshortcuts/drive/drive_create_folder_test.goshortcuts/drive/shortcuts.goshortcuts/drive/shortcuts_test.goshortcuts/wiki/wiki_node_create.goshortcuts/wiki/wiki_node_create_test.goskill-template/domains/drive.mdskills/lark-drive/SKILL.mdskills/lark-drive/references/lark-drive-create-folder.mdskills/lark-wiki/SKILL.mdskills/lark-wiki/references/lark-wiki-node-create.md
Change-Id: I1acd001a1d4616bc5a957cad437e5aa4f1afeb51
7bb99e5 to
70cc9ff
Compare
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
shortcuts/wiki/wiki_node_create_test.go (1)
521-525: Drop the redundant config-dir env setup in theseTestFactorytests.These cases already use
cmdutil.TestFactory(t, ...), so forcingLARKSUITE_CLI_CONFIG_DIRadds noise without affecting behavior.Based on learnings: Shortcut tests that build the CLI via
cmdutil.TestFactory(t, config)should not set this env var becauseTestFactoryprovides an in-memory config closure and does not access the filesystem.Also applies to: 591-595
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/wiki/wiki_node_create_test.go` around lines 521 - 525, Remove the unnecessary environment setup that calls t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) from tests that use cmdutil.TestFactory (e.g., TestWikiNodeCreateBotAutoGrantSuccess and the similar test around the other occurrence); TestFactory supplies an in-memory config and does not read the filesystem, so delete the t.Setenv call to avoid noisy, redundant test setup and leave the rest of the test and the cmdutil.TestFactory(...) invocation intact.
🤖 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_folder.go`:
- Around line 61-63: The call to dry.Desc() inside the runtime.IsBot() branch
overwrites the prior description for the POST that creates the folder (the "[1]
Create folder" step); instead either append the bot-mode note to the existing
description for that POST (read and concatenate to the existing description on
the POST/DryRun call) or create a separate dry step/note that describes the
permission-grant follow-up (i.e., add a new DryRun step after the POST to
document granting the current CLI user full_access) so you don't clobber the
original "[1] Create folder" message.
- Around line 98-99: The shortcut currently calls
common.AutoGrantCurrentUserDrivePermission(runtime, folderToken, "folder") and
writes the result into out["permission_grant"], but the POST to
/drive/v1/permissions/{token}/members requires a broader drive scope; update the
shortcut's declared scopes to include one of drive:drive, drive:file, or
wiki:wiki in addition to space:folder:create so the
AutoGrantCurrentUserDrivePermission call can succeed at runtime and avoid
"failed" permission_grant results.
In `@shortcuts/wiki/wiki_node_create.go`:
- Around line 478-480: The declared OAuth scopes for this shortcut are missing
the drive-level scope needed by AutoGrantCurrentUserDrivePermission, causing
permission grant calls to fail in bot mode; update the shortcut's declared
scopes (the array currently containing "wiki:node:create", "wiki:node:read",
"wiki:space:read") to also include "wiki:wiki" or an appropriate drive-related
scope so AutoGrantCurrentUserDrivePermission(runtime, execution.Node.NodeToken,
"wiki") can successfully call POST
/open-apis/drive/v1/permissions/{token}/members and return a valid
permission_grant result.
- Around line 61-64: The bot note is overwriting the last per-call description
because dry.Desc(...) modifies d.calls[n-1].Desc via DryRunAPI.Desc; update the
DryRunAPI API by adding a new method (e.g., AddGlobalNote or AppendNote) that
stores notes in a separate field (extra map or notes slice) instead of mutating
calls[].Desc, then replace the call site in wiki_node_create.go (where
buildWikiNodeCreateDryRun(readWikiNodeCreateSpec(runtime)) returns and
dry.Desc(...) is invoked) to use the new AddGlobalNote/AppendNote method so the
final POST call description (e.g., "[N] Create wiki node") remains unchanged
while the bot note is preserved; apply the same change pattern to
shortcuts/drive/drive_create_folder.go.
In `@skills/lark-drive/references/lark-drive-create-folder.md`:
- Around line 28-35: Add documentation for the "created" boolean field in the
response contract: state that responses include "created": true on successful
folder creation (the implementation always returns true), and mention it is the
primary success indicator alongside fields like "folder_token", "url", "name",
"parent_folder_token", and optional "permission_grant"; update the response list
to include this "created" field and a brief note that it is always true on
success.
---
Nitpick comments:
In `@shortcuts/wiki/wiki_node_create_test.go`:
- Around line 521-525: Remove the unnecessary environment setup that calls
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) from tests that use
cmdutil.TestFactory (e.g., TestWikiNodeCreateBotAutoGrantSuccess and the similar
test around the other occurrence); TestFactory supplies an in-memory config and
does not read the filesystem, so delete the t.Setenv call to avoid noisy,
redundant test setup and leave the rest of the test and the
cmdutil.TestFactory(...) invocation intact.
🪄 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: b9e6c8be-0970-4d73-82ac-1420953caa22
📒 Files selected for processing (11)
shortcuts/drive/drive_create_folder.goshortcuts/drive/drive_create_folder_test.goshortcuts/drive/shortcuts.goshortcuts/drive/shortcuts_test.goshortcuts/wiki/wiki_node_create.goshortcuts/wiki/wiki_node_create_test.goskill-template/domains/drive.mdskills/lark-drive/SKILL.mdskills/lark-drive/references/lark-drive-create-folder.mdskills/lark-wiki/SKILL.mdskills/lark-wiki/references/lark-wiki-node-create.md
✅ Files skipped from review due to trivial changes (3)
- shortcuts/drive/shortcuts.go
- skills/lark-wiki/SKILL.md
- skill-template/domains/drive.md
🚧 Files skipped from review as they are similar to previous changes (3)
- shortcuts/drive/shortcuts_test.go
- skills/lark-drive/SKILL.md
- skills/lark-wiki/references/lark-wiki-node-create.md
Summary
Add a dedicated
drive +create-foldershortcut to improve Drive folder creation UX while keeping the existing rawfiles.create_folderAPI intact for compatibility. Also extendwiki +node-createto support the same bot-mode auto-grant behavior used by other create shortcuts, and update the related skill docs.Changes
drive +create-foldershortcut with root-folder fallback, bot auto-grant for the current CLI user, and shortcut registration/testswiki +node-create, including output/dry-run updates and testsskills/lark-driveandskills/lark-wikireferences to guide agents toward the new/preferred shortcutsTest Plan
lark xxxcommand works as expectedUnit tests run:
go test ./shortcuts/drive ./shortcuts/wikiRelated Issues
Summary by CodeRabbit
New Features
Documentation