Note that highlight.stroke accepts a dictionary which you can use like this
#let pill(a, b, fill: red) = {
highlight(
fill: fill,
stroke: fill,
radius: (left: 100%),
[~~~~~]
)
h(-.7em)
highlight(
fill: fill,
stroke: fill,
text(white, [#a~])
)
highlight(
fill: none,
stroke: (y: fill),
text(fill, [~#b])
)
h(-.7em)
highlight(
fill: none,
stroke: (y: fill, right: fill),
radius: (right: 100%),
text(fill, [~~~~~])
)
}

Still not perfect maybe but betterer.