fix(sheets): make --max-chars the single read cap for +cells-get / +csv-get

Drop --cell-limit (+cells-get) and --max-rows (+csv-get) from the CLI surface
and pin the underlying tool's cell_limit / max_rows to a very large sentinel so
the tool's own defaults never truncate before --max-chars. --max-chars stays the
only knob (default 200000, unchanged).

- lark_sheet_read_data.go: add unboundedReadLimit (1e9); cellsGetInput pins
  cell_limit, csvGetInput pins max_rows; --max-chars still passed through
- data/flag-defs.json: synced from spec (drops the two flags)
- tests: spot-check moved to --max-chars; dry-run wantInput asserts cell_limit /
  max_rows are pinned high

Mirrors sheet-skill-spec (Base flag records removed).
go build ./... + go test ./shortcuts/sheets/ green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
xiongyuanwen-byted
2026-05-23 08:59:11 +08:00
parent 45cdca131f
commit 2befc49742
4 changed files with 21 additions and 27 deletions

View File

@@ -1196,15 +1196,6 @@
"data_validation"
]
},
{
"name": "cell-limit",
"kind": "own",
"type": "int",
"required": "optional",
"desc": "Safety cap; default 5000",
"default": "5000",
"hidden": true
},
{
"name": "max-chars",
"kind": "own",
@@ -1314,15 +1305,6 @@
"formula"
]
},
{
"name": "max-rows",
"kind": "own",
"type": "int",
"required": "optional",
"desc": "Safety cap; default 100000",
"default": "100000",
"hidden": true
},
{
"name": "max-chars",
"kind": "own",

View File

@@ -66,9 +66,9 @@ func TestFlagsFor_MapsAllFields(t *testing.T) {
t.Errorf("+sheet-create --url should not be cobra-required: %+v", url)
}
// hidden + int default
cap := byName("+cells-get", "cell-limit")
if cap == nil || !cap.Hidden || cap.Default != "5000" {
t.Errorf("+cells-get --cell-limit not mapped: %+v", cap)
cap := byName("+cells-get", "max-chars")
if cap == nil || !cap.Hidden || cap.Default != "200000" {
t.Errorf("+cells-get --max-chars not mapped: %+v", cap)
}
// input sources
cells := byName("+cells-set", "cells")

View File

@@ -19,6 +19,14 @@ import (
// The sandbox tool (export_sheet_to_sandbox) is Sheet-Tool-only and has no
// CLI surface here.
// unboundedReadLimit is pinned into the tool's cell_limit / max_rows so that
// --max-chars is the single effective read cap. The underlying tools default
// those two to smaller values; without an explicit high value they could
// truncate before max_chars. The CLI no longer exposes --cell-limit / --max-rows
// (only --max-chars), so we pass this sentinel to neutralize the tool defaults.
// Large enough to never bind on any real sheet.
const unboundedReadLimit = 1_000_000_000
// CellsGet wraps get_cell_ranges: read multiple A1 ranges and return per-cell
// values, formulas, styles, and other metadata as requested via --include.
var CellsGet = common.Shortcut{
@@ -75,9 +83,10 @@ func cellsGetInput(runtime *common.RuntimeContext, token, sheetID, sheetName str
if runtime.Bool("skip-hidden") {
input["skip_hidden"] = true
}
if n := runtime.Int("cell-limit"); n > 0 {
input["cell_limit"] = n
}
// --cell-limit was removed from the CLI surface; --max-chars is the single
// read cap. Pin cell_limit very high so the tool's own default never binds
// before max_chars.
input["cell_limit"] = unboundedReadLimit
if n := runtime.Int("max-chars"); n > 0 {
input["max_chars"] = n
}
@@ -172,9 +181,10 @@ func csvGetInput(runtime *common.RuntimeContext, token, sheetID, sheetName strin
if runtime.Bool("skip-hidden") {
input["skip_hidden"] = true
}
if n := runtime.Int("max-rows"); n > 0 {
input["max_rows"] = n
}
// --max-rows was removed from the CLI surface; --max-chars is the single
// read cap. Pin max_rows very high so the tool's own default never binds
// before max_chars.
input["max_rows"] = unboundedReadLimit
if n := runtime.Int("max-chars"); n > 0 {
input["max_chars"] = n
}

View File

@@ -31,6 +31,7 @@ func TestReadDataShortcuts_DryRun(t *testing.T) {
"ranges": []interface{}{"A1:B2"},
"include_styles": true,
"value_render_option": "formula",
"cell_limit": float64(unboundedReadLimit), // pinned high; --max-chars is the only cap
},
},
{
@@ -43,6 +44,7 @@ func TestReadDataShortcuts_DryRun(t *testing.T) {
"sheet_id": testSheetID,
"range": "A1:C10",
"value_render_option": "formula",
"max_rows": float64(unboundedReadLimit), // pinned high; --max-chars is the only cap
},
},
{