Skip to content

feat(docs): add insert-table primitive#617

Open
chrischall wants to merge 2 commits into
openclaw:mainfrom
chrischall:feat/602-docs-insert-table
Open

feat(docs): add insert-table primitive#617
chrischall wants to merge 2 commits into
openclaw:mainfrom
chrischall:feat/602-docs-insert-table

Conversation

@chrischall
Copy link
Copy Markdown
Contributor

Closes #602.

Summary

Surfaces the Docs API `InsertTableRequest` as a standalone CLI subcommand that bypasses the markdown writer. The markdown path can render tables, but it has had several distinct rendering bugs (#592, #608, #609) and structural off-by-ones (#607) — for agent-generated table-shaped deliverables (itineraries, schedules, comparisons) a direct primitive is the cleanest backbone.

Usage

```
gog docs insert-table --rows N --cols M [--index N | --at-end] \
[--values-json [[...]]] [--tab=STRING]
```

Flag Notes
`--rows`, `--cols` Required. Must each be `>= 1`.
`--index` / `--at-end` Omit either to insert at end-of-doc (same convention as `docs write --append` and the new `insert-page-break` command); `--at-end` is the explicit form. Mutually exclusive with `--index`.
`--values-json` JSON 2D string array. Dimensions must match `--rows` x `--cols` exactly; omitted = all-empty cells.
`--tab` Standard tab-by-title-or-id support.

Internals

  • Reuses the existing `TableInserter.InsertNativeTable` so the structural insert, the post-insert `Get` to find cell indices, and the per-cell text inserts all go through the same path the markdown writer uses (and pick up any future improvements there).
  • End-of-doc resolution uses `docsTargetEndIndexAndTabID` + `docsAppendIndex`, matching the new `insert-page-break` PR and the recently filed `gog docs insert: default --index to end-of-doc (or rename / require it explicit) #606` insert default.
  • `parseTableValuesJSON` validates dimensions and rejects malformed input with a precise usage error.

Tests

  • `TestParseTableValuesJSON_EmptyProducesAllEmptyMatrix` — empty input → all-empty rows x cols.
  • `TestParseTableValuesJSON_PopulatedMatrixRoundTrip` — happy path.
  • `TestParseTableValuesJSON_RowCountMismatch` — row count enforced.
  • `TestParseTableValuesJSON_ColumnCountMismatch` — per-row column count enforced with the offending row index.
  • `TestParseTableValuesJSON_InvalidJSONRejected` — surface the JSON parse error wrapped in a usage error.
  • `TestDocsInsertTableCmd_FlagValidation` — table-driven coverage of every `Run()` validation branch (`--rows`/`--cols` < 1, `--index`+`--at-end` conflict, negative `--index`, mismatched `--values-json`).

`go test ./internal/cmd/ -count=1` → ok 23.8s.

chrischall and others added 2 commits May 19, 2026 20:26
Closes openclaw#602.

Surfaces the Docs API InsertTableRequest as a standalone CLI subcommand
that bypasses the markdown writer (openclaw#592 / openclaw#608 / openclaw#609 are all
markdown-table-only bugs; agents need a path that doesn't go through
that converter for table-shaped deliverables).

Usage:
  gog docs insert-table <docId> --rows N --cols M [--index N | --at-end] \
                        [--values-json [[...]]] [--tab=STRING]

Internals:
- Reuses the existing TableInserter.InsertNativeTable so the structural
  insert, the post-insert Get-to-find-cell-indices, and the per-cell
  text inserts all go through the same path the markdown writer uses.
- --values-json takes a JSON 2D string array whose dimensions must
  match --rows x --cols exactly. Empty values-json fills the table
  with empty cells.
- --index / --at-end semantics match the new insert-page-break command
  and docs write --append: omit either → resolve to end-of-doc via
  docsTargetEndIndexAndTabID; --at-end is the explicit form.

Tests cover the parseTableValuesJSON helper (empty, populated, row
mismatch, column mismatch, malformed JSON) plus a table-driven Run-
level check for every flag-validation branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(docs): add insert-table primitive — direct table insertion without the markdown path

1 participant