Skip to content

feat(docs): add +table-update shortcut for fine-grained table editing#473

Open
whitesockcat wants to merge 2 commits intolarksuite:mainfrom
whitesockcat:feat/table-update
Open

feat(docs): add +table-update shortcut for fine-grained table editing#473
whitesockcat wants to merge 2 commits intolarksuite:mainfrom
whitesockcat:feat/table-update

Conversation

@whitesockcat
Copy link
Copy Markdown

@whitesockcat whitesockcat commented Apr 14, 2026

Summary

  • Add new docs +table-update shortcut that directly calls the Lark docx block API for precise table manipulation
  • Supports 5 actions: update-cell, insert-row, delete-rows, insert-col, delete-cols
  • Solves the limitation that docs +update cannot reliably edit table cell content or modify table structure (add/remove rows/columns)

Motivation

The existing docs +update operates at document block level with text-based selection (--selection-with-ellipsis / --selection-by-title), which cannot precisely target individual table cells. The Lark docx SDK provides dedicated table mutation APIs (InsertTableRow, DeleteTableRows, etc.) but they were not exposed through any CLI shortcut.

Usage examples

# Modify a cell (row 1, col 2 of the first table)
lark-cli docs +table-update --doc "<url>" --row 1 --col 2 --markdown "new content"

# Insert a row at position 3
lark-cli docs +table-update --doc "<url>" --action insert-row --at 3

# Delete rows [2, 4)
lark-cli docs +table-update --doc "<url>" --action delete-rows --from 2 --to 4

# Insert a column at position 1
lark-cli docs +table-update --doc "<url>" --action insert-col --at 1

# Delete columns [0, 1)
lark-cli docs +table-update --doc "<url>" --action delete-cols --from 0 --to 1

Files changed

File Change
shortcuts/doc/docs_table_update.go New shortcut implementation (~350 lines)
shortcuts/doc/shortcuts.go Register DocsTableUpdate
skills/lark-doc/SKILL.md Add shortcut to docs table
skills/lark-doc/references/lark-doc-table-update.md Reference documentation

Test plan

  • Create a test document with a table via docs +create
  • update-cell: modify cell content by row/col index — verified cell updated correctly
  • insert-row: insert a new row — verified table row count increased
  • update-cell x3: fill inserted row cells — verified content written
  • delete-rows: delete a row — verified row removed, other rows intact
  • go build ./... passes with zero errors

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added lark-cli docs +table-update to edit tables in Lark Docs: update cell content, insert/delete rows and columns; locate tables by index or ID, validate parameters, and return structured success/error JSON.
  • Documentation

    • Added detailed usage guide with parameter references, examples, return-value samples, and behavioral notes (including unsupported document types and index conventions).

The existing `docs +update` command operates at the document block level
and cannot precisely target individual table cells. This adds a new
`docs +table-update` shortcut that directly calls the Lark docx block
API to enable:

- update-cell: modify a specific cell by row/col index
- insert-row / insert-col: insert rows or columns at a given position
- delete-rows / delete-cols: remove rows or columns by index range

This bypasses the MCP markdown channel and uses the native docx
block patch API (InsertTableRow, DeleteTableRows, etc.), providing
reliable table structure manipulation without round-trip issues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions github-actions bot added domain/ccm PR touches the ccm domain size/L Large or sensitive change across domains or core paths labels Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

A new +table-update shortcut command is introduced for Lark Docs that enables updates to document tables via the docx API. The implementation validates action types, discovers target tables, and dispatches operations for cell updates, row/column inserts, and deletes. Associated documentation describes usage and parameters.

Changes

Cohort / File(s) Summary
Core Implementation
shortcuts/doc/docs_table_update.go
New exported shortcut doc.DocsTableUpdate implementing +table-update: flag validation, doc parsing (wiki token resolution), table discovery (by --table-id or --table-index), handlers for update-cell, insert-row, delete-rows, insert-col, delete-cols, API calls (fetch metadata, batch delete/create children, patch block), and structured JSON output.
Shortcut Registration
shortcuts/doc/shortcuts.go
Registered the new DocsTableUpdate in Shortcuts() returned slice.
Documentation
skills/lark-doc/SKILL.md, skills/lark-doc/references/lark-doc-table-update.md
Added shortcut entry and comprehensive reference doc describing command usage, flags (--action, --doc, --table-id/--table-index, row/col params), examples, output JSON, and comparisons with docs +update.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ShortcutHandler
    participant WikiAPI
    participant BlockAPI

    Client->>ShortcutHandler: Invoke +table-update (--action, --doc, --table-id/--table-index, params)
    ShortcutHandler->>ShortcutHandler: Validate flags & parse integers
    ShortcutHandler->>WikiAPI: Resolve doc/wiki token (if needed)
    WikiAPI-->>ShortcutHandler: Return docx token
    ShortcutHandler->>BlockAPI: If no table-id, list blocks (paginated) to find table by index
    BlockAPI-->>ShortcutHandler: Return table block reference / metadata
    alt update-cell
        ShortcutHandler->>BlockAPI: Fetch table metadata (cell ids)
        BlockAPI-->>ShortcutHandler: Return structure
        ShortcutHandler->>BlockAPI: Batch delete cell children -> create new text child with markdown
    else insert/delete rows/cols
        ShortcutHandler->>BlockAPI: Patch table block with insert/delete payload
    end
    BlockAPI-->>ShortcutHandler: Return success/error
    ShortcutHandler-->>Client: Emit structured JSON result or error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • fangshuyu-768
  • liujinkun2025

Poem

🐰 I nibble at tables, tidy each cell bright,
I hop rows in, or vanish them out of sight,
With wiki tokens found and docx calls in tune,
I update, insert, delete—under the moon! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main feature being added: a new +table-update shortcut for fine-grained table editing, which is the primary focus of the changeset.
Description check ✅ Passed The description covers all required template sections (Summary, Changes, Test Plan) with clear motivation, usage examples, file changes, and verification steps.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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

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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shortcuts/doc/docs_table_update.go`:
- Around line 47-69: The Validate function currently accepts numeric flags as
strings and later silently treats invalid strconv.Atoi parses as 0; update
Validate (in shortcuts/doc/docs_table_update.go, the Validate func using
runtime.Str("action")) to parse and validate numeric flags up front: call
strconv.Atoi on runtime.Str("row"), runtime.Str("col"), runtime.Str("at"),
runtime.Str("from"), and runtime.Str("to") where applicable and return
common.FlagErrorf on parse errors or if any parsed value is negative;
additionally, for delete actions ("delete-rows", "delete-cols") enforce that
parsed from < parsed to and return a FlagErrorf if not. Ensure the existing
action-specific checks (for "update-cell", "insert-row", "insert-col",
"delete-rows", "delete-cols") validate both presence and numeric correctness of
these flags before allowing the command to proceed.
- Around line 73-86: The code currently accepts parseDocumentRef results (ref)
and wiki resolutions that may refer to non-docx objects and then calls the docx
API; update the validation in the block around
parseDocumentRef/resolveWikiToDocID so that you reject refs where ref.Kind ==
"doc" immediately with a clear validation error, and when ref.Kind == "wiki"
call resolveWikiToDocID(runtime, ref.Token) then fetch and assert the resolved
wiki node's obj_type == "docx" before assigning docID (otherwise return a
validation error). Apply the same validation logic to the second occurrence
around lines 120-133 (the other parseDocumentRef/resolveWikiToDocID flow) so
only docx targets proceed to the docx/v1/documents/... call.

In `@skills/lark-doc/references/lark-doc-table-update.md`:
- Around line 14-31: Update the example captions so they describe positions as
0-based to match the CLI flags used; edit the lines that annotate the examples
for commands using --row, --col, --at, --from, --to, --table-index and
--table-id (e.g., the captions for the update-cell, insert-row, delete-rows,
insert-col, delete-cols, and table-id examples) to state 0-based indices (e.g.,
"第1个表格的第2行第1列" -> indicate 0-based like "第1个表格的第2行(0-based 索引=2)" or simply
state "索引从0开始") so the descriptive text matches the flags and avoids off-by-one
confusion.
🪄 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: 986ff97d-1b1d-4105-9535-edb437e84458

📥 Commits

Reviewing files that changed from the base of the PR and between fe41234 and 1476628.

📒 Files selected for processing (4)
  • shortcuts/doc/docs_table_update.go
  • shortcuts/doc/shortcuts.go
  • skills/lark-doc/SKILL.md
  • skills/lark-doc/references/lark-doc-table-update.md

- Validate numeric flags (--row, --col, --at, --from, --to) upfront in
  Validate: reject non-integer and negative values before any write
- Enforce --from < --to for delete-rows/delete-cols actions
- Reject legacy /doc/ URLs with a clear validation error
- Verify wiki node obj_type == "docx" before proceeding
- Update documentation examples to clarify 0-based indexing

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 `@shortcuts/doc/docs_table_update.go`:
- Around line 286-294: Currently deleteCellChildren(runtime, docID, cellBlockID)
runs before createCellContent(...), which can permanently lose data if the
create POST fails; change the flow in the function containing deleteCellChildren
and createCellContent to create the replacement content first (call
createCellContent or an equivalent create block API to produce the new block(s)
and obtain their IDs), verify the create succeeded, then atomically
attach/replace the old children by calling the parent/replace API or by deleting
old children only after attaching the new ones; if attaching or deleting fails,
perform cleanup/rollback of the newly created blocks to avoid orphaned content
and return an error.
🪄 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: 925ebf23-48b9-41ab-a749-e4e980c0b76b

📥 Commits

Reviewing files that changed from the base of the PR and between 1476628 and bcd8c63.

📒 Files selected for processing (2)
  • shortcuts/doc/docs_table_update.go
  • skills/lark-doc/references/lark-doc-table-update.md
✅ Files skipped from review due to trivial changes (1)
  • skills/lark-doc/references/lark-doc-table-update.md

Comment on lines +286 to +294
// Step 1: Delete all existing children of the cell.
if err := deleteCellChildren(runtime, docID, cellBlockID); err != nil {
return fmt.Errorf("clear cell: %w", err)
}

// Step 2: Create new content in the cell.
// For simple text, directly create a text block. For complex markdown, use MCP.
if err := createCellContent(runtime, docID, cellBlockID, markdown); err != nil {
return fmt.Errorf("write cell content: %w", 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.

⚠️ Potential issue | 🟠 Major

Avoid clearing the cell before the replacement write succeeds.

This flow deletes the existing children first and only then creates the replacement block. If the POST fails, the command leaves the cell empty and the original content is lost.

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

In `@shortcuts/doc/docs_table_update.go` around lines 286 - 294, Currently
deleteCellChildren(runtime, docID, cellBlockID) runs before
createCellContent(...), which can permanently lose data if the create POST
fails; change the flow in the function containing deleteCellChildren and
createCellContent to create the replacement content first (call
createCellContent or an equivalent create block API to produce the new block(s)
and obtain their IDs), verify the create succeeded, then atomically
attach/replace the old children by calling the parent/replace API or by deleting
old children only after attaching the new ones; if attaching or deleting fails,
perform cleanup/rollback of the newly created blocks to avoid orphaned content
and return an error.

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/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants