Skip to content

feat: add drive create-folder shortcut and wiki node auto-grant#470

Merged
fangshuyu-768 merged 1 commit intomainfrom
feat/drive-create-folder-wiki-node-auto-grant
Apr 16, 2026
Merged

feat: add drive create-folder shortcut and wiki node auto-grant#470
fangshuyu-768 merged 1 commit intomainfrom
feat/drive-create-folder-wiki-node-auto-grant

Conversation

@wittam-01
Copy link
Copy Markdown
Collaborator

@wittam-01 wittam-01 commented Apr 14, 2026

Summary

Add a dedicated drive +create-folder shortcut to improve Drive folder creation UX while keeping the existing raw files.create_folder API intact for compatibility. Also extend wiki +node-create to support the same bot-mode auto-grant behavior used by other create shortcuts, and update the related skill docs.

Changes

  • Add drive +create-folder shortcut with root-folder fallback, bot auto-grant for the current CLI user, and shortcut registration/tests
  • Add bot-mode auto-grant support to wiki +node-create, including output/dry-run updates and tests
  • Update skills/lark-drive and skills/lark-wiki references to guide agents toward the new/preferred shortcuts

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark xxx command works as expected

Unit tests run:

  • go test ./shortcuts/drive ./shortcuts/wiki

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added lark-cli drive +create-folder to create cloud folders with optional parent placement
    • CLI now may auto-grant the current user permissions when creating folders or wiki nodes in bot mode
  • Documentation

    • Added usage reference and examples for the new folder command
    • Updated wiki node docs to describe permission-grant behavior and output fields

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

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

coderabbitai Bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

This PR adds a new Drive shortcut DriveCreateFolder to create Drive folders (optional --folder-token parent), validates --name and --folder-token, supports --dry-run, and in --as bot mode attempts to auto-grant the current CLI user permissions. It also augments Wiki node creation to surface similar permission-grant results and includes tests and docs.

Changes

Cohort / File(s) Summary
Drive Create Folder Shortcut
shortcuts/drive/drive_create_folder.go, shortcuts/drive/drive_create_folder_test.go
New DriveCreateFolder shortcut with request spec, validation (name ≤256 bytes, non-empty), dry-run and Execute POST to /open-apis/drive/v1/files/create_folder, and conditional bot-mode auto-grant. Tests cover validation, dry-run payload, bot and user execution, missing token error.
Drive Shortcut Registry
shortcuts/drive/shortcuts.go, shortcuts/drive/shortcuts_test.go
Inserted DriveCreateFolder into Shortcuts() and updated tests to expect +create-folder.
Wiki Node Creation Enhancement
shortcuts/wiki/wiki_node_create.go, shortcuts/wiki/wiki_node_create_test.go
Dry-run and Execute updated to include bot-mode permission-grant messaging; added augmentWikiNodeCreateOutput() to attach permission_grant from AutoGrantCurrentUserDrivePermission; added tests for nil-node error, bot grant, user-mode skip, and augmentation behavior.
Documentation & Skills
skill-template/domains/drive.md, skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-create-folder.md, skills/lark-wiki/SKILL.md, skills/lark-wiki/references/lark-wiki-node-create.md
Added docs and quick-decision rules for drive +create-folder and updated wiki docs to describe optional permission_grant in bot mode and usage examples.

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?)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • liujinkun2025
  • fangshuyu-768

Poem

🐰 A tiny folder seeds with care,
Name trimmed and placed with gentle flair,
Bot hops in, grants keys with cheer,
Cloud paths grow, the user near —
Hooray, another home appears!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: adding a drive create-folder shortcut and extending wiki node creation with auto-grant functionality.
Description check ✅ Passed The description includes all required template sections with substantive content: Summary explaining motivation, comprehensive Changes list, Test Plan with status, and Related Issues reference.

✏️ 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-create-folder-wiki-node-auto-grant

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
Copy link
Copy Markdown

github-actions Bot commented Apr 14, 2026

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/drive-create-folder-wiki-node-auto-grant -y -g

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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 20761fa and 7bb99e5.

📒 Files selected for processing (11)
  • shortcuts/drive/drive_create_folder.go
  • shortcuts/drive/drive_create_folder_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • shortcuts/wiki/wiki_node_create.go
  • shortcuts/wiki/wiki_node_create_test.go
  • skill-template/domains/drive.md
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-create-folder.md
  • skills/lark-wiki/SKILL.md
  • skills/lark-wiki/references/lark-wiki-node-create.md

Comment thread shortcuts/drive/drive_create_folder.go
Comment thread shortcuts/wiki/wiki_node_create.go Outdated
Comment thread skills/lark-drive/references/lark-drive-create-folder.md
Change-Id: I1acd001a1d4616bc5a957cad437e5aa4f1afeb51
@wittam-01 wittam-01 force-pushed the feat/drive-create-folder-wiki-node-auto-grant branch from 7bb99e5 to 70cc9ff Compare April 16, 2026 02:44
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: 5

🧹 Nitpick comments (1)
shortcuts/wiki/wiki_node_create_test.go (1)

521-525: Drop the redundant config-dir env setup in these TestFactory tests.

These cases already use cmdutil.TestFactory(t, ...), so forcing LARKSUITE_CLI_CONFIG_DIR adds noise without affecting behavior.

Based on learnings: Shortcut tests that build the CLI via cmdutil.TestFactory(t, config) should not set this env var because TestFactory provides 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7bb99e5 and 70cc9ff.

📒 Files selected for processing (11)
  • shortcuts/drive/drive_create_folder.go
  • shortcuts/drive/drive_create_folder_test.go
  • shortcuts/drive/shortcuts.go
  • shortcuts/drive/shortcuts_test.go
  • shortcuts/wiki/wiki_node_create.go
  • shortcuts/wiki/wiki_node_create_test.go
  • skill-template/domains/drive.md
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-create-folder.md
  • skills/lark-wiki/SKILL.md
  • skills/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

Comment thread shortcuts/drive/drive_create_folder.go
Comment thread shortcuts/drive/drive_create_folder.go
Comment thread shortcuts/wiki/wiki_node_create.go
Comment thread shortcuts/wiki/wiki_node_create.go
Comment thread skills/lark-drive/references/lark-drive-create-folder.md
@fangshuyu-768 fangshuyu-768 merged commit 9dfaff4 into main Apr 16, 2026
16 checks passed
@fangshuyu-768 fangshuyu-768 deleted the feat/drive-create-folder-wiki-node-auto-grant branch April 16, 2026 03:19
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.

2 participants