Problem
The generated completion adapter must distinguish the current word from the completed words when COMP_CWORD points just past the last populated COMP_WORDS entry. If it clamps the cursor to the last existing word without appending an empty current word, an exact nested command is treated as a prefix and its child route is not offered.
The current main implementation has the correct behavior, but the staged cursor rewrite in the supplied checkout regresses it. This needs an explicit contract test and an implementation shape that cannot lose the empty current word during future completion changes.
Verified evidence
With a model containing admin and admin/user, the existing current-main contract is:
COMP_WORDS=(cursor admin)
COMP_CWORD=2
_cursor_complete
# COMPREPLY=user
The staged rewrite returns admin because it clamps COMP_CWORD to word_count - 1 and slices without appending an empty current word. The existing test fails when that rewrite is applied to current main.
Scope and acceptance criteria
- Preserve exact nested-command completion when the cursor is at the end of
COMP_WORDS.
- Continue honoring cursors in the middle of the word array, option-value consumption, aliases, and the
-- boundary.
- Keep generated completion scratch state local and safe under unset or malformed completion variables.
- Add regression coverage for the cursor-at-end exact-command case and the existing cursor matrix.
Validation
Run the CLI BATS tests, the full ./tests/validate.sh suite, and the repository quality gates.
Non-goals
No change to command declaration, parser, handler, or option-resolution semantics.
Problem
The generated completion adapter must distinguish the current word from the completed words when
COMP_CWORDpoints just past the last populatedCOMP_WORDSentry. If it clamps the cursor to the last existing word without appending an empty current word, an exact nested command is treated as a prefix and its child route is not offered.The current
mainimplementation has the correct behavior, but the staged cursor rewrite in the supplied checkout regresses it. This needs an explicit contract test and an implementation shape that cannot lose the empty current word during future completion changes.Verified evidence
With a model containing
adminandadmin/user, the existing current-main contract is:COMP_WORDS=(cursor admin) COMP_CWORD=2 _cursor_complete # COMPREPLY=userThe staged rewrite returns
adminbecause it clampsCOMP_CWORDtoword_count - 1and slices without appending an empty current word. The existing test fails when that rewrite is applied to current main.Scope and acceptance criteria
COMP_WORDS.--boundary.Validation
Run the CLI BATS tests, the full
./tests/validate.shsuite, and the repository quality gates.Non-goals
No change to command declaration, parser, handler, or option-resolution semantics.