fix(docs): default docs insert --index to end-of-doc#610
Open
chrischall wants to merge 2 commits into
Open
Conversation
Closes openclaw#606. Iterative inserts without an explicit --index previously stacked at position 1, producing reversed output (each new insert pushed the previous one further right). This is surprising for anyone reading "insert" as the editor-style "add at the end" default. Change `--index` from a defaulted int64 (default 1) to a pointer; when unset, the command now fetches the target body/tab and inserts at docsAppendIndex(endIndex), matching the existing `docs write --append` behaviour. Explicit `--index N` still works exactly as before and skips the extra GET. `--index 0` still errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #606.
Summary
Iterative
gog docs insertcalls without an explicit--indexpreviously stacked at position 1, producing reversed output (each new insert pushed earlier inserts further right). The help even called this out — "Character index to insert at (1 = beginning)" — but it's not what anyone readinginsertas the editor-style "add at the end" default expects, and it silently produces broken docs in the dominant agent use case (build a long doc in chunks across many tool calls).Picks option (2) from the issue: when
--indexis omitted, resolve end-of-doc via the existingdocsTargetEndIndexAndTabID/docsAppendIndexhelpers (same pathdocs write --appenduses) and insert there. Explicit--index Nstill works exactly as before and skips the extra GET.Change
DocsInsertCmd.Indexis now*int64instead ofint64withdefault:"1"— so we can distinguish "omitted" from "set to 1".Run()branches onc.Index == nil:docsAppendIndex(endIndex), also resolves the tab in the same call>= 1, use it directly, no GET"atIndex": "end"when omitted, the explicit int otherwise. The text/JSON success output always reports the resolved integer index.Defaults to end-of-doc when omitted.Tests
TestDocsInsertCmd_DefaultsToEndOfDoc— asserts the GET runs once and the resultingInsertText.Location.IndexmatchesendIndex - 1.TestDocsInsertCmd_ExplicitIndexSkipsGet— asserts no GET when--indexis supplied.TestDocsInsertCmd_ExplicitIndexBelowOneRejected— preserves the existing>= 1guard.Existing
TestDocsEditingCommands_WithTab(which exercises--index 5 --tab Second) still passes.go test ./internal/cmd/ -count=1→ ok 23.8s.Compatibility note
This changes default behaviour for callers that previously relied on the implicit
--index=1. Per the issue's analysis, those callers were getting reversed output rather than something useful; the new default matchesdocs write --appendand whatinsertmeans in any text editor. Anyone explicitly passing--index=1is unaffected.