openai / openai/openai-cli

Autocomplete argument reconstruction does not join tokens after a trailing colon

Open Beginner friendly
#79 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
697
Forks
60
Avg merge
2d 21h
Merged PRs (30d)
71

Description

Summary

rebuildColonSeparatedArgs documents that it rejoins shell-completion arguments when either the next token is ":" or the current token already ends with ":". The implementation enters the loop for the second case but immediately breaks instead of appending the following token.

As a result, a tokenization shape such as:

[]string{"config:", "get"}

remains two arguments instead of being reconstructed as:

[]string{"config:get"}

This can make colon-named commands fail to resolve correctly when a shell presents the word-break boundary after the colon rather than returning the colon as its own token.

Reproduction

On current main (d082a010f7c6cacf407d8a1581446a7857f9f1bb):

got := rebuildColonSeparatedArgs([]string{"config:", "get"})
// current: []string{"config:", "get"}
// expected: []string{"config:get"}

The function's existing comment explicitly describes the intended rule:

Keep joining while the next element is ":" or the current element ends with ":"

but the current loop body contains:

if args[i+1] == ":" {
    // append colon and possibly the following element
    ...
} else {
    break
}

So the strings.HasSuffix(current, ":") half of the loop condition cannot actually join anything unless the next token is also a standalone colon.

Expected behavior

Both common shell tokenization shapes should reconstruct to the same logical command token:

[]string{"config", ":", "get"} -> []string{"config:get"}
[]string{"config:", "get"}      -> []string{"config:get"}

Consecutive colon boundaries should also remain intact, e.g. {"a", ":", ":", "b"} -> {"a::b"}.

Suggested fix

While the next token is a standalone colon or the accumulated token ends in a colon, append the next token directly and advance. This removes the contradictory inner branch and handles both boundary shapes uniformly.

Add focused table-driven coverage for standalone-colon, trailing-colon, repeated-colon, and ordinary no-colon inputs.

Impact

This is shell-completion correctness. Depending on how the invoking shell splits a colon command at the cursor boundary, the completion helper can reconstruct a different argv shape and therefore miss the command or return irrelevant completions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the rebuildColonSeparatedArgs function and inspect its existing callers and tests. Add focused table-driven coverage for standalone-colon, trailing-colon, repeated-colon, and ordinary no-colon inputs, then run the relevant Go tests and confirm both tokenization shapes reconstruct the same command token.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.