Skip to content

feat(task): add upload task attachment shortcut#736

Merged
zero-my merged 2 commits into
larksuite:mainfrom
bytedance-zxy:feat-task-attachment
May 6, 2026
Merged

feat(task): add upload task attachment shortcut#736
zero-my merged 2 commits into
larksuite:mainfrom
bytedance-zxy:feat-task-attachment

Conversation

@bytedance-zxy

@bytedance-zxy bytedance-zxy commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new task +upload-attachment shortcut that uploads a single local file as an attachment to a task (or other resource type supported by the Task attachment endpoint), wrapping the POST /open-apis/task/v2/attachments/upload multipart API.

Motivation

The Task service exposes an attachment upload endpoint that was not yet reachable via the CLI, forcing agents and users to hand-craft multipart requests. Adding it as a first-class shortcut lets AI agents and humans attach files to tasks through the same structured pipeline used by other Task shortcuts.

Changes

  • New shortcut task_upload_attachment.go implementing the Shortcut contract:
    • Flags: --resource-id (task GUID or applink URL), --file (local path, ≤ 50MB), --resource-type (default task ), --user-id-type (default open_id ).
    • Accepts either a raw task GUID or a task applink URL for --resource-id and normalizes it.
    • Enforces the 50MB single-file limit documented by the open API before streaming the upload.
    • Emits structured errors via output.* and uses vfs / path validation for safe file I/O.
    • Supports --dry-run with a DryRunAPI describing method, path, params, and multipart body.
  • Registered the shortcut in shortcuts.go .
  • Unit tests in task_upload_attachment_test.go covering flag validation, applink parsing, size-limit enforcement, request construction, and error paths.
  • Dry-run E2E in task_upload_attachment_dryrun_test.go asserting method, URL, params, and multipart fields.
  • Skill docs: updated SKILL.md and new reference lark-task-upload-attachment.md so the lark-task skill exposes the new capability to agents.
  • Spec artifacts under .trae/specs/feat-task-attachment/ (spec, tasks, checklist) documenting scope and acceptance criteria.

Summary by CodeRabbit

  • New Features

    • Added a task attachment upload command that accepts a task GUID or applink, uploads local files up to 50 MB, and prints a success summary including attachment ID.
    • Supports a dry-run mode that shows the planned API request and file metadata.
  • Documentation

    • Added reference docs and updated skill metadata/permissions for the upload command.
  • Tests

    • Added unit and end-to-end tests covering success, error cases, size limits, applink resolution, and dry-run output.

Change-Id: I668bf3d856baa6e35ed982a33c4bf4d03b924f4b
@github-actions github-actions Bot added domain/task PR touches the task domain size/L Large or sensitive change across domains or core paths labels Apr 30, 2026
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8ff08794-25e0-47a3-b984-eb9dc81464be

📥 Commits

Reviewing files that changed from the base of the PR and between 026558d and a944e97.

📒 Files selected for processing (2)
  • shortcuts/task/task_upload_attachment.go
  • skills/lark-task/references/lark-task-upload-attachment.md

📝 Walkthrough

Walkthrough

Adds a new CLI shortcut +upload-attachment to upload a local file (≤50MB) as a task attachment, a helper to normalize task GUID inputs, unit and e2e tests for dry-run and runtime behavior, and documentation/skill metadata describing the command and required scope.

Changes

Upload attachment shortcut

Layer / File(s) Summary
Data / Helpers
shortcuts/task/shortcuts.go
Adds extractTaskGuid(input string) string to normalize task GUIDs from raw GUIDs or applink URLs.
Core Implementation
shortcuts/task/task_upload_attachment.go
Adds UploadAttachmentTask shortcut with DryRun and Execute handlers; validates file existence/type/≤50MB, builds multipart/form-data preserving filename, streams POST to /open-apis/task/v2/attachments/upload, parses JSON response, extracts first attachment record, logs and emits summary output; covers error paths.
Unit Tests
shortcuts/task/task_upload_attachment_test.go
Adds comprehensive tests covering success (pretty/json), explicit resource_type, resource_id from applink, size limit (sparse file), missing file, API error, dry-run output; includes test helpers to write files and decode multipart bodies.
E2E Dry-Run Test
tests/cli_e2e/task/task_upload_attachment_dryrun_test.go
Adds CLI e2e test exercising --dry-run in multiple variants, asserting one planned POST to /open-apis/task/v2/attachments/upload with correct params and file metadata.
Docs / Skill Metadata
skills/lark-task/SKILL.md, skills/lark-task/references/lark-task-upload-attachment.md
Adds +upload-attachment to skill shortcuts and permissions table; adds reference doc describing usage, params, workflow, size limit, and output format.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant FS as File System
    participant Builder as Request Builder
    participant HTTP as HTTP Client
    participant API as Task API
    participant Handler as Response Handler

    User->>CLI: task +upload-attachment --resource-id=ID --file=path
    CLI->>CLI: validate inputs (exists, regular file, ≤50MB)
    CLI->>FS: open/read file stream
    FS-->>CLI: file stream
    CLI->>Builder: build multipart (resource_type, resource_id, file with real filename)
    Builder-->>CLI: multipart request
    CLI->>HTTP: POST /open-apis/task/v2/attachments/upload (stream)
    HTTP->>API: deliver multipart payload
    API-->>HTTP: JSON response
    HTTP-->>CLI: response bytes
    CLI->>Handler: parse and handle API result
    Handler-->>CLI: attachment record (guid, name, size)
    CLI-->>User: success summary (resource, file name, size, guid)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • larksuite/cli#377: Modifies shortcuts/task/shortcuts.go Shortcuts registration (related change adding task shortcuts).

Suggested reviewers

  • zero-my
  • tengchengwei

Poem

🐰 I found a file beside the trail,
I hopped it up and sent its tale,
Fifty megabytes, not a byte more,
GUIDs arrive — attachments soar! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% 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
Title check ✅ Passed The title 'feat(task): add upload task attachment shortcut' directly and clearly summarizes the main change: adding a new upload attachment shortcut to the task CLI feature.
Description check ✅ Passed The description is comprehensive and well-structured, covering motivation, changes, test coverage (unit and E2E tests, dry-run), and documentation updates with clear detail about implementation specifics.
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.

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

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 `@skills/lark-task/references/lark-task-upload-attachment.md`:
- Around line 48-52: Remove the empty blank line between the two blockquote
sections so the blockquotes using "[!CAUTION]" and "[!NOTE]" are consecutive
lines without an intervening blank line; specifically edit the block containing
"> [!CAUTION] ... " and "> [!NOTE] ..." to delete the blank line that triggers
markdownlint MD028 (no-blanks-blockquote) so both blockquotes are back-to-back.
🪄 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: 43ff6aba-e52a-4dd7-b9cf-30c664dab4b9

📥 Commits

Reviewing files that changed from the base of the PR and between ac4c34f and 026558d.

📒 Files selected for processing (6)
  • shortcuts/task/shortcuts.go
  • shortcuts/task/task_upload_attachment.go
  • shortcuts/task/task_upload_attachment_test.go
  • skills/lark-task/SKILL.md
  • skills/lark-task/references/lark-task-upload-attachment.md
  • tests/cli_e2e/task/task_upload_attachment_dryrun_test.go

Comment thread skills/lark-task/references/lark-task-upload-attachment.md
Change-Id: I3ef1aba33ee22e8b03e6f59bc2fb64f55a742270
@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.91729% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.98%. Comparing base (ac4c34f) to head (a944e97).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/task/task_upload_attachment.go 66.15% 27 Missing and 17 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #736      +/-   ##
==========================================
+ Coverage   64.57%   64.98%   +0.41%     
==========================================
  Files         516      503      -13     
  Lines       45749    46357     +608     
==========================================
+ Hits        29541    30125     +584     
+ Misses      13623    13605      -18     
- Partials     2585     2627      +42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add bytedance-zxy/cli#feat-task-attachment -y -g

@zero-my
zero-my merged commit 0627541 into larksuite:main May 6, 2026
19 checks passed
HomyeeKing pushed a commit to HomyeeKing/cli that referenced this pull request May 6, 2026
* feat(task): add upload task attachment shortcut

Change-Id: I668bf3d856baa6e35ed982a33c4bf4d03b924f4b

* feat(task): update SKILL.md adding resource_type description

Change-Id: I3ef1aba33ee22e8b03e6f59bc2fb64f55a742270
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
* feat(task): add upload task attachment shortcut

Change-Id: I668bf3d856baa6e35ed982a33c4bf4d03b924f4b

* feat(task): update SKILL.md adding resource_type description

Change-Id: I3ef1aba33ee22e8b03e6f59bc2fb64f55a742270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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