Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
402ec08
Add a skills source interface over fs.FS
simonfaltum Nov 25, 2026
2df5cf8
Share the install state file name with libs/skills
simonfaltum Nov 25, 2026
aa6b7d3
Compare skill fixtures with normalized line endings
simonfaltum Nov 25, 2026
fb7d076
Address review on the skills source
simonfaltum Nov 25, 2026
c1365d3
Add the skills command group behind DATABRICKS_SKILLS_PREVIEW
simonfaltum Nov 26, 2026
b2a2be6
Print the skills catalog from skills list
simonfaltum Nov 26, 2026
055acad
Add a skills source interface over fs.FS
simonfaltum Nov 25, 2026
79c67cd
Share the install state file name with libs/skills
simonfaltum Nov 25, 2026
4530158
Compare skill fixtures with normalized line endings
simonfaltum Nov 25, 2026
b61b62d
Address review on the skills source
simonfaltum Nov 25, 2026
2906664
Skill source: unexport escapesDir, reject a catalog_rules directory
simonfaltum Nov 26, 2026
ddbdb00
Carry the minimum CLI version on skills catalog entries
simonfaltum Nov 26, 2026
41dfd3d
Add the skills command group behind DATABRICKS_SKILLS_PREVIEW
simonfaltum Nov 26, 2026
417ae32
Merge origin/main into skills/c2-skills-command-group-behind-an-env-v…
simonfaltum Nov 27, 2026
c75c37c
Merge skills c2 tip into skills list branch
simonfaltum Nov 27, 2026
fcd2902
Check skills command name against root commands, clear env in guard t…
simonfaltum Nov 27, 2026
497ff28
Print the skills catalog from skills list
simonfaltum Nov 27, 2026
53c8155
Merge skills c2 tip into skills list branch
simonfaltum Nov 27, 2026
4844df8
Keep skills list text within the budget and route its JSON through cmdio
simonfaltum Nov 27, 2026
b262160
Merge origin/main into skills list branch
simonfaltum Nov 27, 2026
c3c22dd
Merge origin/main into skills list branch
simonfaltum Nov 27, 2026
6729933
Update agent-hints acceptance test for implemented skills list
simonfaltum Nov 27, 2026
3ac93e6
Merge origin/main into skills list branch
simonfaltum Nov 27, 2026
b10ce6a
Keep skills list acceptance in step with merged siblings
simonfaltum Nov 27, 2026
c4a5e80
Keep each skills list description within the text budget
simonfaltum Nov 27, 2026
ca310ed
Pick the widest skills list width that fits the budget
simonfaltum Nov 27, 2026
047b7e2
Check the names-only skills list layout before the width search
simonfaltum Nov 27, 2026
5dd7276
Bound the skills list width search
simonfaltum Nov 27, 2026
126f116
Merge origin/main into the skills list branch
simonfaltum Nov 27, 2026
50bad47
Merge commit '126f1165d' into skills/klistfast-skills-list-bound-the-…
simonfaltum Nov 27, 2026
fe1d82b
Measure the 400-skill width search in a benchmark
simonfaltum Nov 27, 2026
2208734
Merge origin/main into skills list branch
simonfaltum Nov 27, 2026
607d861
Tighten width search comments and test
simonfaltum Nov 30, 2026
0416fe8
skills list: describe renderTextScan as a reference for the width search
simonfaltum Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 57 additions & 11 deletions cmd/skills/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"path/filepath"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -97,6 +98,9 @@ func renderText(rules string, list []libskills.Skill) string {
if len(list) == 0 {
return withRules(rules) + "No skills found.\n"
}
// Every width lays the list out again, so each description is joined into
// one line once, here.
list = oneLineSkills(list)
// A description only makes its line longer, and the search hint is the one
// line a wider width can leave out. So when the names do not fit even with
// the hint, no width does, and the names-only text is the answer.
Expand All @@ -106,29 +110,61 @@ func renderText(rules string, list []libskills.Skill) string {
}
maxLen := 0
for _, s := range list {
maxLen = max(maxLen, len(oneLine(s.Description)))
}
// The length is not monotonic in width: a wider width can drop the search
// hint, so a binary search could settle on a narrower width than one that
// fits. Try each width from the widest down and keep the first that fits.
for w := min(maxLen, textBudget); w > 0; w-- {
if out := layoutText(rules, list, w); len(out) <= textBudget {
return out
}
maxLen = max(maxLen, len(s.Description))
}
// No width above maxLen cuts a description, so the widest width to try is
// the smaller of maxLen and the budget.
top := min(maxLen, textBudget)
fits := func(w int) bool { return len(layoutText(rules, list, w)) <= textBudget }
// The length is not monotonic in width: once no description is left out, the
// search hint goes away, so a wider width can be shorter. Below the first
// width at which no description is left out the hint is always there, and from
// that width on it never is, so the length only grows within each part. The
// widest fitting width is searched in the upper part first, then the lower.
complete := 1 + sort.Search(top, func(i int) bool { return !dropsAny(list, i+1) })
if w := widestFitIn(complete, top, fits); w > 0 {
return layoutText(rules, list, w)
}
if w := widestFitIn(1, complete-1, fits); w > 0 {
return layoutText(rules, list, w)
}
return names
}

// widestFitIn returns the widest width in [lo, hi] that fits, or 0 when lo does
// not fit. Within [lo, hi] fits must hold up to some width and fail above it.
func widestFitIn(lo, hi int, fits func(int) bool) int {
if hi < lo || !fits(lo) {
return 0
}
first := sort.Search(hi-lo+1, func(i int) bool { return !fits(lo + i) })
return lo + first - 1
}

// dropsAny reports whether layoutText at width leaves some description out.
// It goes false once no description is left out, and stays false above it. It
// must match the dropped rule in layoutText.
func dropsAny(list []libskills.Skill, width int) bool {
for _, s := range list {
if desc := s.Description; desc != "" && cutWords(desc, width) == "" {
return true
}
}
return false
}

// layoutText lays out the text output with descriptions cut to width. A width
// of 0 leaves every description out. A skill is listed by its name alone when
// its description is left out or has no word boundary within width, so one
// long description does not drop the others.
// long description does not drop the others. Descriptions must be one line.
// The search hint must stay the only line a wider width can leave out: the
// width search in renderText relies on it, together with dropsAny.
func layoutText(rules string, list []libskills.Skill, width int) string {
var b strings.Builder
b.WriteString(withRules(rules))
dropped := false
for _, s := range list {
desc := oneLine(s.Description)
desc := s.Description
cut := ""
if width > 0 {
cut = cutWords(desc, width)
Expand All @@ -147,6 +183,16 @@ func layoutText(rules string, list []libskills.Skill, width int) string {
return b.String()
}

// oneLineSkills returns list with each description joined into one line.
func oneLineSkills(list []libskills.Skill) []libskills.Skill {
out := make([]libskills.Skill, len(list))
for i, s := range list {
s.Description = oneLine(s.Description)
out[i] = s
}
return out
}

// oneLine joins the words of s with single spaces, so a description takes
// exactly one line of output.
func oneLine(s string) string {
Expand Down
104 changes: 104 additions & 0 deletions cmd/skills/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"math/rand/v2"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -152,6 +153,109 @@ func TestRenderTextKeepsWidestFittingWidth(t *testing.T) {
assert.NotContains(t, out, "databricks skills search")
}

// renderTextScan is a brute-force reference for the width search: it tries
// every width from the widest down and keeps the first that fits. It shares
// oneLineSkills and layoutText with renderText, so it checks the search only.
func renderTextScan(rules string, list []libskills.Skill) string {
if len(list) == 0 {
return withRules(rules) + "No skills found.\n"
}
list = oneLineSkills(list)
names := layoutText(rules, list, 0)
if len(names)-len(searchHint)-1 > textBudget {
return names
}
maxLen := 0
for _, s := range list {
maxLen = max(maxLen, len(s.Description))
}
for w := min(maxLen, textBudget); w > 0; w-- {
if out := layoutText(rules, list, w); len(out) <= textBudget {
return out
}
}
return names
}

// randomCatalog returns a catalog whose sizes, names, descriptions and rules
// vary with the random source, so the width search meets every case.
func randomCatalog(r *rand.Rand) (string, []libskills.Skill) {
words := []string{"a", "deploy", "the", "workspace", "x", "notebook-run", "describes", "it.", "averyveryverylongwordthatkeepsgoing", " "}
var rules string
if r.IntN(2) == 0 {
rules = strings.Repeat("Pick the skill whose description matches. ", 1+r.IntN(3))
}
// Some catalogs have names long enough that the names alone exceed the budget.
nameLen := 70
if r.IntN(6) == 0 {
nameLen = 200
}
var list []libskills.Skill
for i := range r.IntN(60) {
var desc []string
for range r.IntN(40) {
desc = append(desc, words[r.IntN(len(words))])
}
sep := " "
if r.IntN(10) == 0 {
sep = "\n"
}
text := strings.Join(desc, sep)
if r.IntN(8) == 0 {
// An unbreakable description has no word boundary to cut at.
text = strings.Repeat("x", r.IntN(300))
}
list = append(list, libskills.Skill{
Name: fmt.Sprintf("skill-%d-%s", i, strings.Repeat("n", r.IntN(nameLen))),
Description: text,
})
}
return rules, list
}

func TestRenderTextMatchesWidthScan(t *testing.T) {
for seed := range uint64(300) {
r := rand.New(rand.NewPCG(seed, 1))
rules, list := randomCatalog(r)
want := renderTextScan(rules, list)
got := renderText(rules, list)
if !assert.Equal(t, want, got, "seed %d", seed) {
return
}
}
}

// fourHundredLongSkills returns 400 skills whose descriptions are each far
// longer than the text budget.
func fourHundredLongSkills() []libskills.Skill {
var list []libskills.Skill
for i := range 400 {
desc := strings.Repeat(fmt.Sprintf("word%d describes the skill in detail. ", i), 40)
list = append(list, libskills.Skill{Name: fmt.Sprintf("s%03d", i), Description: desc})
}
return list
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] This test passes even if renderText falls back to names only. The names-only layout of this catalog is also under textBudget and also contains s399. Today the output keeps about 100 descriptions. Comparing against renderTextScan(rules, list), or asserting that some description text such as "s000: word0" is present, would make it catch that regression.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 607d861. The test now also asserts s000: word0 is in the output, so a fall back to names only fails it. I did not compare against renderTextScan because the full scan takes seconds on this catalog.

func TestRenderTextFourHundredLongDescriptionsFitsBudget(t *testing.T) {
out := renderText("Pick the skill whose description matches the task.", fourHundredLongSkills())
assert.LessOrEqual(t, len(out), textBudget)
assert.Contains(t, out, "s399")
// Names alone would also fit, so check that descriptions are kept.
assert.Contains(t, out, "s000: word0")
}

// BenchmarkRenderTextFourHundredLongDescriptions measures the width search on

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] "the 50 ms the search must stay under" refers to the assertion removed in fe1d82b. Nothing else in the repo defines that bound. Consider dropping the number, or saying where it comes from (for example, "the full scan took about 16 s here").

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in 607d861. The benchmark comment no longer cites the 50 ms figure. It now says the full width scan takes seconds on the same catalog.

// a 400-skill catalog with long descriptions. The time per op is the figure to
// watch; the full width scan takes seconds on the same catalog.
func BenchmarkRenderTextFourHundredLongDescriptions(b *testing.B) {
list := fourHundredLongSkills()
const rules = "Pick the skill whose description matches the task."
b.ReportAllocs()
for b.Loop() {
renderText(rules, list)
}
}

func TestRenderTextNoSearchHintWithoutDescriptions(t *testing.T) {
list := []libskills.Skill{{Name: "alpha"}, {Name: "beta"}}
assert.Equal(t, "alpha\nbeta\n"+readHint+"\n", renderText("", list))
Expand Down
Loading