Skip to content

feat(sheets): add --ai-only to +formula-verify for AI formula status - #1959

Open
wenzhuozhen wants to merge 3 commits into
mainfrom
feat/lark-sheets-develop-ai-formula
Open

feat(sheets): add --ai-only to +formula-verify for AI formula status#1959
wenzhuozhen wants to merge 3 commits into
mainfrom
feat/lark-sheets-develop-ai-formula

Conversation

@wenzhuozhen

@wenzhuozhen wenzhuozhen commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add a --ai-only mode to sheets +formula-verify so agents can check the compute status of asynchronous AI formulas (AI_WRITE / AI_CLASSIFY / AI_SENTIMENT / AI_EXTRACT / AI_POLISH / AI_SUMMARY / AI_TRANSLATE), and enrich the lark-sheets skill docs with AI-formula parameter details and clearer verify guidance.

Changes

  • sheets +formula-verify: add --ai-only flag, mapped to the verify_formula tool input ai_only=true. It skips the ordinary 7-Excel-error scan and returns the current AI-formula compute status; a single call is a status probe and coexists with --sheet-id / --sheet-name / --range, honoring --exit-on-error.
  • Regenerate flag_defs_gen.go and add dry-run cases for --ai-only.
  • Skill docs (mirrored from the sheet-skill-spec canonical source):
    • lark-sheets-formula-translation: full AI-function parameter details — range rules, AI_TRANSLATE language keys, AI_EXTRACT extract-type, AI_CLASSIFY three modes, AI_INFER / AI_IMPORTDATA array semantics.
    • lark-sheets-formula-verify: clarify --ai-only convergence expectation (small batches resolve quickly; pending on large batches is normal) and drop implementation-leaking phrasing.

Test Plan

  • Unit tests pass (go test ./shortcuts/sheets/ -run 'TestFormulaVerify|FlagDef')
  • Manual local verification confirms the lark-cli sheets +formula-verify --ai-only flow works end-to-end against a real spreadsheet (returns ai_formula_total / done / pending / failed + status)

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added an --ai-only option to +formula-verify to verify only AI formulas and skip standard Excel-style error scanning.
    • Designed for asynchronous AI formula compute flows, returning a current status snapshot that may require repeated polling.
    • Can be combined with sheet and --range filters.
  • Documentation

    • Documented the unified AI formula syntax, supported use cases, and best practices.
    • Added an “AI 公式校验(--ai-only)” guide with expected statuses and example workflows.

…polling

BE-2: +formula-verify gains --ai-only, mapping to verify_formula tool
input ai_only=true. AI formulas (AI_WRITE / AI_CLASSIFY / …) compute
asynchronously; --ai-only is a single-shot polling probe (no built-in
wait/timeout) that skips the ordinary 7-Excel-error scan and returns
current AI-formula compute status. Coexists with --sheet-id/--range and
honors --exit-on-error.

BE-4: mirror sheet-skill-spec SoT docs (AI formula list in
lark-sheets-formula-translation, --ai-only + async polling section in
lark-sheets-formula-verify) and regenerate flag_defs_gen.go.

Spec source: active@6fe4ea7389c6d0631dc8279ee7506c357d0600325e28ffabdc97d9a66339e762
…rding

Mirror from sheet-skill-spec SoT (ee/sheet-skill-spec MR!55):
- formula-translation: full AI function param details (range rules,
  AI_TRANSLATE language keys, AI_EXTRACT type, AI_CLASSIFY modes,
  AI_INFER/AI_IMPORTDATA array semantics)
- formula-verify: clarify --ai-only convergence expectation, drop
  implementation-leaking phrasing
@github-actions github-actions Bot added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Jul 20, 2026
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The +formula-verify shortcut now supports --ai-only, forwarding ai_only: true for asynchronous AI formula status checks. Tests cover standalone and range-scoped requests, while reference documentation describes AI formula syntax and polling behavior.

Changes

AI formula verification

Layer / File(s) Summary
CLI flag and request wiring
shortcuts/sheets/data/flag-defs.json, shortcuts/sheets/flag_defs_gen.go, shortcuts/sheets/lark_sheet_formula_verify.go, shortcuts/sheets/lark_sheet_formula_verify_test.go
Adds the optional --ai-only flag, forwards ai_only: true to verify_formula, and tests standalone and range-scoped request payloads.
AI formula usage and verification documentation
skills/lark-sheets/references/lark-sheets-formula-translation.md, skills/lark-sheets/references/lark-sheets-formula-verify.md
Documents AI formula syntax, asynchronous computation, polling status, selectors, and exit behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FormulaVerifyCLI
  participant formulaVerifyInput
  participant verify_formula
  FormulaVerifyCLI->>formulaVerifyInput: parse --ai-only and selectors
  formulaVerifyInput->>verify_formula: send ai_only=true and optional ranges
  verify_formula-->>FormulaVerifyCLI: return current AI formula status
Loading

Possibly related PRs

  • larksuite/cli#1626: Both changes modify the +formula-verify shortcut plumbing to verify_formula.
  • larksuite/cli#1833: Introduced the original +formula-verify implementation and related tests.

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding --ai-only support to +formula-verify for AI formula status checks.
Description check ✅ Passed The description follows the required template and includes summary, changes, test plan, and related issues with relevant details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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/lark-sheets-develop-ai-formula

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 Jul 20, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/lark-sheets-develop-ai-formula -y -g

Sync the lark-sheets AI formula skill from sheet-skill-spec (SoT) after
the product change that merges all AI formulas into one AI() function:

- formula-translation reference: single =AI(prompt, [range]) function with
  syntax (incl. variadic =AI(part1, part2, ...) concatenation), per-case
  usage table (translate / sentiment / classify / extract / summarize /
  rewrite / generate / cleanup / keywords / multi-cell prompt), and
  prompt best practices
- formula-verify reference + --ai-only flag def: unified AI() wording
- flag_defs_gen.go regenerated from flag-defs.json
- lark_sheet_formula_verify.go: drop stale AI_WRITE / AI_CLASSIFY names
  in the ai_only comment, reference the unified AI() function

Co-authored-by: TRAE CLI <noreply@bytedance.com>

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

🤖 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 `@skills/lark-sheets/references/lark-sheets-formula-translation.md`:
- Around line 38-42: Add a supported language identifier, such as text, to the
fenced formula example blocks containing the AI formulas, including both
locations referenced by the comment. Keep the formula examples unchanged.
- Line 72: Update the structured-output example in the formula translation
guidance to use valid JSON with double-quoted property names and concrete JSON
values; describe the permitted score range separately rather than using “0-100”
as a value. Keep the existing category and score fields and guidance intact.
- Line 87: Update the post-write validation guidance around
lark-sheets-formula-verify and +formula-verify --ai-only so completion requires
every AI formula to have status done and no failure or unsupported statuses.
Continue polling while any formula is pending, and do not declare the run
complete merely because pending formulas are absent.

In `@skills/lark-sheets/references/lark-sheets-formula-verify.md`:
- Line 73: Update the AI formula signature in lark-sheets-formula-verify.md to
match lark-sheets-formula-translation.md by including the variadic form
=AI(part1, part2, ...), or explicitly state that =AI(prompt, [range]) is
shorthand for it.
🪄 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: d72e1c61-bf87-48d4-9cdf-ec8d6dc6eb87

📥 Commits

Reviewing files that changed from the base of the PR and between d5e4694 and bf63865.

📒 Files selected for processing (5)
  • shortcuts/sheets/data/flag-defs.json
  • shortcuts/sheets/flag_defs_gen.go
  • shortcuts/sheets/lark_sheet_formula_verify.go
  • skills/lark-sheets/references/lark-sheets-formula-translation.md
  • skills/lark-sheets/references/lark-sheets-formula-verify.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • shortcuts/sheets/flag_defs_gen.go
  • shortcuts/sheets/data/flag-defs.json
  • shortcuts/sheets/lark_sheet_formula_verify.go

Comment on lines +38 to +42
```
=AI(prompt)
=AI(prompt, range)
=AI(part1, part2, ...)
```

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

Add language identifiers to the fenced formula examples.

The two fenced blocks trigger markdownlint MD040. Use an appropriate identifier such as text or the repository’s supported formula-language identifier.

Also applies to: 78-81

🧰 Tools
🪛 markdownlint-cli2 (0.23.0)

[warning] 38-38: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 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 `@skills/lark-sheets/references/lark-sheets-formula-translation.md` around
lines 38 - 42, Add a supported language identifier, such as text, to the fenced
formula example blocks containing the AI formulas, including both locations
referenced by the comment. Keep the formula examples unchanged.

Source: Linters/SAST tools

1. **明确输出格式**:与其写"分析一下",不如写"判断情绪,只返回 Positive / Neutral / Negative"。限定可选值能让结果可机读、可再计算。
2. **指定语言**:写"翻译成中文"比只写"翻译"更稳定。
3. **指定长度**:如"总结成一句话""30 字以内"。
4. **需要结构化时明确要 JSON**:如提示"返回 JSON:{category:'', score:0-100}",AI 能较稳定地输出结构化结果。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Use a valid JSON example.

{'category':'', 'score':0-100} is not valid JSON because it uses single quotes and a non-value range expression. Show valid JSON, and describe the allowed score range separately.

🤖 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 `@skills/lark-sheets/references/lark-sheets-formula-translation.md` at line 72,
Update the structured-output example in the formula translation guidance to use
valid JSON with double-quoted property names and concrete JSON values; describe
the permitted score range separately rather than using “0-100” as a value. Keep
the existing category and score fields and guidance intact.


对整列逐行跑 AI,推荐**模板单元格 + `--copy-to-range` 向下扩展**:在种子单元格写 `=AI("<提示词>", A2)`,再用 `--copy-to-range` 扩展到整列,相对引用会随行自增(`A2` → `A3` → …)。这样每行独立计算、行为可预测,比依赖单条公式一次铺开整列更稳。

**写完 AI 公式后的校验**:AI 公式异步计算,少量公式通常很快就能算出结果;一次批量写入较多公式时,部分公式在校验时仍处于计算中(pending)属于正常现象。写完后用 `lark-sheets-formula-verify` 的 `+formula-verify --ai-only` 查看 AI 公式计算状态,直到不再有 pending 即算完成。细节见 `lark-sheets-formula-verify`。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not equate “no pending” with successful completion.

A failed or unsupported AI formula is also no longer pending. Require all formulas to be done with no failure statuses before declaring the run complete.

Proposed wording
-写完后用 `lark-sheets-formula-verify` 的 `+formula-verify --ai-only` 查看 AI 公式计算状态,直到不再有 pending 即算完成。
+写完后用 `lark-sheets-formula-verify` 的 `+formula-verify --ai-only` 查看状态,直到所有公式均为 done 且没有 failed/unsupported 状态;若出现失败,应先处理后再交付。
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
**写完 AI 公式后的校验**:AI 公式异步计算,少量公式通常很快就能算出结果;一次批量写入较多公式时,部分公式在校验时仍处于计算中(pending)属于正常现象。写完后用 `lark-sheets-formula-verify``+formula-verify --ai-only` 查看 AI 公式计算状态,直到不再有 pending 即算完成。细节见 `lark-sheets-formula-verify`
**写完 AI 公式后的校验**:AI 公式异步计算,少量公式通常很快就能算出结果;一次批量写入较多公式时,部分公式在校验时仍处于计算中(pending)属于正常现象。写完后用 `lark-sheets-formula-verify``+formula-verify --ai-only` 查看状态,直到所有公式均为 done 且没有 failed/unsupported 状态;若出现失败,应先处理后再交付。细节见 `lark-sheets-formula-verify`
🤖 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 `@skills/lark-sheets/references/lark-sheets-formula-translation.md` at line 87,
Update the post-write validation guidance around lark-sheets-formula-verify and
+formula-verify --ai-only so completion requires every AI formula to have status
done and no failure or unsupported statuses. Continue polling while any formula
is pending, and do not declare the run complete merely because pending formulas
are absent.


## AI 公式校验(`--ai-only`)

飞书表格提供一个统一的 **`AI` 公式**(`=AI(prompt, [range])`,用自然语言驱动翻译 / 分类 / 情感分析 / 信息提取 / 总结 / 润色等,写法与清单见 `lark-sheets-formula-translation`)。AI 公式的写入与普通公式一致(复用 `+cells-set` / `set_cell_range`,无需特殊接口),但**计算是异步的**:写入后要等 AI 算完才有结果。普通的 `+formula-verify` 只扫本地单元格值(7 类 Excel 错误),看不到 AI 公式的计算状态。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Keep the AI signature consistent with the translation reference.

This parenthetical only advertises =AI(prompt, [range]), while skills/lark-sheets/references/lark-sheets-formula-translation.md also documents =AI(part1, part2, ...). Include the variadic form or explicitly state that the notation is shorthand.

🤖 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 `@skills/lark-sheets/references/lark-sheets-formula-verify.md` at line 73,
Update the AI formula signature in lark-sheets-formula-verify.md to match
lark-sheets-formula-translation.md by including the variadic form =AI(part1,
part2, ...), or explicitly state that =AI(prompt, [range]) is shorthand for it.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.15%. Comparing base (8897196) to head (bf63865).
⚠️ Report is 93 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1959      +/-   ##
==========================================
+ Coverage   74.72%   75.15%   +0.43%     
==========================================
  Files         886      912      +26     
  Lines       92621    96455    +3834     
==========================================
+ Hits        69208    72494    +3286     
- Misses      18052    18383     +331     
- Partials     5361     5578     +217     

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

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