Skip to content

Core: duplicated leaf helpers — label sanitization and host matching #1581

Closed

Description

@huang195

What

Two leaf-helper families are copy-pasted across packages:

Label sanitization/truncation — 3 copies. truncateLabel, sanitizeLabel, hasControlRunes have byte-identical bodies in core/cost/usage/usage.go:1569-1662 and core/cost/ledger/row.go:210-304 (~45 lines each; only the comments differ). cmd/agentop/tui/usage_render.go:687 has a third, weaker variant (C0/DEL only). The rune predicate was already extracted (pipeline.IsControlRune, imported by both cost packages) — row.go:256 explicitly says the rule was extracted but the loops were not.

Host matching — 4 copies. matchesAnyHost (identical port-strip + path.Match glob) at cpex/plugin.go:460, ibac/plugin.go:572, lineage/plugin.go:789, sparc/collect.go:148.

Fix

SanitizeLabel/TruncateLabel beside pipeline.IsControlRune (or a tiny leaf), with each package keeping its policy comments and thin wrappers; one hostmatch helper in core/plugins/internal. ~130 lines deleted and the stored-vs-rendered control-rune handling stops differing.

Found in the 2026-10-29 structural audit of code organization.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions