Skip to content

feat(docs): add --at <text> anchor to insert / delete / update / insert-person / insert-page-break #683

@sebsnyk

Description

@sebsnyk

Motivation

gog docs insert-image --at <placeholder> already follows the "anchor by text" pattern and is much friendlier than --index=N. The sibling commands insert, delete, update, insert-person, insert-page-break all still require numeric indices, forcing callers into the same docs raw walk pattern over and over.

Once find-range (#682) lands, these can be implemented as thin wrappers.

Depends on

Verified against current source (v0.21.x):

  • docs_insert_page_break.go exposes --index + --at-end only; no --at <text>.
  • docs_format.go flag set is bold/italic/underline/strike/font-family/font-size/text-color/bg-color/alignment/line-spacing/heading-level/named-style — no text-anchor.
  • docs_insert_image.go is the only command with name:"at".

Repro

Today, to insert a Person chip at a specific name occurrence inside a doc body, a script has to:

  1. gog docs raw and walk for the matching textRun.
  2. gog docs delete --start=S --end=E to remove the existing run.
  3. gog docs insert-person --email=... --index=S.

Three calls per chip, with the indices recomputed in reverse-document order to avoid drift.

Proposed surface

Add the following flags to each command:

--at <text>            Anchor by literal text
--occurrence INT       Disambiguate when multiple matches (default 1)
--match-case           Case-sensitive match

Per command behaviour:

  • delete --at <text> — delete the matched range. Mutually exclusive with --start/--end.
  • insert --at <text> — insert at the start index of the match (does not replace; for replace, use update).
  • update --at <text> — replace the matched range with --text/--file content. Mutually exclusive with --index/--replace-range.
  • insert-person --at <text> — atomic delete-and-insert-chip in one batchUpdate.
  • insert-page-break --at <text> — insert at the start index of the match.

When the match is ambiguous and --occurrence is not set, exit non-zero with a hint listing all occurrences.

Acceptance criteria

  • All five commands accept --at <text> and the result is identical to the current --index/--start/--end form when fed the resolved range.
  • Ambiguous matches without --occurrence produce an error before mutating.
  • insert-person --at is atomic (single batchUpdate request bundling DeleteContentRange + the InsertText/InsertPerson sequence), so concurrent writers cannot see an intermediate state.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions