feat(docs): add +table-update shortcut for fine-grained table editing#473
feat(docs): add +table-update shortcut for fine-grained table editing#473whitesockcat wants to merge 2 commits intolarksuite:mainfrom
Conversation
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>
|
|
📝 WalkthroughWalkthroughA new Changes
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
shortcuts/doc/docs_table_update.goshortcuts/doc/shortcuts.goskills/lark-doc/SKILL.mdskills/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>
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
shortcuts/doc/docs_table_update.goskills/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
| // 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) |
There was a problem hiding this comment.
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.
Summary
docs +table-updateshortcut that directly calls the Lark docx block API for precise table manipulationupdate-cell,insert-row,delete-rows,insert-col,delete-colsdocs +updatecannot reliably edit table cell content or modify table structure (add/remove rows/columns)Motivation
The existing
docs +updateoperates 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
Files changed
shortcuts/doc/docs_table_update.goshortcuts/doc/shortcuts.goDocsTableUpdateskills/lark-doc/SKILL.mdskills/lark-doc/references/lark-doc-table-update.mdTest plan
docs +createupdate-cell: modify cell content by row/col index — verified cell updated correctlyinsert-row: insert a new row — verified table row count increasedupdate-cellx3: fill inserted row cells — verified content writtendelete-rows: delete a row — verified row removed, other rows intactgo build ./...passes with zero errors🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
lark-cli docs +table-updateto 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