Skip to content

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

Open
bytedance-zxy wants to merge 1 commit intolarksuite:mainfrom
bytedance-zxy:feat-task-attachment
Open

feat(task): add upload task attachment shortcut#736
bytedance-zxy wants to merge 1 commit intolarksuite:mainfrom
bytedance-zxy:feat-task-attachment

Conversation

@bytedance-zxy
Copy link
Copy Markdown
Contributor

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

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 task attachment upload command supporting local file uploads up to 50MB per file.
  • Documentation

    • Added reference documentation for the task attachment upload command with usage examples and prerequisites.

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

coderabbitai Bot commented Apr 30, 2026

📝 Walkthrough

Walkthrough

A new CLI shortcut +upload-attachment is introduced to upload files as task attachments, with a supporting helper function to normalize task GUID inputs. The feature includes comprehensive tests and documentation describing the upload workflow, size limits, and API integration.

Changes

Cohort / File(s) Summary
Core Implementation
shortcuts/task/shortcuts.go, shortcuts/task/task_upload_attachment.go
Adds extractTaskGuid helper for normalizing GUID inputs from raw values or applink URLs, and implements the UploadAttachmentTask shortcut with multipart form upload, 50MB size validation, file I/O handling, and response parsing via task API result handler.
Unit Tests
shortcuts/task/task_upload_attachment_test.go
Seven test scenarios covering successful uploads, resource type/ID passthrough, applink GUID extraction, size limit enforcement, file validation errors, API errors, and dry-run output; includes helpers for test file generation and multipart body decoding.
E2E Tests
tests/cli_e2e/task/task_upload_attachment_dryrun_test.go
End-to-end test for --dry-run mode verifying correct HTTP request construction including method, URL, params, and multipart body fields across default and customized input scenarios.
Documentation
skills/lark-task/SKILL.md, skills/lark-task/references/lark-task-upload-attachment.md
Skill metadata extended to describe attachment uploading capability; new reference document specifies parameters, prerequisites, workflow steps, validation rules, and expected output format.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI
    participant FileSystem as File System
    participant RequestBuilder as Request Builder
    participant HTTPClient as HTTP Client
    participant API as Task API
    participant ResponseHandler as Response Handler

    User->>CLI: task +upload-attachment --resource-id=ID --file=path
    CLI->>CLI: Validate inputs (size ≤ 50MB, file exists)
    CLI->>FileSystem: Read file
    FileSystem-->>CLI: File bytes
    CLI->>RequestBuilder: Build multipart form data
    RequestBuilder->>RequestBuilder: Add resource_type, resource_id, file
    RequestBuilder-->>CLI: Multipart request
    CLI->>HTTPClient: POST /open-apis/task/v2/attachments/upload
    HTTPClient->>API: Stream multipart payload
    API-->>HTTPClient: JSON response {data: {items: [...]}}
    HTTPClient-->>CLI: Response bytes
    CLI->>ResponseHandler: Handle API result
    ResponseHandler-->>CLI: Parsed attachment record
    CLI-->>User: Success message with attachment GUID, name, size
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

domain/task, size/L

Suggested reviewers

  • LuckyTerry
  • liangshuo-1
  • tengchengwei

Poem

🐰 With whiskers twitching, files now soar,
Attachments hop through task-api doors,
Fifty megs per hop, so neat and right,
GUIDs extracted from URLs bright! ✨

🚥 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 pull request title accurately and clearly summarizes the main change: adding a new upload task attachment shortcut to the CLI.
Description check ✅ Passed The pull request description covers all required template sections: Summary, Changes, Test Plan (with checkboxes for unit and manual testing), and Related Issues. The description is comprehensive and well-structured.
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

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

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 `@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 on lines +48 to +52
> [!CAUTION]
> This is a **Write Operation** -- You must confirm the user's intent before executing.

> [!NOTE]
> The Task attachment upload endpoint accepts exactly one file per call. To upload multiple files, invoke the shortcut once per file.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix markdownlint MD028 in adjacent blockquotes.

There is a blank line between blockquote sections that triggers no-blanks-blockquote and may break docs lint checks.

✏️ Proposed fix
 > [!CAUTION]
 > This is a **Write Operation** -- You must confirm the user's intent before executing.
-
 > [!NOTE]
 > The Task attachment upload endpoint accepts exactly one file per call. To upload multiple files, invoke the shortcut once per file.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
> [!CAUTION]
> This is a **Write Operation** -- You must confirm the user's intent before executing.
> [!NOTE]
> The Task attachment upload endpoint accepts exactly one file per call. To upload multiple files, invoke the shortcut once per file.
> [!CAUTION]
> This is a **Write Operation** -- You must confirm the user's intent before executing.
> [!NOTE]
> The Task attachment upload endpoint accepts exactly one file per call. To upload multiple files, invoke the shortcut once per file.
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 50-50: Blank line inside blockquote

(MD028, no-blanks-blockquote)

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

In `@skills/lark-task/references/lark-task-upload-attachment.md` around lines 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.

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.

1 participant