Skip to content

fix(autocomplete): rejoin trailing colon command tokens - #80

Open
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/autocomplete-trailing-colon
Open

fix(autocomplete): rejoin trailing colon command tokens#80
sylvesterkaczmarek wants to merge 2 commits into
openai:mainfrom
sylvesterkaczmarek:fix/autocomplete-trailing-colon

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Make completion argument reconstruction honor the trailing-colon case that the helper already documents.

Fixes #79.

Problem

Shell completion can split colon-named CLI commands at different word-boundary shapes. rebuildColonSeparatedArgs is intended to normalize those shapes before command lookup.

Its comment explicitly says to keep joining when either:

  • the next token is a standalone ":"; or
  • the accumulated current token already ends in ":".

The second condition currently cannot do useful work. The loop admits the trailing-colon case, but the inner branch immediately executes break unless the next token itself equals ":".

So:

rebuildColonSeparatedArgs([]string{"config:", "get"})

currently returns:

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

instead of:

[]string{"config:get"}

Root cause

The loop condition and loop body encode different rules:

for ... && (args[i+1] == ":" || strings.HasSuffix(current, ":")) {
    if args[i+1] == ":" {
        ...
    } else {
        break
    }
}

When only strings.HasSuffix(current, ":") is true, execution enters the loop and immediately leaves it without joining the next token.

Fix

The reconstruction rule can be expressed directly: while either boundary condition holds, append the next token to the accumulated token and advance.

That handles all of these consistently:

["config", ":", "get"] -> ["config:get"]
["config:", "get"]      -> ["config:get"]
["a", ":", ":", "b"] -> ["a::b"]

Ordinary arguments without colon boundaries remain untouched.

Regression coverage

Added a focused table-driven test covering:

  • the standalone-colon shape already described by the function comment;
  • the previously broken trailing-colon shape;
  • repeated colon boundaries;
  • an ordinary no-colon control.

The trailing-colon case fails on current upstream main and passes with this change.

Validation

The branch is based directly on upstream main at d082a010f7c6cacf407d8a1581446a7857f9f1bb and is not behind it.

Production code is reduced by nine net lines because the contradictory nested branch is replaced with the direct reconstruction rule. Regression coverage lives in a separate focused test file.

Full repository validation is left to the repository's GitHub Actions checks.

Risk

Low. The change is confined to the internal argv reconstruction used by shell completion. It only joins the next token in cases where the helper's existing loop condition already identifies a colon boundary, and leaves ordinary argument sequences unchanged.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 18, 2026 10:52
@markstuart-oai

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-06T01:32:03.518605Z 08c2e73 Manual request
🔒 Security Review Completed 2026-09-06T01:32:04.036030Z 08c2e73 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08c2e73de1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 342 to +344
for i+1 < len(args) && (args[i+1] == ":" || strings.HasSuffix(current, ":")) {
if args[i+1] == ":" {
current += ":"
i++
// Check if there's a following element after the ":"
if i+1 < len(args) && args[i+1] != ":" {
current += args[i+1]
i++
}
} else {
break
}
current += args[i+1]
i++

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve spaces after colon-ending arguments

When a completed argument legitimately ends in :, this loop now concatenates the following whitespace-delimited argument as though it were part of the same token. For example, the Bash path in internal/autocomplete/shellscripts/bash_autocomplete.bash:9 passes openai beta:assistants create --instructions Prefix: --mo<Tab> as separate arguments, but reconstruction changes the last two to Prefix:--mo; GetCompletions therefore no longer recognizes --mo as a flag prefix and omits --model. Avoid joining merely because current ends in a colon when the boundary represents a real space (the empty-current case after Prefix: is affected similarly).

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 08c2e73de1

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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.

Autocomplete argument reconstruction does not join tokens after a trailing colon

2 participants