Skip to content

fix(autocomplete): complete inherited flags after subcommands - #166

Open
markstuart-oai wants to merge 1 commit into
mainfrom
markstuart-oai/c17-inherited-global-completion
Open

fix(autocomplete): complete inherited flags after subcommands#166
markstuart-oai wants to merge 1 commit into
mainfrom
markstuart-oai/c17-inherited-global-completion

Conversation

@markstuart-oai

Copy link
Copy Markdown
Contributor

Summary

Flag completion stopped at the current command's declarations, so openai __complete -- models list --fo returned no suggestions even though --format and --format-error are valid there. Include inherited flag names and aliases after nested commands, and consume their values before continuing command traversal.

Use the pinned urfave inheritance contract: preserve child name/alias overrides, nearest-ancestor precedence, hidden inherited flags, and flags marked local. Preserve completion statuses, file completion and explicit @ paths. Completion does not execute API requests. Regression coverage exercises raw and initialized command trees, the production entrypoint, and rendered Bash completion.

Validation

Passed locally with Go 1.27.0 on Linux (module version and dependencies unchanged):

  • go test ./internal/autocomplete ./cmd/openai -count=1, go test ./internal/..., and go test ./... -run '^$'.
  • go mod verify, ./scripts/lint (build only), go test -race ./internal/autocomplete ./cmd/openai -count=1, and go vet ./internal/autocomplete ./cmd/openai.
  • GOOS=windows GOARCH=amd64 go test -c -o /tmp/openai-cli-windows-tests/ ./... (output directory abbreviated here); no Windows runtime test.
  • Changed-file formatting and diff checks; rendered Bash execution; Bash, Zsh and PowerShell syntax checks. Fish was unavailable; Zsh and PowerShell runtime behavior was not tested.
  • Fresh before/after binaries: nested --fo changes from empty output to --format and --format-error; root output stays the same. All four probes exit 0 with empty stderr. The initial inherited-completion regression failed on the original implementation.

Full ./scripts/test mock suite NOT RUN locally: the pinned Steady bootstrap failed loading the JSR @std/cli manifest. A direct connectivity probe and an existing local health response did not establish a working mock server. No network or security controls were bypassed. Full CI/mock-suite validation remains required.

Copilot AI lite review requested due to automatic review settings September 8, 2026 01:21
@markstuart-oai markstuart-oai added the autoimprove Scoped automated improvement label Sep 8, 2026
@markstuart-oai
markstuart-oai requested a review from a team as a code owner September 8, 2026 01:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-08T01:24:25.289903Z 3fa6361 PR opened
🔒 Security Review Completed 2026-09-08T01:23:58.305187Z 3fa6361 PR opened
ℹ️ 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.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Castiron custom code

✅ No new custom-code files detected.

5 mixed files remain; 0 existing customizations changed.

Compared 094a4ab96e803fa6361069c7. Generated baselines verified.

5 existing customizations unchanged
  • pkg/cmd/adminorganizationcertificate.go
  • pkg/cmd/cmd.go
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 34176372943 --repo openai/openai-cli \
  --name castiron-custom-code-34176372943-1 --dir /tmp/castiron-custom-code-34176372943-1
git apply --stat /tmp/castiron-custom-code-34176372943-1/custom-code.patch
cat /tmp/castiron-custom-code-34176372943-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 094a4ab96e80c2952c830ae36a9a9f009617e5ec 3fa6361069c7a513f52718d4067d46e93dc289bc
python3 scripts/castiron/custom_code_report.py report \
  --base 094a4ab96e80c2952c830ae36a9a9f009617e5ec \
  --head 3fa6361069c7a513f52718d4067d46e93dc289bc --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-3fa6361069c7
cat /tmp/castiron-custom-code-3fa6361069c7/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

@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: 3fa6361069

ℹ️ 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".

completions = builder.createFromFlag(current, &flag, completions)
}
seen := map[string]bool{}
for flag := range inheritedFlags(cmd, ancestors) {

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 Stop inherited completion after the option terminator

When a nested invocation already contains a standalone -- (for example, openai models list -- --fo), traversal does not record that option parsing has ended, so this loop newly suggests inherited flags such as --format even though every following token is positional. The same issue can misclassify a later inherited flag as value-taking and suppress normal positional/file completion; inherited lookup should be disabled after consuming the separator.

Useful? React with 👍 / 👎.

Copilot AI 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.

🟡 Changes recommended

Hidden local flags are currently skipped for traversal but still suggested for completion, which can mis-handle value consumption and expose hidden flags in completion output.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes CLI flag autocompletion so that nested subcommands (e.g., models list) can complete flags inherited from ancestor commands, while preserving urfave/cli inheritance precedence and value-consumption semantics.

Changes:

  • Extend completion traversal to consider inherited (ancestor) flags and consume their values while walking subcommands.
  • Add targeted regression tests covering raw vs initialized command trees, protocol behavior, and the production main entrypoint completion output.
  • Validate shadowing/precedence rules (nearest-ancestor wins, child aliases suppress ancestor flags, Local flags don’t inherit, hidden inherited flags aren’t suggested).
File summaries
File Description
internal/autocomplete/autocomplete.go Implements inherited-flag discovery during traversal and augments flag completion to include inherited candidates.
internal/autocomplete/protocol_test.go Adds protocol-level test cases for inherited flag completion/value/file behavior under nested commands.
internal/autocomplete/inheritance_test.go New unit tests that pin inheritance/precedence and parser contract behaviors for completion.
cmd/openai/completion_test.go New integration-style test that runs the real main completion path in a subprocess with sanitized environment.
Review details

Suppressed comments (1)

internal/autocomplete/autocomplete.go:307

  • Flag-name completion currently includes hidden local flags because cmd.Flags are always passed to createFromFlag without checking cli.VisibleFlag. This is inconsistent with the inherited-flag path (which filters hidden flags) and can leak Hidden=true flags into completion output.
	if isFlag(current) {
		for _, flag := range cmd.Flags {
			completions = builder.createFromFlag(current, &flag, completions)
		}
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 105 to 115
@@ -112,9 +113,44 @@ func findFlag(cmd *cli.Command, arg string) *cli.Flag {
return &flag
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autoimprove Scoped automated improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants