Skip to content

Collapse identical sibling flag sets in single mode#7

Merged
bueti merged 1 commit into
mainfrom
v0.4-sibling-collapse
Apr 18, 2026
Merged

Collapse identical sibling flag sets in single mode#7
bueti merged 1 commit into
mainfrom
v0.4-sibling-collapse

Conversation

@bueti
Copy link
Copy Markdown
Owner

@bueti bueti commented Apr 18, 2026

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:

  • flag name
  • shorthand letter
  • value type
  • required/optional status
  • usage text

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):

  • `-p, --instances` (required) — target instances
  • `-r, --reason` (required) — justification for the action

`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:

  • `SharedChildrenFlags []FlagData` on a parent whose children were collapsed.
  • `SkipFlagsInRender bool` on each child in a collapsed group.

Split mode

Unaffected. Each leaf is already its own standalone skill with its own flag table — nothing to collapse.

Test plan

  • `go build ./...`
  • `go test ./...` — 8 new tests in `sibling_collapse_test.go` pass alongside existing suite
  • `go vet ./...`
  • `golangci-lint run ./...` — 0 issues
  • `go run ./example skills print` — output unchanged (example subcommands have different flag sets, so nothing collapses)
  • CI matrix (Linux / macOS / Windows on Go 1.25) once it runs on the PR

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.
@bueti bueti merged commit 471c9d0 into main Apr 18, 2026
4 checks passed
@bueti bueti deleted the v0.4-sibling-collapse branch April 18, 2026 18:50
@bueti bueti mentioned this pull request Apr 18, 2026
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.

1 participant