feat: Add HasSubcommands() so menus don't require discovery - #63
Open
boblail wants to merge 1 commit into
Open
Conversation
Rendering a menu called Subcommands() on every child twice — once in Expand() (even at depth 0, where the result was discarded) and once to decide whether to render the ':' sigil. Both calls can trigger discovery, which may exec the child. Expand() now returns immediately at depth 0, and the sigil is rendered with the new HasSubcommands() predicate, which answers "may this command have subcommands?" without performing discovery. Commands built by external contracts can opt in via the SubcommandsReporter interface; otherwise HasSubcommands() falls back to calling Subcommands(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
boblail
commented
Aug 19, 2026
| return parallelMap(c, func(cmd Command) ([]Command, []error) { | ||
| // At depth 0, nothing is expanded; don't ask for subcommands at all | ||
| // because Subcommands() may trigger discovery. | ||
| if depth == 0 { |
Member
Author
There was a problem hiding this comment.
Optimization: check this before calling cmd.Subcommands() 👍
boblail
marked this pull request as ready for review
August 19, 2026 00:21
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.
Rendering a menu called
Subcommands()on every child twice — once inExpand()(even at depth 0, where the result was discarded) and once to decide whether to render the:sigil — and both calls can trigger discovery, which may exec the child.Expand()now returns immediately at depth 0, and the sigil is rendered with the newHasSubcommands()predicate, which answers "may this command have subcommands?" without performing discovery. The sigil accordingly now means "may have subcommands": an empty module keeps its:at depth 0. Commands built by external contracts can opt in via theSubcommandsReporterinterface; otherwiseHasSubcommands()falls back to callingSubcommands(), preserving today's behaviour.Groundwork for progressive OpenCLI discovery (#62).
🤖 Generated with Claude Code