Skip to content

feat: add markdown +patch shortcut#857

Merged
wittam-01 merged 2 commits into
mainfrom
feat/markdown-patch
May 18, 2026
Merged

feat: add markdown +patch shortcut#857
wittam-01 merged 2 commits into
mainfrom
feat/markdown-patch

Conversation

@wittam-01

@wittam-01 wittam-01 commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a new markdown +patch shortcut that updates a Markdown file in Drive via a fetch-local-replace-overwrite flow, enabling targeted edits without rewriting the entire file. Supports both literal and RE2 regex matching modes.

Changes

  • Add shortcuts/markdown/markdown_patch.go implementing the markdown +patch command and register it in shortcuts/markdown/shortcuts.go
  • Extract shared file-name resolution and overwrite-upload helpers into shortcuts/markdown/helpers.go and refactor markdown_overwrite.go to reuse them
  • Add unit tests in markdown_patch_test.go covering literal/regex modes, zero-match skip-upload, and flag validation
  • Add dry-run and workflow E2E cases under tests/cli_e2e/markdown/
  • Update README, lark-markdown skill docs, and add skills/lark-markdown/references/lark-markdown-patch.md

Test Plan

  • Unit tests pass (make unit-test)
  • Manual local verification confirms the lark markdown +patch command works as expected (literal, regex, and zero-match scenarios)

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added markdown +patch: local literal or RE2 regex edits for Drive-native .md files; reports match_count, only uploads when matches > 0, and rejects edits that would produce an empty file.
  • Documentation

    • Skill bumped to v1.1.0 and docs (EN/CN/skill refs) updated with patch semantics, flags, examples, dry-run behavior, and JSON response fields; README updated.
  • Tests

    • Added unit and e2e tests covering validation, literal/regex modes, dry-run, and lifecycle patching.

Review Change Stack

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label May 13, 2026
@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16479c31-b580-445f-ac7a-703155708ab2

📥 Commits

Reviewing files that changed from the base of the PR and between 4d98eec and 5bdc520.

📒 Files selected for processing (8)
  • shortcuts/common/extract.go
  • shortcuts/common/extract_test.go
  • shortcuts/markdown/helpers.go
  • shortcuts/markdown/markdown_patch.go
  • shortcuts/markdown/markdown_patch_test.go
  • skills/lark-markdown/SKILL.md
  • skills/lark-markdown/references/lark-markdown-patch.md
  • tests/cli_e2e/markdown/markdown_dryrun_test.go
✅ Files skipped from review due to trivial changes (2)
  • skills/lark-markdown/SKILL.md
  • skills/lark-markdown/references/lark-markdown-patch.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/cli_e2e/markdown/markdown_dryrun_test.go
  • shortcuts/markdown/helpers.go
  • shortcuts/markdown/markdown_patch.go
  • shortcuts/markdown/markdown_patch_test.go

📝 Walkthrough

Walkthrough

Adds markdown +patch (literal and regex modes) that downloads a Drive-native .md, performs local replacement, and conditionally overwrites; extracts filename/download/size helpers; registers the command; adds unit and e2e tests; and updates README and skill docs (bump to v1.1.0).

Changes

Markdown Patch Feature

Layer / File(s) Summary
Helper utilities for markdown operations
shortcuts/markdown/helpers.go, shortcuts/markdown/markdown_overwrite.go
Extract resolveMarkdownOverwriteFileName and openMarkdownDownload; add context import; centralize zero-size validation and refactor MarkdownOverwrite.Execute to call the resolver.
Patch command implementation
shortcuts/markdown/markdown_patch.go
Add exported MarkdownPatch shortcut with flags (--file-token, --pattern, --content, --regex), validation (including RE2 compile), DryRun plan enumerating download/metadata/upload steps, Execute flow (download → apply literal/regex replacement → upload only if matches), and JSON envelope output (updated, mode, match_count, version, size_bytes_before/after).
Command registration and wiring
shortcuts/markdown/shortcuts.go, shortcuts/markdown/markdown_test.go
Register MarkdownPatch in Shortcuts() and update tests to expect +patch among markdown commands.
Unit tests for patch command
shortcuts/markdown/markdown_patch_test.go
Add validation tests, no-match behavior, literal overwrite, regex overwrite (capture substitution), allow empty replacement (deletion), reject empty final content, and decodeMarkdownEnvelope helper.
End-to-end tests
tests/cli_e2e/markdown/markdown_dryrun_test.go, tests/cli_e2e/markdown/markdown_workflow_test.go
Add TestMarkdownPatchDryRun_Content to validate API orchestration (including multipart upload steps); extend lifecycle workflow to include patch-and-verify step.
Common helper
shortcuts/common/extract.go, shortcuts/common/extract_test.go
Add GetInt helper to safely extract ints from nested map[string]interface{} and accompanying unit test.
Feature documentation
README.md, README.zh.md, skills/lark-drive/SKILL.md, skills/lark-drive/references/lark-drive-upload.md, skills/lark-markdown/SKILL.md, skills/lark-markdown/references/lark-markdown-patch.md
Update README tables and skills to list patch; bump lark-markdown version to 1.1.0; refine quick-decision guidance to route native .md patch/overwrite to lark-markdown; add comprehensive lark-markdown patch reference.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#704: Foundation for markdown overwrite helpers and filename resolution reused by this patch implementation.

Suggested labels

domain/ccm, feature

Suggested reviewers

  • fangshuyu-768

🐰 A markdown patch hops into Drive,

Finds TODOs and makes them come alive.
Literal swaps or RE2 delight,
Download, replace, upload when it's right.
A little rabbit clap for files made bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 PR title 'feat: add markdown +patch shortcut' clearly and concisely describes the main change: introducing a new markdown patch command.
Description check ✅ Passed The PR description covers all required template sections: Summary (motivation and scope), Changes (main changes listed), Test Plan (with checkboxes), and Related Issues. All sections are substantive and complete.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/markdown-patch

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.

@codecov

codecov Bot commented May 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.63158% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.80%. Comparing base (2419524) to head (5bdc520).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/markdown/markdown_patch.go 93.15% 5 Missing and 5 partials ⚠️
shortcuts/common/extract.go 85.71% 1 Missing and 1 partial ⚠️
shortcuts/markdown/helpers.go 92.30% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #857      +/-   ##
==========================================
+ Coverage   66.47%   66.80%   +0.32%     
==========================================
  Files         562      564       +2     
  Lines       51871    52465     +594     
==========================================
+ Hits        34482    35048     +566     
- Misses      14499    14516      +17     
- Partials     2890     2901      +11     

☔ 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 13, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/markdown-patch -y -g

@evandance evandance added the domain/ccm PR touches the ccm domain label May 13, 2026
Change-Id: I8159941ff9dec4e5cbf0c757ec19ee172b302224
@wittam-01
wittam-01 force-pushed the feat/markdown-patch branch from 762bf38 to 963a61d Compare May 18, 2026 08:58
@github-actions github-actions Bot removed the domain/ccm PR touches the ccm domain label May 18, 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/markdown/markdown_patch.go`:
- Around line 184-189: The replacement is using regexp.ReplaceAllString which
treats $-sequences as capture references and can corrupt literal Markdown (e.g.,
"$100"); change the call to use re.ReplaceAllLiteralString(original,
spec.Content) so spec.Content is used verbatim. Locate the
regexp.Compile(spec.Pattern) block and replace the re.ReplaceAllString(...) call
(near re.FindAllStringIndex and return) with re.ReplaceAllLiteralString while
keeping the match counting via re.FindAllStringIndex(original, -1) and returning
len(matches) as before.
🪄 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: cb50732b-7ce0-4955-83ff-fa9b2d5ceb59

📥 Commits

Reviewing files that changed from the base of the PR and between 762bf38 and 963a61d.

📒 Files selected for processing (14)
  • README.md
  • README.zh.md
  • shortcuts/markdown/helpers.go
  • shortcuts/markdown/markdown_overwrite.go
  • shortcuts/markdown/markdown_patch.go
  • shortcuts/markdown/markdown_patch_test.go
  • shortcuts/markdown/markdown_test.go
  • shortcuts/markdown/shortcuts.go
  • skills/lark-drive/SKILL.md
  • skills/lark-drive/references/lark-drive-upload.md
  • skills/lark-markdown/SKILL.md
  • skills/lark-markdown/references/lark-markdown-patch.md
  • tests/cli_e2e/markdown/markdown_dryrun_test.go
  • tests/cli_e2e/markdown/markdown_workflow_test.go
✅ Files skipped from review due to trivial changes (6)
  • skills/lark-markdown/references/lark-markdown-patch.md
  • README.md
  • skills/lark-drive/references/lark-drive-upload.md
  • shortcuts/markdown/shortcuts.go
  • skills/lark-markdown/SKILL.md
  • README.zh.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • shortcuts/markdown/markdown_test.go
  • tests/cli_e2e/markdown/markdown_workflow_test.go
  • tests/cli_e2e/markdown/markdown_dryrun_test.go
  • skills/lark-drive/SKILL.md
  • shortcuts/markdown/helpers.go
  • shortcuts/markdown/markdown_overwrite.go
  • shortcuts/markdown/markdown_patch_test.go

Comment thread shortcuts/markdown/markdown_patch.go
@wittam-01
wittam-01 force-pushed the feat/markdown-patch branch from 53e3316 to 4d98eec Compare May 18, 2026 10:22

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

Review Summary

Thanks for the PR! The +patch shortcut is a nice addition. Here are the issues I found:

Priority Issue File
High No HTTP status code check after download — error responses could be treated as Markdown and uploaded, corrupting the file helpers.go
Medium $ injection in regex replacement with no escape mechanism markdown_patch.go
Medium Regex compiled twice (Validate + Execute) markdown_patch.go
Medium TOCTOU: no concurrency protection between download and upload markdown_patch.go
Low Inconsistent required-flag checking style markdown_patch.go
Low Download filename discarded then re-fetched via extra API call markdown_patch.go
Low match_count type roundtrip through float markdown_patch.go

The High priority item (missing HTTP status check) could lead to data corruption and should be addressed before merge.

Comment thread shortcuts/markdown/markdown_patch.go
Comment thread shortcuts/markdown/markdown_patch.go
Comment thread shortcuts/markdown/helpers.go
Comment thread shortcuts/markdown/markdown_patch.go
Comment thread shortcuts/markdown/markdown_patch.go
Comment thread shortcuts/markdown/markdown_patch.go
Comment thread shortcuts/markdown/markdown_patch.go
Change-Id: I98079901e980b74998938afc4917b91a79689948
@wittam-01
wittam-01 force-pushed the feat/markdown-patch branch from 4d98eec to 5bdc520 Compare May 18, 2026 12:35
@wittam-01
wittam-01 merged commit de00343 into main May 18, 2026
22 checks passed
@wittam-01
wittam-01 deleted the feat/markdown-patch branch May 18, 2026 12:54
@liangshuo-1 liangshuo-1 mentioned this pull request May 18, 2026
2 tasks
tuxedomm pushed a commit to zhumiaoxin/cli that referenced this pull request Jun 6, 2026
* feat: add markdown +patch shortcut

Change-Id: I8159941ff9dec4e5cbf0c757ec19ee172b302224

* fix: align markdown patch validation and dry-run

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

Labels

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