gastownhall/beads · error

no rules to compact

Error message

no rules to compact

What it means

CompactRules rejects an empty rules slice because merging zero rules cannot produce a meaningful composite markdown file. It is a guard against producing empty/degenerate output rather than a runtime failure.

Source

Thrown at cmd/bd/rules.go:517

	bestCount := 0
	for w, c := range freq {
		if c > bestCount || (c == bestCount && w < bestWord) {
			bestWord = w
			bestCount = c
		}
	}
	return bestWord
}

// roundTo2 rounds a float to 2 decimal places.
func roundTo2(f float64) float64 {
	return float64(int(f*100+0.5)) / 100
}

// CompactRules merges a group of rules into a single composite markdown file.
func CompactRules(rules []RuleFile, groupLabel string) (string, error) {
	if len(rules) == 0 {
		return "", fmt.Errorf("no rules to compact")
	}

	// Collect and deduplicate Do/Don't lines
	seenDo := make(map[string]bool)
	seenDont := make(map[string]bool)
	var doLines, dontLines []string

	for _, r := range rules {
		for _, line := range r.DoLines {
			trimmed := strings.TrimSpace(line)
			if trimmed != "" && !seenDo[trimmed] {
				seenDo[trimmed] = true
				doLines = append(doLines, trimmed)
			}
		}
		for _, line := range r.DontLines {
			trimmed := strings.TrimSpace(line)
			if trimmed != "" && !seenDont[trimmed] {

View on GitHub (pinned to 71377f2769)

Solutions

  1. Check len(rules) > 0 before calling CompactRules.
  2. Skip compaction (or print a friendly message) when the rules directory yields no RuleFiles.
  3. Create at least one rule .md file in the rules directory.

Example fix

// before
out, err := CompactRules(rules, group)
// after
if len(rules) == 0 {
    fmt.Fprintln(os.Stderr, "no rules found; nothing to compact")
    return nil
}
out, err := CompactRules(rules, group)
Defensive patterns

Strategy: validation

Validate before calling

if len(rules) == 0 {
    return nil // or skip compaction with a friendly message
}

Prevention

When it happens

Trigger: Calling CompactRules with a nil or empty []RuleFile, e.g. when the rules directory contained no parseable rules or was empty.

Common situations: Running `bd rules compact` in a repo with no .beads rules files; RunAudit returned an empty result and callers pass it straight through; filtering removed all rules before compaction.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/467fdbc7da59c6ae. Report an issue: GitHub.