Collapse identical sibling flag sets in single mode#7
Merged
Conversation
Real-usage feedback: in CLIs like `infractl k8s actions`, six sibling leaves (cycle, triage, terminate, reboot, ignore, trigger-hw-check) all took the same -p <instances> and -r <reason> flags. Skillgen emitted the flag table six times, ~45 lines of pure duplication. When a parent command's visible children all have exactly the same local-flag fingerprint (name, shorthand, type, required-ness, and usage text), skillgen now hoists the flag table onto the parent section and suppresses the per-child list. Differences in any of those dimensions disable the collapse — agents must never see a subtly wrong shared flag list. collectDescendants now returns the flattened slice *and* a separate rootShared []FlagData for flags hoisted up to the root's own section (since the root isn't part of the slice). flagFingerprint + helpers stay internal. CommandData gains SharedChildrenFlags (parent) and SkipFlagsInRender (children) so custom templates can inspect or override the collapse decision. Split mode is unaffected — each leaf is already standalone. Eight new tests in sibling_collapse_test.go cover: happy path, partial-overlap non-collapse, usage-text-difference non-collapse, no-flag parents, single-child parents, root-level collapse, determinism between runs, and split-mode invariance. README gets a "Sibling collapse" section with an example output snippet; CHANGELOG picks up an Added entry under Unreleased.
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.
Summary
When a parent command's visible children all have exactly the same local-flag fingerprint (name, shorthand, type, required-ness, and usage text), skillgen now hoists the flag block onto the parent section and suppresses the per-child list.
Detection predicate
Siblings collapse only when every one of the following matches across all children:
Any mismatch — including a different usage string — disables the collapse for that parent. The agent must never see a subtly wrong shared flag list. Parents with only one visible child or no flags at all are never collapsed.
Output shape
When collapse fires the parent section gets a new "Shared subcommand flags" block and each child skips its own `Flags:` list:
```markdown
`mytool actions`
Shared subcommand flags (apply to every subcommand below):
`mytool actions cycle`
Move past a bad node.
`mytool actions triage`
Preserve for investigation.
```
Top-level siblings use an `## Shared subcommand flags` block on the root section itself.
Public API
`CommandData` gains two new fields so custom templates can inspect or override the decision:
Split mode
Unaffected. Each leaf is already its own standalone skill with its own flag table — nothing to collapse.
Test plan