Skip to content

feat(slides): support explicit screenshot output paths - #2180

Merged
BD-ZERO merged 6 commits into
mainfrom
feat/slides-screenshot-output-path
Aug 5, 2026
Merged

feat(slides): support explicit screenshot output paths#2180
BD-ZERO merged 6 commits into
mainfrom
feat/slides-screenshot-output-path

Conversation

@BD-ZERO

@BD-ZERO BD-ZERO commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add AI-friendly --output support to slides +screenshot, aligning single-image screenshots with other file-producing shortcuts while preserving the server-returned image format and avoiding normal name collisions.

Changes

  • Add --output <file> for exactly one screenshot in both existing-slide and XML render modes.
  • Reconcile .png, .jpg, and .jpeg extensions with the actual server response format before choosing the final path.
  • When the final path exists, save as _2, _3, and so on.
  • Return the original requested_output, actual absolute output, and output_adjusted: true whenever extension reconciliation or conflict avoidance changes the path.
  • Reject directory-like paths, leading/trailing whitespace, unsafe paths, and unsupported extensions before the API request.
  • Keep batch --output-dir output on the same conflict-avoidance naming rule.
  • Resolve the requested output path before the network request and reuse it when producing result metadata.
  • Update the Slides Skill, technical plan, unit tests, dry-run E2E, and live workflow coverage; no --overwrite flag is introduced.

Test Plan

  • GOTOOLCHAIN=go1.23.0 make build
  • GOTOOLCHAIN=go1.23.0 make unit-test
  • GOTOOLCHAIN=go1.23.0 make vet
  • GOTOOLCHAIN=go1.23.0 make fmt-check
  • GOTOOLCHAIN=go1.23.0 go mod tidy produces no changes
  • Incremental golangci-lint reports 0 issues
  • Slides dry-run E2E tests pass
  • Local CLI help and embedded Skill content expose the new contract

Related Issues

Summary by CodeRabbit

  • New Features

    • Save a single slide screenshot to a specific file with --output.
    • Continue saving multiple screenshots to a directory with --output-dir.
    • Automatically adjust extensions to match the selected image format.
    • Report actual output paths in command results and dry-run previews.
  • Bug Fixes

    • Added safeguards for invalid paths, conflicting options, overwrites, and incompatible selectors.
    • Improved naming and collision handling.
  • Documentation

    • Updated screenshot guidance and examples for file and directory output modes.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The slide screenshot shortcut adds single-file output through --output, format-aware extension handling, validation, collision handling, output metadata, documentation, unit tests, and end-to-end coverage.

Changes

Screenshot output handling

Layer / File(s) Summary
Output flags and validation
shortcuts/slides/slides_screenshot.go, shortcuts/slides/slides_screenshot_test.go
Adds output validation for selectors, naming flags, paths, and single-image responses.
Target resolution and image writing
shortcuts/slides/slides_screenshot.go
Resolves file or directory targets, adjusts extensions for PNG or JPEG responses, handles collisions, and reports actual paths.
Shortcut validation and behavior tests
shortcuts/slides/slides_screenshot_test.go
Tests fixed output paths, validation failures, extension correction, overwrite protection, render mode, dry-run metadata, and multi-image rejection.
Documentation and end-to-end coverage
skills/lark-slides/SKILL.md, skills/lark-slides/references/lark-slides-screenshot.md, tests/cli_e2e/slides/*
Documents output semantics and verifies normalized paths, response metadata, image formats, and dry-run requests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • larksuite/cli#2156: Modifies screenshot selector validation and execution paths in slides_screenshot.go.
  • larksuite/cli#2177: Modifies screenshot selector validation and related tests.

Suggested reviewers: ethan-zhx

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant ScreenshotShortcut
  participant ScreenshotAPI
  participant ImageWriter
  participant Filesystem
  CLI->>ScreenshotShortcut: Pass screenshot options
  ScreenshotShortcut->>ScreenshotAPI: Request selected slide image
  ScreenshotAPI-->>ScreenshotShortcut: Return image bytes and format
  ScreenshotShortcut->>ImageWriter: Resolve target and overwrite mode
  ImageWriter->>Filesystem: Write screenshot
  Filesystem-->>ImageWriter: Return actual path
  ImageWriter-->>ScreenshotShortcut: Return output metadata
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 clearly and concisely describes the main change: explicit screenshot output paths for Slides.
Description check ✅ Passed The description includes the required Summary, Changes, Test Plan, and Related Issues sections with detailed, relevant information.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/slides-screenshot-output-path

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.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/slides-screenshot-output-path -y -g

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.15385% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.87%. Comparing base (ebdeda8) to head (63cee60).

Files with missing lines Patch % Lines
shortcuts/slides/slides_screenshot.go 86.15% 11 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2180      +/-   ##
==========================================
+ Coverage   75.85%   75.87%   +0.01%     
==========================================
  Files         958      958              
  Lines      101701   101792      +91     
==========================================
+ Hits        77150    77239      +89     
+ Misses      18684    18681       -3     
- Partials     5867     5872       +5     

☔ View full report in Codecov by Harness.
📢 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.

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

🧹 Nitpick comments (1)
shortcuts/slides/slides_screenshot.go (1)

550-550: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Pass output routing as a typed value.

saveSlideScreenshotImage accepts outputDir, outputName, fallbackName, and outputPath as positional string values. A caller can swap these values without a compiler error. Pass slidesScreenshotOutputTarget, or a smaller dedicated write-target type, through the save helper chain.

As per coding guidelines, prefer distinct types when same-typed values could be silently swapped.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/slides/slides_screenshot.go` at line 550, Update
saveSlideScreenshotImage and its caller/helper chain to accept a typed
output-routing value, using slidesScreenshotOutputTarget or a smaller dedicated
write-target type instead of separate positional strings for outputDir,
outputName, fallbackName, and outputPath. Adjust all call sites and field access
accordingly so same-typed routing values cannot be accidentally swapped.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shortcuts/slides/slides_screenshot_test.go`:
- Around line 1281-1313: Update
shortcuts/slides/slides_screenshot_test.go:1281-1313 in
TestSlidesScreenshotOutputWritesRequestedRenderPath to request shots/preview.jpg
for the PNG response, then assert the PNG is written to shots/preview.png and
verify requested_output, output, output_adjusted, and omitted output_dir
metadata directly. Update shortcuts/slides/slides_screenshot_test.go:1456-1475
with a --content dry-run case using --output, asserting output is present and
output_dir is absent.
- Around line 564-597: Update
TestSlidesScreenshotOutputRejectsConflictingNamingFlags to assert the error’s
typed metadata with errs.ProblemOf, requiring errs.CategoryValidation and
errs.SubtypeInvalidArgument, while retaining the existing errors.As check for
ValidationError.Param and the conflict-message assertion.

In `@shortcuts/slides/slides_screenshot.go`:
- Around line 474-488: Reject outer whitespace in validateScreenshotOutputPath
with a typed --output validation error instead of trimming the value. In
shortcuts/slides/slides_screenshot.go lines 299-313, retain and use the original
requested value for path resolution and result metadata; in lines 284-288,
report that same unmodified value in dry-run output.
- Around line 763-783: Update writeScreenshotOutputPath and
writeUniqueScreenshotPath to use an atomic no-replace save whenever overwrite is
disabled, rather than relying only on the preceding Stat check. Treat an atomic
collision as an existing-file condition; in writeScreenshotOutputPath return the
existing validation error, while in writeUniqueScreenshotPath retry with the
next suffix. Preserve overwrite behavior and existing error handling for
non-collision failures.

In `@tests/cli_e2e/slides/slides_screenshot_workflow_test.go`:
- Around line 134-136: In the test flow around wantOutput, replace
filepath.EvalSymlinks with the existing internal/vfs EvalSymlinks API while
preserving the current error assertion and resolved-path behavior.

---

Nitpick comments:
In `@shortcuts/slides/slides_screenshot.go`:
- Line 550: Update saveSlideScreenshotImage and its caller/helper chain to
accept a typed output-routing value, using slidesScreenshotOutputTarget or a
smaller dedicated write-target type instead of separate positional strings for
outputDir, outputName, fallbackName, and outputPath. Adjust all call sites and
field access accordingly so same-typed routing values cannot be accidentally
swapped.
🪄 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 Plus

Run ID: ce1c0e3e-fba4-4570-bbc7-2dd1d3788e7f

📥 Commits

Reviewing files that changed from the base of the PR and between 3b66d47 and da6c8bb.

📒 Files selected for processing (6)
  • shortcuts/slides/slides_screenshot.go
  • shortcuts/slides/slides_screenshot_test.go
  • skills/lark-slides/SKILL.md
  • skills/lark-slides/references/lark-slides-screenshot.md
  • tests/cli_e2e/slides/slides_screenshot_dryrun_test.go
  • tests/cli_e2e/slides/slides_screenshot_workflow_test.go

Comment thread shortcuts/slides/slides_screenshot_test.go
Comment thread shortcuts/slides/slides_screenshot_test.go
Comment thread shortcuts/slides/slides_screenshot.go
Comment thread shortcuts/slides/slides_screenshot.go Outdated
Comment thread tests/cli_e2e/slides/slides_screenshot_workflow_test.go
Comment thread shortcuts/slides/slides_screenshot.go
@BD-ZERO
BD-ZERO force-pushed the feat/slides-screenshot-output-path branch from 7a48886 to a3a83a6 Compare August 5, 2026 03:45
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Comment thread shortcuts/slides/slides_screenshot.go

@fangshuyu-768 fangshuyu-768 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed the current head. No actionable findings; targeted Slides tests, race checks, vet, formatting, build, and dry-run E2E passed, and all required CI checks are green.

@BD-ZERO
BD-ZERO merged commit 7363eb5 into main Aug 5, 2026
27 checks passed
@BD-ZERO
BD-ZERO deleted the feat/slides-screenshot-output-path branch August 5, 2026 08:50
@liangshuo-1 liangshuo-1 mentioned this pull request Aug 5, 2026
3 tasks
zkh-bytedance pushed a commit that referenced this pull request Aug 6, 2026
Adds AI-friendly output path handling to `slides +screenshot`.

- Supports `--output` for a single screenshot in both existing-slide and XML render modes.
- Validates selector count, conflicting output flags, unsafe paths, directories, whitespace, and unsupported extensions with structured errors.
- Reconciles the requested filename with the server’s actual PNG/JPEG format and reports the final path through `output`, `requested_output`, and `output_adjusted`.
- Avoids replacing existing screenshots by appending `_2`, `_3`, and subsequent suffixes.
- Keeps `--output-dir` for multi-page screenshots and preserves `--output-name` for render mode.
- Updates the Slides Skill with explicit `--slide-number` / `--slide-id` guidance and task-scoped screenshot directories.
- Adds unit, dry-run E2E, and live workflow coverage for validation, path handling, format adjustment, and collision behavior.

Co-authored-by: TRAE CLI <traecli@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants