Skip to content

feat(sheets): add undo shortcut - #1715

Open
zhengzhijiej-tech wants to merge 7 commits into
mainfrom
feat/sheets-undo-shortcut-zzj
Open

feat(sheets): add undo shortcut#1715
zhengzhijiej-tech wants to merge 7 commits into
mainfrom
feat/sheets-undo-shortcut-zzj

Conversation

@zhengzhijiej-tech

@zhengzhijiej-tech zhengzhijiej-tech commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add lark-cli sheets +undo as a user-only shortcut.
  • Route it through the sheet AI undo_last write tool with excel_id as the only input.
  • Register the shortcut metadata and generated flag definitions.
  • Add dry-run and execute-path tests for the request contract.

Verification

  • go test -count=1 ./shortcuts/sheets/...
  • ./build.sh
  • Ran a development-environment smoke test: create a spreadsheet, write A1, run sheets +undo, verify A1 is cleared, then run sheets +undo again and verify the empty-stack response.

Summary by CodeRabbit

  • New Features
    • Added a +undo shortcut to undo the calling user’s latest AI-generated spreadsheet write(s).
    • Supports targeting via spreadsheet URL or spreadsheet token; allows --count (1–20) for multi-step undo.
    • High-risk action requires --yes; supports --dry-run to preview the operation.
  • Documentation
    • Updated Sheets history references and examples to explain +undo behavior, limits, and how it differs from version rollback.
  • Tests
    • Added end-to-end CLI tests for +undo, including dry-run, request payload verification, --count validation, confirmation gating, and output mapping.

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cecf0db6-0e45-4b1f-82f9-e6a9effd97b9

📥 Commits

Reviewing files that changed from the base of the PR and between 5d1a5ee and 10363e0.

📒 Files selected for processing (5)
  • shortcuts/sheets/data/flag-defs.json
  • shortcuts/sheets/flag_defs_gen.go
  • shortcuts/sheets/lark_sheet_undo.go
  • shortcuts/sheets/lark_sheet_undo_test.go
  • shortcuts/sheets/shortcuts.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • shortcuts/sheets/flag_defs_gen.go
  • shortcuts/sheets/shortcuts.go
  • shortcuts/sheets/lark_sheet_undo.go
  • shortcuts/sheets/data/flag-defs.json
  • shortcuts/sheets/lark_sheet_undo_test.go

📝 Walkthrough

Walkthrough

Adds a registered +undo Sheets shortcut with spreadsheet locator, count, and dry-run flags. It invokes the undo_last write tool, validates counts from 1–20, tests execution and failure outputs, and documents user-scoped undo behavior and examples.

Changes

Sheets undo shortcut

Layer / File(s) Summary
Undo contract and registration
shortcuts/sheets/data/flag-defs.json, shortcuts/sheets/flag_defs_gen.go, shortcuts/sheets/shortcuts.go
Defines and registers +undo with spreadsheet locator flags, --count, --dry-run, and write-risk metadata.
Undo execution flow
shortcuts/sheets/lark_sheet_undo.go
Adds count validation, spreadsheet token resolution, consistent undo_last inputs, and separate dry-run and execute paths.
Validation and usage coverage
shortcuts/sheets/lark_sheet_undo_test.go, skills/lark-sheets/SKILL.md, skills/lark-sheets/references/lark-sheets-history.md
Tests request construction, confirmation, execution results, validation, and failure reasons; documents behavior, flags, constraints, and examples.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Runtime
  participant Undo
  participant undo_last
  Runtime->>Undo: invoke +undo with spreadsheet locator and count
  Undo->>Undo: validate count and resolve spreadsheet token
  Undo->>undo_last: send excel_id and count
  undo_last-->>Runtime: return undo result
Loading

Suggested reviewers: fangshuyu-768

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: adding the sheets undo shortcut.
Description check ✅ Passed It covers the main summary, changes, and verification details, with only minor template gaps like the missing Related Issues section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sheets-undo-shortcut-zzj

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 added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact size/L Large or sensitive change across domains or core paths and removed size/M Single-domain feat or fix with limited business impact labels Jul 2, 2026
@zhengzhijiej-tech
zhengzhijiej-tech force-pushed the feat/sheets-undo-shortcut-zzj branch 2 times, most recently from 572c324 to d48bf26 Compare July 7, 2026 03:26
@wenzhuozhen
wenzhuozhen force-pushed the feat/lark-sheets-develop branch 2 times, most recently from 9f93cce to 74d65e6 Compare July 13, 2026 08:05
@zhengzhijiej-tech
zhengzhijiej-tech force-pushed the feat/lark-sheets-develop branch from 5d9cb51 to 31a8b47 Compare July 13, 2026 08:43
Base automatically changed from feat/lark-sheets-develop to main July 13, 2026 13:29
@github-actions github-actions Bot added size/XL Architecture-level or global-impact change and removed size/L Large or sensitive change across domains or core paths labels Jul 13, 2026
@zhengzhijiej-tech
zhengzhijiej-tech force-pushed the feat/sheets-undo-shortcut-zzj branch from d48bf26 to 42870f0 Compare July 14, 2026 03:10
@github-actions github-actions Bot added size/M Single-domain feat or fix with limited business impact and removed size/XL Architecture-level or global-impact change labels Jul 14, 2026

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shortcuts/sheets/lark_sheet_undo_test.go`:
- Around line 77-79: Replace the substring-only assertion in the relevant
error-path test with structured checks using errs.ProblemOf: require a typed
problem with errs.SubtypeInvalidArgument, then use errors.As to require
*errs.ValidationError and validate its Param against the expected count
parameter. Preserve the existing precise-message check only if needed, and
verify the wrapped cause as required by the test guideline; add imports for
errors and errs if missing.
🪄 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: 69cc976a-a77a-404a-a3e6-8dc3c153e479

📥 Commits

Reviewing files that changed from the base of the PR and between 37d490a and 42870f0.

📒 Files selected for processing (7)
  • shortcuts/sheets/data/flag-defs.json
  • shortcuts/sheets/flag_defs_gen.go
  • shortcuts/sheets/lark_sheet_undo.go
  • shortcuts/sheets/lark_sheet_undo_test.go
  • shortcuts/sheets/shortcuts.go
  • skills/lark-sheets/SKILL.md
  • skills/lark-sheets/references/lark-sheets-history.md

Comment on lines +77 to +79
if !strings.Contains(err.Error(), tt.wantSub) {
t.Fatalf("unexpected error: %v", err)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Assert typed metadata for error paths.

The test uses strings.Contains to assert the error, which violates the **/*_test.go coding guideline: "Error-path tests must assert typed metadata via errs.ProblemOf (category / subtype / param) and cause preservation, not message substrings alone."

Please update the assertion to verify the typed Subtype (e.g., errs.SubtypeInvalidArgument) and the Param (using errors.As(err, &ve) for validation errors). As per coding guidelines, Error-path tests must assert typed metadata via errs.ProblemOf (category / subtype / param) and cause preservation, not message substrings alone.

🛠️ Proposed fix

Replace the substring check with a structured assertion:

			p, ok := errs.ProblemOf(err)
			if !ok {
				t.Fatalf("expected typed error, got: %v", err)
			}
			if p.Subtype != errs.SubtypeInvalidArgument {
				t.Errorf("Subtype = %v, want %v", p.Subtype, errs.SubtypeInvalidArgument)
			}

			var ve *errs.ValidationError
			if errors.As(err, &ve) {
				if ve.Param != "count" && ve.Param != "--count" {
					t.Errorf("Param = %q, want count or --count", ve.Param)
				}
			} else {
				t.Errorf("expected *errs.ValidationError")
			}

			// Keep the substring assertion to ensure the precise guidance message matches.
			if !strings.Contains(err.Error(), tt.wantSub) {
				t.Fatalf("unexpected error: %v", err)
			}

(Note: Ensure that "errors" and "github.com/larksuite/cli/internal/errs" are added to the file's imports if not already present.)

🤖 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/sheets/lark_sheet_undo_test.go` around lines 77 - 79, Replace the
substring-only assertion in the relevant error-path test with structured checks
using errs.ProblemOf: require a typed problem with errs.SubtypeInvalidArgument,
then use errors.As to require *errs.ValidationError and validate its Param
against the expected count parameter. Preserve the existing precise-message
check only if needed, and verify the wrapped cause as required by the test
guideline; add imports for errors and errs if missing.

Source: Coding guidelines

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.66%. Comparing base (37d490a) to head (42870f0).

Files with missing lines Patch % Lines
shortcuts/sheets/lark_sheet_undo.go 73.91% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1715   +/-   ##
=======================================
  Coverage   74.66%   74.66%           
=======================================
  Files         877      878    +1     
  Lines       91731    91755   +24     
=======================================
+ Hits        68494    68512   +18     
- Misses      17926    17929    +3     
- Partials     5311     5314    +3     

☔ 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.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/sheets-undo-shortcut-zzj -y -g

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Quality Summary

CI did not complete successfully. Use the failed check links below to decide whether this PR needs a code change or a rerun.

Failed checks

@zhengzhijiej-tech
zhengzhijiej-tech force-pushed the feat/sheets-undo-shortcut-zzj branch from 88c22ff to 5d1a5ee Compare July 17, 2026 08:25
@zhengzhijiej-tech
zhengzhijiej-tech force-pushed the feat/sheets-undo-shortcut-zzj branch from 5d1a5ee to 10363e0 Compare July 28, 2026 08:30
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/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant