From 4243c2ae6705d4d6cc9d1cca4b793e1061ebc859 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 14:06:17 +0000 Subject: [PATCH 01/14] cmd/skills: end flags before a leading-hyphen file in read output `skills read` printed `databricks skills read-file ` for each supporting file. A name or path that starts with "-" was read by Cobra as a flag when the agent ran the printed command. Print "--" before the arguments when the name or the file starts with "-". Ordinary names print as before. Co-authored-by: Isaac --- acceptance/cmd/skills/hyphen/manifest.json | 6 +++++ acceptance/cmd/skills/hyphen/out.test.toml | 1 + acceptance/cmd/skills/hyphen/output.txt | 23 +++++++++++++++++++ acceptance/cmd/skills/hyphen/script | 11 +++++++++ .../skills/hyphen/skills/demo-skill/-notes.md | 1 + .../skills/hyphen/skills/demo-skill/SKILL.md | 6 +++++ acceptance/cmd/skills/hyphen/test.toml | 3 +++ cmd/skills/read.go | 7 +++++- cmd/skills/read_test.go | 12 ++++++++++ 9 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 acceptance/cmd/skills/hyphen/manifest.json create mode 100644 acceptance/cmd/skills/hyphen/out.test.toml create mode 100644 acceptance/cmd/skills/hyphen/output.txt create mode 100644 acceptance/cmd/skills/hyphen/script create mode 100644 acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md create mode 100644 acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md create mode 100644 acceptance/cmd/skills/hyphen/test.toml diff --git a/acceptance/cmd/skills/hyphen/manifest.json b/acceptance/cmd/skills/hyphen/manifest.json new file mode 100644 index 00000000000..7aff125e539 --- /dev/null +++ b/acceptance/cmd/skills/hyphen/manifest.json @@ -0,0 +1,6 @@ +{ + "version": "0.0.1", + "skills": { + "demo-skill": {"version": "0.0.1", "description": "A skill with a file named with a leading hyphen.", "files": ["SKILL.md", "-notes.md"]} + } +} diff --git a/acceptance/cmd/skills/hyphen/out.test.toml b/acceptance/cmd/skills/hyphen/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/cmd/skills/hyphen/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/cmd/skills/hyphen/output.txt b/acceptance/cmd/skills/hyphen/output.txt new file mode 100644 index 00000000000..e543d5b4797 --- /dev/null +++ b/acceptance/cmd/skills/hyphen/output.txt @@ -0,0 +1,23 @@ + +=== the read output prints the command for -notes.md after -- + +>>> [CLI] skills read demo-skill +--- +name: demo-skill +description: A skill with a file named with a leading hyphen. +--- + +# Demo skill + +Other files in this skill, each read with its command: + databricks skills read-file -- demo-skill -notes.md + +=== the printed command runs as printed and prints the file + +>>> eval databricks skills read-file -- demo-skill -notes.md +Notes that start with a hyphen. + +=== read-file with -- reads the file directly + +>>> [CLI] skills read-file -- demo-skill -notes.md +Notes that start with a hyphen. diff --git a/acceptance/cmd/skills/hyphen/script b/acceptance/cmd/skills/hyphen/script new file mode 100644 index 00000000000..22e9d59ab4a --- /dev/null +++ b/acceptance/cmd/skills/hyphen/script @@ -0,0 +1,11 @@ +# The printed read-file command ends the flags, so a file named -notes.md is read. +title "the read output prints the command for -notes.md after --" +trace $CLI skills read demo-skill + +title "the printed command runs as printed and prints the file" +databricks() { "$CLI" "$@"; } +line=$($CLI skills read demo-skill | grep -- '-notes.md') +trace eval "$line" + +title "read-file with -- reads the file directly" +trace $CLI skills read-file -- demo-skill -notes.md diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md b/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md new file mode 100644 index 00000000000..8655544cc84 --- /dev/null +++ b/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md @@ -0,0 +1 @@ +Notes that start with a hyphen. diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md b/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md new file mode 100644 index 00000000000..2ef8ee6ba8e --- /dev/null +++ b/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md @@ -0,0 +1,6 @@ +--- +name: demo-skill +description: A skill with a file named with a leading hyphen. +--- + +# Demo skill diff --git a/acceptance/cmd/skills/hyphen/test.toml b/acceptance/cmd/skills/hyphen/test.toml new file mode 100644 index 00000000000..f7c4cc2e00e --- /dev/null +++ b/acceptance/cmd/skills/hyphen/test.toml @@ -0,0 +1,3 @@ +Cloud = false +Env.DATABRICKS_SKILLS_PREVIEW = "1" +Env.DATABRICKS_SKILLS_DIR = "." diff --git a/cmd/skills/read.go b/cmd/skills/read.go index 09ba8b617c0..ed4c253430c 100644 --- a/cmd/skills/read.go +++ b/cmd/skills/read.go @@ -122,7 +122,12 @@ func writeReadText(w io.Writer, goos, name string, content []byte, files []strin fmt.Fprintf(&b, " %s\n", f) continue } - fmt.Fprintf(&b, " databricks skills read-file %s %s\n", quotedName, quotedFile) + // A leading "-" would make Cobra read the name or file as a flag, so "--" ends the flags first. + endOfFlags := "" + if strings.HasPrefix(name, "-") || strings.HasPrefix(f, "-") { + endOfFlags = "-- " + } + fmt.Fprintf(&b, " databricks skills read-file %s%s %s\n", endOfFlags, quotedName, quotedFile) } } _, err := io.WriteString(w, b.String()) diff --git a/cmd/skills/read_test.go b/cmd/skills/read_test.go index cde69b0efa6..23f8ea9da0e 100644 --- a/cmd/skills/read_test.go +++ b/cmd/skills/read_test.go @@ -27,6 +27,18 @@ func TestWriteReadTextQuotesFileCommands(t *testing.T) { assert.Contains(t, out.String(), " databricks skills read-file guide-skill \"references/my guide.md\"\n") } +func TestWriteReadTextEndsFlagsBeforeLeadingHyphenFile(t *testing.T) { + var out bytes.Buffer + err := writeReadText(&out, "linux", "guide-skill", []byte("# Guide\n"), []string{"-notes.md", "references/ok.md"}) + require.NoError(t, err) + assert.Contains(t, out.String(), " databricks skills read-file -- guide-skill -notes.md\n databricks skills read-file guide-skill references/ok.md\n") + + out.Reset() + err = writeReadText(&out, "linux", "-guide-skill", []byte("# Guide\n"), []string{"references/ok.md"}) + require.NoError(t, err) + assert.Contains(t, out.String(), " databricks skills read-file -- -guide-skill references/ok.md\n") +} + func TestWriteReadTextPrintsPathWithoutCommandWhenItCannotBeQuoted(t *testing.T) { var out bytes.Buffer err := writeReadText(&out, "linux", "guide-skill", []byte("# Guide\n"), []string{"references/a\nb.md", "references/ok.md"}) From 2d3660484552fc2b65fdd261580ff65d58d39703 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 14:43:18 +0000 Subject: [PATCH 02/14] libs/skills: end flags before a leading-hyphen skill name in the group footer The help footer for a command group printed "databricks skills read " for each skill. A name that starts with "-" was read by Cobra as a flag when the printed command ran. Print "--" before the name in that case. Ordinary names print as before. Co-authored-by: Isaac --- libs/skills/hints.go | 8 +++++++- libs/skills/hints_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libs/skills/hints.go b/libs/skills/hints.go index ddeabb95118..d8afd77bd18 100644 --- a/libs/skills/hints.go +++ b/libs/skills/hints.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "slices" + "strings" "github.com/databricks/cli/libs/log" ) @@ -49,6 +50,11 @@ func WriteGroupHint(ctx context.Context, w io.Writer, group string) { fmt.Fprintln(w) fmt.Fprintln(w, "Coding agents: read the skills for this command group before you use it.") for _, name := range names { - fmt.Fprintf(w, " databricks skills read %s\n", name) + // A leading "-" would make Cobra read the name as a flag, so "--" ends the flags first. + endOfFlags := "" + if strings.HasPrefix(name, "-") { + endOfFlags = "-- " + } + fmt.Fprintf(w, " databricks skills read %s%s\n", endOfFlags, name) } } diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index 69ddd731676..ceec374e22f 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -2,10 +2,15 @@ package skills import ( "bytes" + "os" + "path/filepath" + "strings" "testing" "github.com/databricks/cli/libs/env" + "github.com/spf13/pflag" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestWriteGroupHint(t *testing.T) { @@ -36,3 +41,25 @@ func TestWriteGroupHint(t *testing.T) { }) } } + +func TestWriteGroupHintRunsLeadingHyphenSkillAsPrinted(t *testing.T) { + dir := t.TempDir() + const manifest = `{"version": "1.0.0", "skills": {"-foo": {"version": "1.0.0", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]}}}` + require.NoError(t, os.WriteFile(filepath.Join(dir, "manifest.json"), []byte(manifest), 0o644)) + + ctx := env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", dir) + ctx = env.Set(ctx, "DATABRICKS_SKILLS_PREVIEW", "1") + ctx = env.Set(ctx, "DATABRICKS_SKILLS_HINTS", "1") + + var buf bytes.Buffer + WriteGroupHint(ctx, &buf, "jobs") + assert.Equal(t, "\nCoding agents: read the skills for this command group before you use it.\n"+ + " databricks skills read -- -foo\n", buf.String()) + + // The printed command, minus "databricks skills read", must parse to the name, not to flags. + printed := strings.Fields(buf.String()) + args := printed[len(printed)-2:] + fs := pflag.NewFlagSet("read", pflag.ContinueOnError) + require.NoError(t, fs.Parse(args)) + assert.Equal(t, []string{"-foo"}, fs.Args()) +} From 2a5b94f28108eb524ea304f11c730047dc749f79 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 14:44:25 +0000 Subject: [PATCH 03/14] cmd/skills: cover a leading-hyphen file in the read acceptance test Move the printed read-file case into the existing read acceptance test, using the shared release fixture, instead of a separate hyphen directory. The printed command is asserted with contains.py before it is run, and the separate test.toml is dropped because the parent directory sets the same variables. Co-authored-by: Isaac --- acceptance/cmd/skills/hyphen/manifest.json | 6 ----- acceptance/cmd/skills/hyphen/out.test.toml | 1 - acceptance/cmd/skills/hyphen/output.txt | 23 ------------------- acceptance/cmd/skills/hyphen/script | 11 --------- .../skills/hyphen/skills/demo-skill/SKILL.md | 6 ----- acceptance/cmd/skills/hyphen/test.toml | 3 --- acceptance/cmd/skills/read/output.txt | 14 ++++++++++- acceptance/cmd/skills/read/script | 9 ++++++++ acceptance/cmd/skills/release/manifest.json | 2 +- .../skills/guide-skill}/-notes.md | 0 10 files changed, 23 insertions(+), 52 deletions(-) delete mode 100644 acceptance/cmd/skills/hyphen/manifest.json delete mode 100644 acceptance/cmd/skills/hyphen/out.test.toml delete mode 100644 acceptance/cmd/skills/hyphen/output.txt delete mode 100644 acceptance/cmd/skills/hyphen/script delete mode 100644 acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md delete mode 100644 acceptance/cmd/skills/hyphen/test.toml rename acceptance/cmd/skills/{hyphen/skills/demo-skill => release/skills/guide-skill}/-notes.md (100%) diff --git a/acceptance/cmd/skills/hyphen/manifest.json b/acceptance/cmd/skills/hyphen/manifest.json deleted file mode 100644 index 7aff125e539..00000000000 --- a/acceptance/cmd/skills/hyphen/manifest.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "version": "0.0.1", - "skills": { - "demo-skill": {"version": "0.0.1", "description": "A skill with a file named with a leading hyphen.", "files": ["SKILL.md", "-notes.md"]} - } -} diff --git a/acceptance/cmd/skills/hyphen/out.test.toml b/acceptance/cmd/skills/hyphen/out.test.toml deleted file mode 100644 index 18b1a88417e..00000000000 --- a/acceptance/cmd/skills/hyphen/out.test.toml +++ /dev/null @@ -1 +0,0 @@ -Cloud = false diff --git a/acceptance/cmd/skills/hyphen/output.txt b/acceptance/cmd/skills/hyphen/output.txt deleted file mode 100644 index e543d5b4797..00000000000 --- a/acceptance/cmd/skills/hyphen/output.txt +++ /dev/null @@ -1,23 +0,0 @@ - -=== the read output prints the command for -notes.md after -- - ->>> [CLI] skills read demo-skill ---- -name: demo-skill -description: A skill with a file named with a leading hyphen. ---- - -# Demo skill - -Other files in this skill, each read with its command: - databricks skills read-file -- demo-skill -notes.md - -=== the printed command runs as printed and prints the file - ->>> eval databricks skills read-file -- demo-skill -notes.md -Notes that start with a hyphen. - -=== read-file with -- reads the file directly - ->>> [CLI] skills read-file -- demo-skill -notes.md -Notes that start with a hyphen. diff --git a/acceptance/cmd/skills/hyphen/script b/acceptance/cmd/skills/hyphen/script deleted file mode 100644 index 22e9d59ab4a..00000000000 --- a/acceptance/cmd/skills/hyphen/script +++ /dev/null @@ -1,11 +0,0 @@ -# The printed read-file command ends the flags, so a file named -notes.md is read. -title "the read output prints the command for -notes.md after --" -trace $CLI skills read demo-skill - -title "the printed command runs as printed and prints the file" -databricks() { "$CLI" "$@"; } -line=$($CLI skills read demo-skill | grep -- '-notes.md') -trace eval "$line" - -title "read-file with -- reads the file directly" -trace $CLI skills read-file -- demo-skill -notes.md diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md b/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md deleted file mode 100644 index 2ef8ee6ba8e..00000000000 --- a/acceptance/cmd/skills/hyphen/skills/demo-skill/SKILL.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -name: demo-skill -description: A skill with a file named with a leading hyphen. ---- - -# Demo skill diff --git a/acceptance/cmd/skills/hyphen/test.toml b/acceptance/cmd/skills/hyphen/test.toml deleted file mode 100644 index f7c4cc2e00e..00000000000 --- a/acceptance/cmd/skills/hyphen/test.toml +++ /dev/null @@ -1,3 +0,0 @@ -Cloud = false -Env.DATABRICKS_SKILLS_PREVIEW = "1" -Env.DATABRICKS_SKILLS_DIR = "." diff --git a/acceptance/cmd/skills/read/output.txt b/acceptance/cmd/skills/read/output.txt index 1b298027865..c046e6dce10 100644 --- a/acceptance/cmd/skills/read/output.txt +++ b/acceptance/cmd/skills/read/output.txt @@ -13,6 +13,17 @@ Read the guide in references for details. Other files in this skill, each read with its command: databricks skills read-file guide-skill references/guide.md + databricks skills read-file -- guide-skill -notes.md + +=== A file whose name starts with a hyphen: the printed command ends the flags and runs as printed + +>>> eval databricks skills read-file -- guide-skill -notes.md +Notes that start with a hyphen. + +=== read-file accepts -- before a leading-hyphen file name + +>>> [CLI] skills read-file -- guide-skill -notes.md +Notes that start with a hyphen. === A skill without supporting files @@ -33,7 +44,8 @@ description: A skill for tests. "source": "[TESTROOT]/cmd/skills/read/../release", "content": "---\nname: guide-skill\ndescription: A skill with a supporting file.\n---\n\n# Guide skill\n\nRead the guide in references for details.\n", "files": [ - "references/guide.md" + "references/guide.md", + "-notes.md" ] } diff --git a/acceptance/cmd/skills/read/script b/acceptance/cmd/skills/read/script index 99d41334672..a4374f2f307 100644 --- a/acceptance/cmd/skills/read/script +++ b/acceptance/cmd/skills/read/script @@ -4,6 +4,15 @@ export DATABRICKS_SKILLS_DIR=$TESTDIR/../release title "A skill with a supporting file: SKILL.md, then the file list" trace $CLI skills read guide-skill +title "A file whose name starts with a hyphen: the printed command ends the flags and runs as printed" +databricks() { "$CLI" "$@"; } +line="databricks skills read-file -- guide-skill -notes.md" +$CLI skills read guide-skill | contains.py " $line" > /dev/null +trace eval "$line" + +title "read-file accepts -- before a leading-hyphen file name" +trace $CLI skills read-file -- guide-skill -notes.md + title "A skill without supporting files" trace $CLI skills read demo-skill diff --git a/acceptance/cmd/skills/release/manifest.json b/acceptance/cmd/skills/release/manifest.json index 0281c53fe69..5d5b05b1e7d 100644 --- a/acceptance/cmd/skills/release/manifest.json +++ b/acceptance/cmd/skills/release/manifest.json @@ -2,7 +2,7 @@ "version": "0.0.1", "skills": { "demo-skill": {"version": "0.0.1", "description": "A skill for tests.", "files": ["SKILL.md"], "commands": ["fs", "air"]}, - "guide-skill": {"version": "0.0.1", "description": "A skill with a supporting file.", "files": ["SKILL.md", "references/guide.md"]}, + "guide-skill": {"version": "0.0.1", "description": "A skill with a supporting file.", "files": ["SKILL.md", "references/guide.md", "-notes.md"]}, "future-skill": {"version": "0.0.1", "description": "A skill that needs a newer CLI.", "files": ["SKILL.md"], "min_cli_version": "99.0.0"} } } diff --git a/acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md b/acceptance/cmd/skills/release/skills/guide-skill/-notes.md similarity index 100% rename from acceptance/cmd/skills/hyphen/skills/demo-skill/-notes.md rename to acceptance/cmd/skills/release/skills/guide-skill/-notes.md From 7f56db9554a68d78540bbf7f37b730dab44ecb37 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 15:35:27 +0000 Subject: [PATCH 04/14] libs/skills: test the group footer through the real jobs command Add a skill named -foo to the shared acceptance release, and an acceptance test that traces the footer under `jobs --help` and runs the printed command, so the test covers the real root command rather than a bare flag set. The libs/skills catalog test counts the release, so it moves to four skills too. Co-authored-by: Isaac --- acceptance/cmd/skills/release/manifest.json | 3 ++- acceptance/cmd/skills/release/skills/-foo/SKILL.md | 6 ++++++ acceptance/help/skills/hints-hyphen/out.test.toml | 1 + acceptance/help/skills/hints-hyphen/output.txt | 14 ++++++++++++++ acceptance/help/skills/hints-hyphen/script | 8 ++++++++ acceptance/help/skills/hints-hyphen/test.toml | 3 +++ libs/skills/resolve_test.go | 9 +++++---- 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 acceptance/cmd/skills/release/skills/-foo/SKILL.md create mode 100644 acceptance/help/skills/hints-hyphen/out.test.toml create mode 100644 acceptance/help/skills/hints-hyphen/output.txt create mode 100644 acceptance/help/skills/hints-hyphen/script create mode 100644 acceptance/help/skills/hints-hyphen/test.toml diff --git a/acceptance/cmd/skills/release/manifest.json b/acceptance/cmd/skills/release/manifest.json index 0281c53fe69..e9351246685 100644 --- a/acceptance/cmd/skills/release/manifest.json +++ b/acceptance/cmd/skills/release/manifest.json @@ -3,6 +3,7 @@ "skills": { "demo-skill": {"version": "0.0.1", "description": "A skill for tests.", "files": ["SKILL.md"], "commands": ["fs", "air"]}, "guide-skill": {"version": "0.0.1", "description": "A skill with a supporting file.", "files": ["SKILL.md", "references/guide.md"]}, - "future-skill": {"version": "0.0.1", "description": "A skill that needs a newer CLI.", "files": ["SKILL.md"], "min_cli_version": "99.0.0"} + "future-skill": {"version": "0.0.1", "description": "A skill that needs a newer CLI.", "files": ["SKILL.md"], "min_cli_version": "99.0.0"}, + "-foo": {"version": "0.0.1", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]} } } diff --git a/acceptance/cmd/skills/release/skills/-foo/SKILL.md b/acceptance/cmd/skills/release/skills/-foo/SKILL.md new file mode 100644 index 00000000000..9c36f6fb254 --- /dev/null +++ b/acceptance/cmd/skills/release/skills/-foo/SKILL.md @@ -0,0 +1,6 @@ +--- +name: -foo +description: A skill whose name starts with a hyphen. +--- + +# Foo skill diff --git a/acceptance/help/skills/hints-hyphen/out.test.toml b/acceptance/help/skills/hints-hyphen/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/help/skills/hints-hyphen/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/help/skills/hints-hyphen/output.txt b/acceptance/help/skills/hints-hyphen/output.txt new file mode 100644 index 00000000000..eca55a5f1da --- /dev/null +++ b/acceptance/help/skills/hints-hyphen/output.txt @@ -0,0 +1,14 @@ + +>>> [CLI] jobs --help +Use "databricks jobs [command] --help" for more information about a command. + +Coding agents: read the skills for this command group before you use it. + databricks skills read -- -foo + +>>> eval databricks skills read -- -foo +--- +name: -foo +description: A skill whose name starts with a hyphen. +--- + +# Foo skill diff --git a/acceptance/help/skills/hints-hyphen/script b/acceptance/help/skills/hints-hyphen/script new file mode 100644 index 00000000000..9d00f1b5e53 --- /dev/null +++ b/acceptance/help/skills/hints-hyphen/script @@ -0,0 +1,8 @@ +export DATABRICKS_SKILLS_DIR="$TESTDIR/../../../cmd/skills/release" + +# The footer for a group ends the flags before a skill whose name starts with "-", so the printed command runs. +trace $CLI jobs --help | tail -n 4 + +databricks() { "$CLI" "$@"; } +line=$($CLI jobs --help | grep -- ' databricks skills read') +trace eval "$line" diff --git a/acceptance/help/skills/hints-hyphen/test.toml b/acceptance/help/skills/hints-hyphen/test.toml new file mode 100644 index 00000000000..dbb7d352196 --- /dev/null +++ b/acceptance/help/skills/hints-hyphen/test.toml @@ -0,0 +1,3 @@ +Cloud = false +Env.DATABRICKS_SKILLS_HINTS = "1" +Env.DATABRICKS_SKILLS_PREVIEW = "1" diff --git a/libs/skills/resolve_test.go b/libs/skills/resolve_test.go index f836cf389a0..11635aed1c2 100644 --- a/libs/skills/resolve_test.go +++ b/libs/skills/resolve_test.go @@ -38,8 +38,9 @@ func TestLocalCatalogFromAcceptanceFixture(t *testing.T) { dir := filepath.Join("..", "..", "acceptance", "cmd", "skills", "release") catalog, err := LocalCatalog(env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", dir)) require.NoError(t, err) - require.Len(t, catalog.Skills, 3) - assert.Equal(t, "demo-skill", catalog.Skills[0].Name) - assert.Equal(t, "future-skill", catalog.Skills[1].Name) - assert.Equal(t, "guide-skill", catalog.Skills[2].Name) + require.Len(t, catalog.Skills, 4) + assert.Equal(t, "-foo", catalog.Skills[0].Name) + assert.Equal(t, "demo-skill", catalog.Skills[1].Name) + assert.Equal(t, "future-skill", catalog.Skills[2].Name) + assert.Equal(t, "guide-skill", catalog.Skills[3].Name) } From e1931fe3ff6d2822a7ef0be77d8fbd5cf3202a7e Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 15:35:33 +0000 Subject: [PATCH 05/14] libs/skills: leave out skills whose names the installer rejects The installer accepts only skill names of lowercase letters, digits and single hyphens, up to 64 characters. The skills catalog accepted any name from a manifest, so a hand-written DATABRICKS_SKILLS_DIR manifest could list a name with spaces, shell metacharacters or a leading hyphen, and the printed commands broke. The catalog now skips such a skill and logs its name at debug level. The name check moves from the installer into libs/skills as IsSkillName, and the installer uses it from there. Catalogs with valid names are unchanged. Because the catalog only lists valid names, the help footer and the read output no longer need "--" before a skill name. A file name that starts with "-" still gets it. Co-authored-by: Isaac --- cmd/skills/read.go | 4 ++-- cmd/skills/read_test.go | 5 ----- libs/aitools/installer/source.go | 19 ++----------------- libs/skills/fs.go | 7 +++++++ libs/skills/fs_test.go | 21 +++++++++++++++++++++ libs/skills/hints.go | 8 +------- libs/skills/hints_test.go | 19 ++++++------------- libs/skills/manifest.go | 21 +++++++++++++++++++++ libs/skills/skills.go | 4 ++-- 9 files changed, 62 insertions(+), 46 deletions(-) diff --git a/cmd/skills/read.go b/cmd/skills/read.go index ed4c253430c..a7866b085ee 100644 --- a/cmd/skills/read.go +++ b/cmd/skills/read.go @@ -122,9 +122,9 @@ func writeReadText(w io.Writer, goos, name string, content []byte, files []strin fmt.Fprintf(&b, " %s\n", f) continue } - // A leading "-" would make Cobra read the name or file as a flag, so "--" ends the flags first. + // A leading "-" would make Cobra read the file as a flag, so "--" ends the flags first. endOfFlags := "" - if strings.HasPrefix(name, "-") || strings.HasPrefix(f, "-") { + if strings.HasPrefix(f, "-") { endOfFlags = "-- " } fmt.Fprintf(&b, " databricks skills read-file %s%s %s\n", endOfFlags, quotedName, quotedFile) diff --git a/cmd/skills/read_test.go b/cmd/skills/read_test.go index 23f8ea9da0e..001a8239631 100644 --- a/cmd/skills/read_test.go +++ b/cmd/skills/read_test.go @@ -32,11 +32,6 @@ func TestWriteReadTextEndsFlagsBeforeLeadingHyphenFile(t *testing.T) { err := writeReadText(&out, "linux", "guide-skill", []byte("# Guide\n"), []string{"-notes.md", "references/ok.md"}) require.NoError(t, err) assert.Contains(t, out.String(), " databricks skills read-file -- guide-skill -notes.md\n databricks skills read-file guide-skill references/ok.md\n") - - out.Reset() - err = writeReadText(&out, "linux", "-guide-skill", []byte("# Guide\n"), []string{"references/ok.md"}) - require.NoError(t, err) - assert.Contains(t, out.String(), " databricks skills read-file -- -guide-skill references/ok.md\n") } func TestWriteReadTextPrintsPathWithoutCommandWhenItCannotBeQuoted(t *testing.T) { diff --git a/libs/aitools/installer/source.go b/libs/aitools/installer/source.go index e899645f206..8feb0bb4f04 100644 --- a/libs/aitools/installer/source.go +++ b/libs/aitools/installer/source.go @@ -7,9 +7,7 @@ import ( "io" "net/http" "path" - "regexp" "strings" - "sync" "time" "github.com/databricks/cli/libs/clicompat" @@ -72,19 +70,6 @@ func (s *GitHubManifestSource) FetchManifest(ctx context.Context, ref string) (* return &manifest, nil } -// maxSkillNameLength is the Agent Skills limit on the length of a skill name. -const maxSkillNameLength = 64 - -// skillNamePattern is the Agent Skills name format -// (https://agentskills.io/specification#name-field): lowercase letters, digits -// and single hyphens. Every name is a directory under the skills dir, next to -// the installer's state file, so the format also keeps names from aliasing each -// other on case-insensitive filesystems or through Windows trailing dots and -// spaces. -var skillNamePattern = sync.OnceValue(func() *regexp.Regexp { - return regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*$`) -}) - // unportableSkill returns why a skill that stays inside its directory still // cannot be installed the same way on every OS, or "" if it can. Install skips // such a skill and update keeps the installed copy, the way both treat a skill @@ -95,8 +80,8 @@ var skillNamePattern = sync.OnceValue(func() *regexp.Regexp { // may differ only in case, and no path may be both a file and a folder: either // would merge or collide on a case-insensitive filesystem. func unportableSkill(name string, files []string) string { - if len(name) > maxSkillNameLength || !skillNamePattern().MatchString(name) { - return fmt.Sprintf("the name is not at most %d lowercase letters, digits and single hyphens", maxSkillNameLength) + if !skills.IsSkillName(name) { + return fmt.Sprintf("the name is not at most %d lowercase letters, digits and single hyphens", skills.MaxSkillNameLength) } if isWindowsDeviceName(name) { return "the name is a reserved Windows device name" diff --git a/libs/skills/fs.go b/libs/skills/fs.go index 5f76d8adf4a..ec9fcbeeb3d 100644 --- a/libs/skills/fs.go +++ b/libs/skills/fs.go @@ -10,6 +10,8 @@ import ( "path" "slices" "time" + + "github.com/databricks/cli/libs/log" ) const manifestFile = "manifest.json" @@ -46,6 +48,11 @@ func (s *fsSource) Catalog(ctx context.Context) (*Catalog, error) { catalog.Rules = string(data) } for _, name := range slices.Sorted(maps.Keys(m.Skills)) { + if !IsSkillName(name) { + // The installer rejects this name, so the catalog leaves the skill out. + log.Debugf(ctx, "skills catalog: skipping skill %q: the name is not a valid skill name", name) + continue + } meta := m.Skills[name] catalog.Skills = append(catalog.Skills, Skill{ Name: name, diff --git a/libs/skills/fs_test.go b/libs/skills/fs_test.go index df6d3be51b8..f35e078400d 100644 --- a/libs/skills/fs_test.go +++ b/libs/skills/fs_test.go @@ -52,6 +52,27 @@ func TestCatalogFromFixture(t *testing.T) { }, catalog.Skills[1]) } +func TestCatalogLeavesOutSkillNamesTheInstallerRejects(t *testing.T) { + src := mapSource(`{"version": "1.0.0", "skills": { + "alpha": {"version": "1.0.0", "files": ["SKILL.md"]}, + "-foo": {"version": "1.0.0", "files": ["SKILL.md"]}, + "a b": {"version": "1.0.0", "files": ["SKILL.md"]}}}`) + catalog, err := src.Catalog(t.Context()) + require.NoError(t, err) + + require.Len(t, catalog.Skills, 1) + assert.Equal(t, "alpha", catalog.Skills[0].Name) +} + +func TestIsSkillName(t *testing.T) { + for _, name := range []string{"a", "alpha", "databricks-core", "skill2", strings.Repeat("a", MaxSkillNameLength)} { + assert.True(t, IsSkillName(name), name) + } + for _, name := range []string{"", "-foo", "a b", "Alpha", "a--b", "a_b", "a/b", "a.b", strings.Repeat("a", MaxSkillNameLength+1)} { + assert.False(t, IsSkillName(name), name) + } +} + func TestReadFiles(t *testing.T) { src := fixtureSource() diff --git a/libs/skills/hints.go b/libs/skills/hints.go index d8afd77bd18..ddeabb95118 100644 --- a/libs/skills/hints.go +++ b/libs/skills/hints.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "slices" - "strings" "github.com/databricks/cli/libs/log" ) @@ -50,11 +49,6 @@ func WriteGroupHint(ctx context.Context, w io.Writer, group string) { fmt.Fprintln(w) fmt.Fprintln(w, "Coding agents: read the skills for this command group before you use it.") for _, name := range names { - // A leading "-" would make Cobra read the name as a flag, so "--" ends the flags first. - endOfFlags := "" - if strings.HasPrefix(name, "-") { - endOfFlags = "-- " - } - fmt.Fprintf(w, " databricks skills read %s%s\n", endOfFlags, name) + fmt.Fprintf(w, " databricks skills read %s\n", name) } } diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index ceec374e22f..245e4dd9a01 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -4,11 +4,9 @@ import ( "bytes" "os" "path/filepath" - "strings" "testing" "github.com/databricks/cli/libs/env" - "github.com/spf13/pflag" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -42,9 +40,11 @@ func TestWriteGroupHint(t *testing.T) { } } -func TestWriteGroupHintRunsLeadingHyphenSkillAsPrinted(t *testing.T) { +func TestWriteGroupHintLeavesOutSkillNameTheInstallerRejects(t *testing.T) { dir := t.TempDir() - const manifest = `{"version": "1.0.0", "skills": {"-foo": {"version": "1.0.0", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]}}}` + const manifest = `{"version": "1.0.0", "skills": { + "-foo": {"version": "1.0.0", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]}, + "alpha": {"version": "1.0.0", "description": "A valid skill.", "files": ["SKILL.md"], "commands": ["jobs"]}}}` require.NoError(t, os.WriteFile(filepath.Join(dir, "manifest.json"), []byte(manifest), 0o644)) ctx := env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", dir) @@ -53,13 +53,6 @@ func TestWriteGroupHintRunsLeadingHyphenSkillAsPrinted(t *testing.T) { var buf bytes.Buffer WriteGroupHint(ctx, &buf, "jobs") - assert.Equal(t, "\nCoding agents: read the skills for this command group before you use it.\n"+ - " databricks skills read -- -foo\n", buf.String()) - - // The printed command, minus "databricks skills read", must parse to the name, not to flags. - printed := strings.Fields(buf.String()) - args := printed[len(printed)-2:] - fs := pflag.NewFlagSet("read", pflag.ContinueOnError) - require.NoError(t, fs.Parse(args)) - assert.Equal(t, []string{"-foo"}, fs.Args()) + require.Equal(t, "\nCoding agents: read the skills for this command group before you use it.\n"+ + " databricks skills read alpha\n", buf.String()) } diff --git a/libs/skills/manifest.go b/libs/skills/manifest.go index f31af350d1d..65c9ea1f5f5 100644 --- a/libs/skills/manifest.go +++ b/libs/skills/manifest.go @@ -4,10 +4,31 @@ import ( "errors" "fmt" "maps" + "regexp" "slices" "strings" + "sync" ) +// MaxSkillNameLength is the Agent Skills limit on the length of a skill name. +const MaxSkillNameLength = 64 + +// skillNamePattern is the Agent Skills name format +// (https://agentskills.io/specification#name-field): lowercase letters, digits +// and single hyphens. Every name is a directory under the skills dir, next to +// the installer's state file, so the format also keeps names from aliasing each +// other on case-insensitive filesystems or through Windows trailing dots and +// spaces. +var skillNamePattern = sync.OnceValue(func() *regexp.Regexp { + return regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*$`) +}) + +// IsSkillName reports whether name is a skill name the installer accepts: at +// most MaxSkillNameLength lowercase letters, digits and single hyphens. +func IsSkillName(name string) bool { + return len(name) <= MaxSkillNameLength && skillNamePattern().MatchString(name) +} + const ( // StableRepoDir is the release directory of stable skills (the repo_dir default). StableRepoDir = "skills" diff --git a/libs/skills/skills.go b/libs/skills/skills.go index 5fb3f1fb191..b01b6f2d105 100644 --- a/libs/skills/skills.go +++ b/libs/skills/skills.go @@ -55,8 +55,8 @@ type FileSizer interface { // Catalog is the set of skills a source serves. type Catalog struct { - // Skills are sorted by name. Install also skips non-portable names and - // paths, which the catalog does not check yet. + // Skills are sorted by name. A name IsSkillName rejects is left out. Install + // also skips non-portable paths, which the catalog does not check yet. Skills []Skill // Version is the release version. From 6403bb5d9ea2bcf9fdf3563c18efa89a20d5da96 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 15:42:03 +0000 Subject: [PATCH 06/14] acceptance: leave the leading-hyphen skill out of the shared release The catalog now skips a skill whose name the installer rejects, so a "-foo" skill in the shared release no longer lists. Remove it from the shared fixture and restore the skill count in resolve_test.go. The hints-hyphen test gets its own manifest with "-foo" and a valid skill, and shows that the help footer lists only the valid one. Co-authored-by: Isaac --- acceptance/cmd/skills/release/manifest.json | 3 +-- acceptance/cmd/skills/release/skills/-foo/SKILL.md | 6 ------ acceptance/help/skills/hints-hyphen/manifest.json | 7 +++++++ acceptance/help/skills/hints-hyphen/output.txt | 10 +--------- acceptance/help/skills/hints-hyphen/script | 8 +------- acceptance/help/skills/hints-hyphen/test.toml | 1 + libs/skills/resolve_test.go | 9 ++++----- 7 files changed, 15 insertions(+), 29 deletions(-) delete mode 100644 acceptance/cmd/skills/release/skills/-foo/SKILL.md create mode 100644 acceptance/help/skills/hints-hyphen/manifest.json diff --git a/acceptance/cmd/skills/release/manifest.json b/acceptance/cmd/skills/release/manifest.json index e9351246685..0281c53fe69 100644 --- a/acceptance/cmd/skills/release/manifest.json +++ b/acceptance/cmd/skills/release/manifest.json @@ -3,7 +3,6 @@ "skills": { "demo-skill": {"version": "0.0.1", "description": "A skill for tests.", "files": ["SKILL.md"], "commands": ["fs", "air"]}, "guide-skill": {"version": "0.0.1", "description": "A skill with a supporting file.", "files": ["SKILL.md", "references/guide.md"]}, - "future-skill": {"version": "0.0.1", "description": "A skill that needs a newer CLI.", "files": ["SKILL.md"], "min_cli_version": "99.0.0"}, - "-foo": {"version": "0.0.1", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]} + "future-skill": {"version": "0.0.1", "description": "A skill that needs a newer CLI.", "files": ["SKILL.md"], "min_cli_version": "99.0.0"} } } diff --git a/acceptance/cmd/skills/release/skills/-foo/SKILL.md b/acceptance/cmd/skills/release/skills/-foo/SKILL.md deleted file mode 100644 index 9c36f6fb254..00000000000 --- a/acceptance/cmd/skills/release/skills/-foo/SKILL.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -name: -foo -description: A skill whose name starts with a hyphen. ---- - -# Foo skill diff --git a/acceptance/help/skills/hints-hyphen/manifest.json b/acceptance/help/skills/hints-hyphen/manifest.json new file mode 100644 index 00000000000..b78a0c91c01 --- /dev/null +++ b/acceptance/help/skills/hints-hyphen/manifest.json @@ -0,0 +1,7 @@ +{ + "version": "0.0.1", + "skills": { + "-foo": {"version": "0.0.1", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]}, + "alpha": {"version": "0.0.1", "description": "A valid skill.", "files": ["SKILL.md"], "commands": ["jobs"]} + } +} diff --git a/acceptance/help/skills/hints-hyphen/output.txt b/acceptance/help/skills/hints-hyphen/output.txt index eca55a5f1da..8f2dbfde390 100644 --- a/acceptance/help/skills/hints-hyphen/output.txt +++ b/acceptance/help/skills/hints-hyphen/output.txt @@ -3,12 +3,4 @@ Use "databricks jobs [command] --help" for more information about a command. Coding agents: read the skills for this command group before you use it. - databricks skills read -- -foo - ->>> eval databricks skills read -- -foo ---- -name: -foo -description: A skill whose name starts with a hyphen. ---- - -# Foo skill + databricks skills read alpha diff --git a/acceptance/help/skills/hints-hyphen/script b/acceptance/help/skills/hints-hyphen/script index 9d00f1b5e53..c2cc2b06826 100644 --- a/acceptance/help/skills/hints-hyphen/script +++ b/acceptance/help/skills/hints-hyphen/script @@ -1,8 +1,2 @@ -export DATABRICKS_SKILLS_DIR="$TESTDIR/../../../cmd/skills/release" - -# The footer for a group ends the flags before a skill whose name starts with "-", so the printed command runs. +# The footer lists only the skills whose names the installer accepts. "-foo" is left out, so no printed command starts with a flag. trace $CLI jobs --help | tail -n 4 - -databricks() { "$CLI" "$@"; } -line=$($CLI jobs --help | grep -- ' databricks skills read') -trace eval "$line" diff --git a/acceptance/help/skills/hints-hyphen/test.toml b/acceptance/help/skills/hints-hyphen/test.toml index dbb7d352196..6fa2621e444 100644 --- a/acceptance/help/skills/hints-hyphen/test.toml +++ b/acceptance/help/skills/hints-hyphen/test.toml @@ -1,3 +1,4 @@ Cloud = false +Env.DATABRICKS_SKILLS_DIR = "." Env.DATABRICKS_SKILLS_HINTS = "1" Env.DATABRICKS_SKILLS_PREVIEW = "1" diff --git a/libs/skills/resolve_test.go b/libs/skills/resolve_test.go index 11635aed1c2..f836cf389a0 100644 --- a/libs/skills/resolve_test.go +++ b/libs/skills/resolve_test.go @@ -38,9 +38,8 @@ func TestLocalCatalogFromAcceptanceFixture(t *testing.T) { dir := filepath.Join("..", "..", "acceptance", "cmd", "skills", "release") catalog, err := LocalCatalog(env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", dir)) require.NoError(t, err) - require.Len(t, catalog.Skills, 4) - assert.Equal(t, "-foo", catalog.Skills[0].Name) - assert.Equal(t, "demo-skill", catalog.Skills[1].Name) - assert.Equal(t, "future-skill", catalog.Skills[2].Name) - assert.Equal(t, "guide-skill", catalog.Skills[3].Name) + require.Len(t, catalog.Skills, 3) + assert.Equal(t, "demo-skill", catalog.Skills[0].Name) + assert.Equal(t, "future-skill", catalog.Skills[1].Name) + assert.Equal(t, "guide-skill", catalog.Skills[2].Name) } From 91029cf534ab844b67d1dd1711e4e1bb1c6140c0 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 16:36:48 +0000 Subject: [PATCH 07/14] libs/skills: check the skill name in ReadFile and reword the name docs Skill reads looked the skill up in the raw manifest, so `skills read-file -- -foo SKILL.md` served a skill that list and read hide. The lookup now also requires IsSkillName, and returns ErrUnknownSkill as it does for an unlisted skill. `skills read-file` prints the skill name as it is, since the catalog only lists valid names. The file name keeps its quoting. IsSkillName is the Agent Skills name format. The installer also rejects Windows device names, which the comments now say. The hints acceptance test is renamed to match what it checks, and a test shows the footer stays off with DATABRICKS_SKILLS_PREVIEW unset. Co-authored-by: Isaac --- .../manifest.json | 0 .../out.test.toml | 0 .../output.txt | 0 .../script | 0 .../test.toml | 0 cmd/skills/read.go | 12 ++++++------ libs/skills/fs.go | 5 +++-- libs/skills/fs_test.go | 14 ++++++++++++++ libs/skills/hints_test.go | 18 ++++++++++++++++++ libs/skills/manifest.go | 6 ++++-- libs/skills/skills.go | 5 +++-- 11 files changed, 48 insertions(+), 12 deletions(-) rename acceptance/help/skills/{hints-hyphen => hints-invalid-name}/manifest.json (100%) rename acceptance/help/skills/{hints-hyphen => hints-invalid-name}/out.test.toml (100%) rename acceptance/help/skills/{hints-hyphen => hints-invalid-name}/output.txt (100%) rename acceptance/help/skills/{hints-hyphen => hints-invalid-name}/script (100%) rename acceptance/help/skills/{hints-hyphen => hints-invalid-name}/test.toml (100%) diff --git a/acceptance/help/skills/hints-hyphen/manifest.json b/acceptance/help/skills/hints-invalid-name/manifest.json similarity index 100% rename from acceptance/help/skills/hints-hyphen/manifest.json rename to acceptance/help/skills/hints-invalid-name/manifest.json diff --git a/acceptance/help/skills/hints-hyphen/out.test.toml b/acceptance/help/skills/hints-invalid-name/out.test.toml similarity index 100% rename from acceptance/help/skills/hints-hyphen/out.test.toml rename to acceptance/help/skills/hints-invalid-name/out.test.toml diff --git a/acceptance/help/skills/hints-hyphen/output.txt b/acceptance/help/skills/hints-invalid-name/output.txt similarity index 100% rename from acceptance/help/skills/hints-hyphen/output.txt rename to acceptance/help/skills/hints-invalid-name/output.txt diff --git a/acceptance/help/skills/hints-hyphen/script b/acceptance/help/skills/hints-invalid-name/script similarity index 100% rename from acceptance/help/skills/hints-hyphen/script rename to acceptance/help/skills/hints-invalid-name/script diff --git a/acceptance/help/skills/hints-hyphen/test.toml b/acceptance/help/skills/hints-invalid-name/test.toml similarity index 100% rename from acceptance/help/skills/hints-hyphen/test.toml rename to acceptance/help/skills/hints-invalid-name/test.toml diff --git a/cmd/skills/read.go b/cmd/skills/read.go index a7866b085ee..caddc4625e8 100644 --- a/cmd/skills/read.go +++ b/cmd/skills/read.go @@ -104,9 +104,10 @@ func otherFiles(files []string) []string { } // writeReadText writes SKILL.md, with a trailing newline added if it is missing, -// then the other files with the command that reads each one. The commands are -// quoted for the shell of goos. A name or file that no quoting keeps literal -// is listed without its command. Nothing else goes to stdout. +// then the other files with the command that reads each one. The name is a +// skill name the catalog lists, so it is printed as it is. The file is quoted +// for the shell of goos. A file that no quoting keeps literal is listed without +// its command. Nothing else goes to stdout. func writeReadText(w io.Writer, goos, name string, content []byte, files []string) error { var b strings.Builder b.Write(content) @@ -115,10 +116,9 @@ func writeReadText(w io.Writer, goos, name string, content []byte, files []strin } if len(files) > 0 { b.WriteString("\nOther files in this skill, each read with its command:\n") - quotedName, nameOK := shellquote.Arg(goos, name) for _, f := range files { quotedFile, fileOK := shellquote.Arg(goos, f) - if !nameOK || !fileOK { + if !fileOK { fmt.Fprintf(&b, " %s\n", f) continue } @@ -127,7 +127,7 @@ func writeReadText(w io.Writer, goos, name string, content []byte, files []strin if strings.HasPrefix(f, "-") { endOfFlags = "-- " } - fmt.Fprintf(&b, " databricks skills read-file %s%s %s\n", endOfFlags, quotedName, quotedFile) + fmt.Fprintf(&b, " databricks skills read-file %s%s %s\n", endOfFlags, name, quotedFile) } } _, err := io.WriteString(w, b.String()) diff --git a/libs/skills/fs.go b/libs/skills/fs.go index ec9fcbeeb3d..2339b7aef74 100644 --- a/libs/skills/fs.go +++ b/libs/skills/fs.go @@ -100,14 +100,15 @@ func (s *fsSource) FileSize(ctx context.Context, skill, file string) (int64, err } // filePath returns the path of a skill file in the release. The manifest must -// list the file for the skill. +// list the file for the skill, and a name IsSkillName rejects is unknown, as it +// is to Catalog. func (s *fsSource) filePath(ctx context.Context, skill, file string) (string, error) { m, err := s.manifest(ctx) if err != nil { return "", err } meta, ok := m.Skills[skill] - if !ok { + if !ok || !IsSkillName(skill) { return "", fmt.Errorf("%w: %q", ErrUnknownSkill, skill) } if !slices.Contains(meta.Files, file) { diff --git a/libs/skills/fs_test.go b/libs/skills/fs_test.go index f35e078400d..31caab3162d 100644 --- a/libs/skills/fs_test.go +++ b/libs/skills/fs_test.go @@ -1,6 +1,7 @@ package skills import ( + "io/fs" "os" "strings" "testing" @@ -64,6 +65,19 @@ func TestCatalogLeavesOutSkillNamesTheInstallerRejects(t *testing.T) { assert.Equal(t, "alpha", catalog.Skills[0].Name) } +func TestReadFileRejectsSkillNameTheCatalogLeavesOut(t *testing.T) { + src := mapSource(`{"version": "1.0.0", "skills": { + "alpha": {"version": "1.0.0", "files": ["SKILL.md"]}, + "-foo": {"version": "1.0.0", "files": ["SKILL.md"]}}}`) + + _, err := src.ReadFile(t.Context(), "-foo", "SKILL.md") + assert.ErrorIs(t, err, ErrUnknownSkill) + + _, err = src.ReadFile(t.Context(), "alpha", "SKILL.md") + require.Error(t, err) + assert.ErrorIs(t, err, fs.ErrNotExist) +} + func TestIsSkillName(t *testing.T) { for _, name := range []string{"a", "alpha", "databricks-core", "skill2", strings.Repeat("a", MaxSkillNameLength)} { assert.True(t, IsSkillName(name), name) diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index 245e4dd9a01..630a1ead3c6 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -56,3 +56,21 @@ func TestWriteGroupHintLeavesOutSkillNameTheInstallerRejects(t *testing.T) { require.Equal(t, "\nCoding agents: read the skills for this command group before you use it.\n"+ " databricks skills read alpha\n", buf.String()) } + +// With DATABRICKS_SKILLS_PREVIEW unset the feature is off, so the footer stays +// off even with hints on and the same manifest. +func TestWriteGroupHintIsOffWithoutPreview(t *testing.T) { + dir := t.TempDir() + const manifest = `{"version": "1.0.0", "skills": { + "-foo": {"version": "1.0.0", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]}, + "alpha": {"version": "1.0.0", "description": "A valid skill.", "files": ["SKILL.md"], "commands": ["jobs"]}}}` + require.NoError(t, os.WriteFile(filepath.Join(dir, "manifest.json"), []byte(manifest), 0o644)) + + ctx := env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", dir) + ctx = env.Set(ctx, "DATABRICKS_SKILLS_PREVIEW", "") + ctx = env.Set(ctx, "DATABRICKS_SKILLS_HINTS", "1") + + var buf bytes.Buffer + WriteGroupHint(ctx, &buf, "jobs") + require.Empty(t, buf.String()) +} diff --git a/libs/skills/manifest.go b/libs/skills/manifest.go index 65c9ea1f5f5..4e0c17b1dd0 100644 --- a/libs/skills/manifest.go +++ b/libs/skills/manifest.go @@ -23,8 +23,10 @@ var skillNamePattern = sync.OnceValue(func() *regexp.Regexp { return regexp.MustCompile(`^[a-z0-9]+(-[a-z0-9]+)*$`) }) -// IsSkillName reports whether name is a skill name the installer accepts: at -// most MaxSkillNameLength lowercase letters, digits and single hyphens. +// IsSkillName reports whether name has the Agent Skills name format: at most +// MaxSkillNameLength lowercase letters, digits and single hyphens. The installer +// also rejects Windows device names such as "con"; that check is separate, in +// the installer, and IsSkillName does not make it. func IsSkillName(name string) bool { return len(name) <= MaxSkillNameLength && skillNamePattern().MatchString(name) } diff --git a/libs/skills/skills.go b/libs/skills/skills.go index b01b6f2d105..e0a5f0ca362 100644 --- a/libs/skills/skills.go +++ b/libs/skills/skills.go @@ -55,8 +55,9 @@ type FileSizer interface { // Catalog is the set of skills a source serves. type Catalog struct { - // Skills are sorted by name. A name IsSkillName rejects is left out. Install - // also skips non-portable paths, which the catalog does not check yet. + // Skills are sorted by name. A name IsSkillName rejects, the Agent Skills + // name format, is left out. Install also skips reserved Windows device names + // and non-portable paths; the catalog checks neither yet. Skills []Skill // Version is the release version. From c18cfe76b5e517354e34763d1534863ee772a739 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 17:14:44 +0000 Subject: [PATCH 08/14] skills: end flags in the help hint for a leading-hyphen skill name The help footer printed the skill name unquoted, so a skill named with a leading hyphen was read by Cobra as a flag. Print "--" first in that case. Also add a quoted leading-hyphen file case and send the acceptance check's output to LOG.read. Co-authored-by: Isaac --- acceptance/cmd/skills/read/script | 2 +- cmd/skills/read_test.go | 10 ++++++++++ libs/skills/hints.go | 12 +++++++++++- libs/skills/hints_test.go | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/acceptance/cmd/skills/read/script b/acceptance/cmd/skills/read/script index a4374f2f307..432f42823af 100644 --- a/acceptance/cmd/skills/read/script +++ b/acceptance/cmd/skills/read/script @@ -7,7 +7,7 @@ trace $CLI skills read guide-skill title "A file whose name starts with a hyphen: the printed command ends the flags and runs as printed" databricks() { "$CLI" "$@"; } line="databricks skills read-file -- guide-skill -notes.md" -$CLI skills read guide-skill | contains.py " $line" > /dev/null +$CLI skills read guide-skill | contains.py " $line" > LOG.read trace eval "$line" title "read-file accepts -- before a leading-hyphen file name" diff --git a/cmd/skills/read_test.go b/cmd/skills/read_test.go index 23f8ea9da0e..5af1faa587b 100644 --- a/cmd/skills/read_test.go +++ b/cmd/skills/read_test.go @@ -37,6 +37,16 @@ func TestWriteReadTextEndsFlagsBeforeLeadingHyphenFile(t *testing.T) { err = writeReadText(&out, "linux", "-guide-skill", []byte("# Guide\n"), []string{"references/ok.md"}) require.NoError(t, err) assert.Contains(t, out.String(), " databricks skills read-file -- -guide-skill references/ok.md\n") + + out.Reset() + err = writeReadText(&out, "linux", "guide-skill", []byte("# Guide\n"), []string{"-my notes.md"}) + require.NoError(t, err) + assert.Contains(t, out.String(), " databricks skills read-file -- guide-skill '-my notes.md'\n") + + out.Reset() + err = writeReadText(&out, "windows", "guide-skill", []byte("# Guide\n"), []string{"-my notes.md"}) + require.NoError(t, err) + assert.Contains(t, out.String(), " databricks skills read-file -- guide-skill \"-my notes.md\"\n") } func TestWriteReadTextPrintsPathWithoutCommandWhenItCannotBeQuoted(t *testing.T) { diff --git a/libs/skills/hints.go b/libs/skills/hints.go index ddeabb95118..340dcb3182b 100644 --- a/libs/skills/hints.go +++ b/libs/skills/hints.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "slices" + "strings" "github.com/databricks/cli/libs/log" ) @@ -49,6 +50,15 @@ func WriteGroupHint(ctx context.Context, w io.Writer, group string) { fmt.Fprintln(w) fmt.Fprintln(w, "Coding agents: read the skills for this command group before you use it.") for _, name := range names { - fmt.Fprintf(w, " databricks skills read %s\n", name) + fmt.Fprintf(w, " %s\n", hintReadCommand(name)) } } + +// hintReadCommand returns the command that reads the skill named name. A name +// that starts with "-" gets "--" first, so Cobra does not read it as a flag. +func hintReadCommand(name string) string { + if strings.HasPrefix(name, "-") { + return "databricks skills read -- " + name + } + return "databricks skills read " + name +} diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index 69ddd731676..df69b68ed9e 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -36,3 +36,8 @@ func TestWriteGroupHint(t *testing.T) { }) } } + +func TestHintReadCommand(t *testing.T) { + assert.Equal(t, "databricks skills read alpha", hintReadCommand("alpha")) + assert.Equal(t, "databricks skills read -- -alpha", hintReadCommand("-alpha")) +} From e580301ddcf919c478b781f07bf83398efdf1a97 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 17:15:16 +0000 Subject: [PATCH 09/14] libs/skills: fold the preview-off check into the hint table The footer test for DATABRICKS_SKILLS_PREVIEW unset is now a case in TestWriteGroupHint, with the preview value as a table field. The hints acceptance test also runs the read commands on the names the catalog leaves out, so their unknown-skill errors are in the golden, and the manifest adds a name with a space. The Catalog comment names the Agent Skills format directly. Co-authored-by: Isaac --- .../skills/hints-invalid-name/manifest.json | 1 + .../help/skills/hints-invalid-name/output.txt | 9 ++++ .../help/skills/hints-invalid-name/script | 7 +++- libs/skills/hints_test.go | 42 +++++++------------ libs/skills/skills.go | 6 +-- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/acceptance/help/skills/hints-invalid-name/manifest.json b/acceptance/help/skills/hints-invalid-name/manifest.json index b78a0c91c01..dd07032606a 100644 --- a/acceptance/help/skills/hints-invalid-name/manifest.json +++ b/acceptance/help/skills/hints-invalid-name/manifest.json @@ -2,6 +2,7 @@ "version": "0.0.1", "skills": { "-foo": {"version": "0.0.1", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]}, + "a b": {"version": "0.0.1", "description": "A skill whose name has a space.", "files": ["SKILL.md"], "commands": ["jobs"]}, "alpha": {"version": "0.0.1", "description": "A valid skill.", "files": ["SKILL.md"], "commands": ["jobs"]} } } diff --git a/acceptance/help/skills/hints-invalid-name/output.txt b/acceptance/help/skills/hints-invalid-name/output.txt index 8f2dbfde390..61c44fd5a6e 100644 --- a/acceptance/help/skills/hints-invalid-name/output.txt +++ b/acceptance/help/skills/hints-invalid-name/output.txt @@ -4,3 +4,12 @@ Use "databricks jobs [command] --help" for more information about a command. Coding agents: read the skills for this command group before you use it. databricks skills read alpha + +>>> [CLI] skills read -- -foo +Error: unknown skill "-foo": run "databricks skills list" to see the available skills + +>>> [CLI] skills read-file -- -foo SKILL.md +Error: unknown skill: "-foo" + +>>> [CLI] skills read a b +Error: unknown skill "a b": run "databricks skills list" to see the available skills diff --git a/acceptance/help/skills/hints-invalid-name/script b/acceptance/help/skills/hints-invalid-name/script index c2cc2b06826..3207d3cb497 100644 --- a/acceptance/help/skills/hints-invalid-name/script +++ b/acceptance/help/skills/hints-invalid-name/script @@ -1,2 +1,7 @@ -# The footer lists only the skills whose names the installer accepts. "-foo" is left out, so no printed command starts with a flag. +# The footer lists only the skills whose names the installer accepts. "-foo" and "a b" are left out, so no printed command starts with a flag or needs quotes. trace $CLI jobs --help | tail -n 4 + +# The catalog leaves those names out, so reading them fails as an unknown skill. +musterr trace $CLI skills read -- -foo +musterr trace $CLI skills read-file -- -foo SKILL.md +musterr trace $CLI skills read "a b" diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index 630a1ead3c6..731ff194de9 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -16,21 +16,25 @@ func TestWriteGroupHint(t *testing.T) { const footer = "\nCoding agents: read the skills for this command group before you use it.\n" + " databricks skills read alpha\n" cases := []struct { - name string - hints string - dir string - group string - want string + name string + preview string + hints string + dir string + group string + want string }{ - {name: "hints off", hints: "0", dir: dir, group: "jobs"}, - {name: "no source", hints: "1", dir: "", group: "jobs"}, - {name: "unmapped group", hints: "1", dir: dir, group: "fs"}, - {name: "mapped group", hints: "1", dir: dir, group: "jobs", want: footer}, + {name: "hints off", preview: "1", hints: "0", dir: dir, group: "jobs"}, + {name: "no source", preview: "1", hints: "1", dir: "", group: "jobs"}, + {name: "unmapped group", preview: "1", hints: "1", dir: dir, group: "fs"}, + {name: "mapped group", preview: "1", hints: "1", dir: dir, group: "jobs", want: footer}, + // Without DATABRICKS_SKILLS_PREVIEW the feature is off, so the footer + // stays off even with hints on and a source that maps the group. + {name: "preview off", preview: "", hints: "1", dir: dir, group: "jobs"}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { ctx := env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", c.dir) - ctx = env.Set(ctx, "DATABRICKS_SKILLS_PREVIEW", "1") + ctx = env.Set(ctx, "DATABRICKS_SKILLS_PREVIEW", c.preview) ctx = env.Set(ctx, "DATABRICKS_SKILLS_HINTS", c.hints) var buf bytes.Buffer @@ -56,21 +60,3 @@ func TestWriteGroupHintLeavesOutSkillNameTheInstallerRejects(t *testing.T) { require.Equal(t, "\nCoding agents: read the skills for this command group before you use it.\n"+ " databricks skills read alpha\n", buf.String()) } - -// With DATABRICKS_SKILLS_PREVIEW unset the feature is off, so the footer stays -// off even with hints on and the same manifest. -func TestWriteGroupHintIsOffWithoutPreview(t *testing.T) { - dir := t.TempDir() - const manifest = `{"version": "1.0.0", "skills": { - "-foo": {"version": "1.0.0", "description": "A skill whose name starts with a hyphen.", "files": ["SKILL.md"], "commands": ["jobs"]}, - "alpha": {"version": "1.0.0", "description": "A valid skill.", "files": ["SKILL.md"], "commands": ["jobs"]}}}` - require.NoError(t, os.WriteFile(filepath.Join(dir, "manifest.json"), []byte(manifest), 0o644)) - - ctx := env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", dir) - ctx = env.Set(ctx, "DATABRICKS_SKILLS_PREVIEW", "") - ctx = env.Set(ctx, "DATABRICKS_SKILLS_HINTS", "1") - - var buf bytes.Buffer - WriteGroupHint(ctx, &buf, "jobs") - require.Empty(t, buf.String()) -} diff --git a/libs/skills/skills.go b/libs/skills/skills.go index e0a5f0ca362..97cf5834835 100644 --- a/libs/skills/skills.go +++ b/libs/skills/skills.go @@ -55,9 +55,9 @@ type FileSizer interface { // Catalog is the set of skills a source serves. type Catalog struct { - // Skills are sorted by name. A name IsSkillName rejects, the Agent Skills - // name format, is left out. Install also skips reserved Windows device names - // and non-portable paths; the catalog checks neither yet. + // Skills are sorted by name. A skill whose name is not in the Agent Skills + // name format (see IsSkillName) is left out. Install also skips reserved + // Windows device names and non-portable paths; the catalog checks neither yet. Skills []Skill // Version is the release version. From e73a6a04f850ded4aa9a53111322898d1158dc50 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Fri, 27 Nov 2026 17:16:51 +0000 Subject: [PATCH 10/14] skills: leave the help footer to the stacked change The help footer's leading-hyphen handling moves to the stacked pull request that owns the footer, so this branch no longer changes libs/skills. Co-authored-by: Isaac --- libs/skills/hints.go | 12 +----------- libs/skills/hints_test.go | 5 ----- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/libs/skills/hints.go b/libs/skills/hints.go index 340dcb3182b..ddeabb95118 100644 --- a/libs/skills/hints.go +++ b/libs/skills/hints.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "slices" - "strings" "github.com/databricks/cli/libs/log" ) @@ -50,15 +49,6 @@ func WriteGroupHint(ctx context.Context, w io.Writer, group string) { fmt.Fprintln(w) fmt.Fprintln(w, "Coding agents: read the skills for this command group before you use it.") for _, name := range names { - fmt.Fprintf(w, " %s\n", hintReadCommand(name)) + fmt.Fprintf(w, " databricks skills read %s\n", name) } } - -// hintReadCommand returns the command that reads the skill named name. A name -// that starts with "-" gets "--" first, so Cobra does not read it as a flag. -func hintReadCommand(name string) string { - if strings.HasPrefix(name, "-") { - return "databricks skills read -- " + name - } - return "databricks skills read " + name -} diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index df69b68ed9e..69ddd731676 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -36,8 +36,3 @@ func TestWriteGroupHint(t *testing.T) { }) } } - -func TestHintReadCommand(t *testing.T) { - assert.Equal(t, "databricks skills read alpha", hintReadCommand("alpha")) - assert.Equal(t, "databricks skills read -- -alpha", hintReadCommand("-alpha")) -} From 233bb76cd88873270b190e07b8e76db985bb5796 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Mon, 30 Nov 2026 10:11:10 +0000 Subject: [PATCH 11/14] skills: drop the redundant test.toml lines and the preview-off case Co-authored-by: Isaac --- .../help/skills/hints-invalid-name/test.toml | 2 -- libs/skills/hints_test.go | 24 ++++++++----------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/acceptance/help/skills/hints-invalid-name/test.toml b/acceptance/help/skills/hints-invalid-name/test.toml index 6fa2621e444..1e3837584d3 100644 --- a/acceptance/help/skills/hints-invalid-name/test.toml +++ b/acceptance/help/skills/hints-invalid-name/test.toml @@ -1,4 +1,2 @@ -Cloud = false Env.DATABRICKS_SKILLS_DIR = "." Env.DATABRICKS_SKILLS_HINTS = "1" -Env.DATABRICKS_SKILLS_PREVIEW = "1" diff --git a/libs/skills/hints_test.go b/libs/skills/hints_test.go index 731ff194de9..245e4dd9a01 100644 --- a/libs/skills/hints_test.go +++ b/libs/skills/hints_test.go @@ -16,25 +16,21 @@ func TestWriteGroupHint(t *testing.T) { const footer = "\nCoding agents: read the skills for this command group before you use it.\n" + " databricks skills read alpha\n" cases := []struct { - name string - preview string - hints string - dir string - group string - want string + name string + hints string + dir string + group string + want string }{ - {name: "hints off", preview: "1", hints: "0", dir: dir, group: "jobs"}, - {name: "no source", preview: "1", hints: "1", dir: "", group: "jobs"}, - {name: "unmapped group", preview: "1", hints: "1", dir: dir, group: "fs"}, - {name: "mapped group", preview: "1", hints: "1", dir: dir, group: "jobs", want: footer}, - // Without DATABRICKS_SKILLS_PREVIEW the feature is off, so the footer - // stays off even with hints on and a source that maps the group. - {name: "preview off", preview: "", hints: "1", dir: dir, group: "jobs"}, + {name: "hints off", hints: "0", dir: dir, group: "jobs"}, + {name: "no source", hints: "1", dir: "", group: "jobs"}, + {name: "unmapped group", hints: "1", dir: dir, group: "fs"}, + {name: "mapped group", hints: "1", dir: dir, group: "jobs", want: footer}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { ctx := env.Set(t.Context(), "DATABRICKS_SKILLS_DIR", c.dir) - ctx = env.Set(ctx, "DATABRICKS_SKILLS_PREVIEW", c.preview) + ctx = env.Set(ctx, "DATABRICKS_SKILLS_PREVIEW", "1") ctx = env.Set(ctx, "DATABRICKS_SKILLS_HINTS", c.hints) var buf bytes.Buffer From d52e263f14f509b19aba9cb06e10ed4f20cb7478 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Mon, 30 Nov 2026 11:07:17 +0000 Subject: [PATCH 12/14] skills: drop invalid skill names once when the manifest is read Co-authored-by: Isaac --- libs/skills/fs.go | 20 +++++++++++--------- libs/skills/skills.go | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libs/skills/fs.go b/libs/skills/fs.go index 9b7de6c0a83..b2cc972317a 100644 --- a/libs/skills/fs.go +++ b/libs/skills/fs.go @@ -50,11 +50,6 @@ func (s *fsSource) Catalog(ctx context.Context) (*Catalog, error) { catalog.Rules = string(data) } for _, name := range slices.Sorted(maps.Keys(m.Skills)) { - if !IsSkillName(name) { - // The installer rejects this name, so the catalog leaves the skill out. - log.Debugf(ctx, "skills catalog: skipping skill %q: the name is not a valid skill name", name) - continue - } meta := m.Skills[name] catalog.Skills = append(catalog.Skills, Skill{ Name: name, @@ -102,15 +97,14 @@ func (s *fsSource) FileSize(ctx context.Context, skill, file string) (int64, err } // filePath returns the path of a skill file in the release. The manifest must -// list the file for the skill, and a name IsSkillName rejects is unknown, as it -// is to Catalog. +// list the file for the skill. func (s *fsSource) filePath(ctx context.Context, skill, file string) (string, error) { m, err := s.manifest(ctx) if err != nil { return "", err } meta, ok := m.Skills[skill] - if !ok || !IsSkillName(skill) { + if !ok { return "", fmt.Errorf("%w: %q", ErrUnknownSkill, skill) } if !slices.Contains(meta.Files, file) { @@ -120,7 +114,9 @@ func (s *fsSource) filePath(ctx context.Context, skill, file string) (string, er } // manifest reads and checks the release manifest. Every path it names, the -// skill files, repo_dir and catalog_rules, must stay inside the release. +// skill files, repo_dir and catalog_rules, must stay inside the release. It +// drops the skills whose name the installer would reject, so every reader sees +// the same skills. func (s *fsSource) manifest(ctx context.Context) (*Manifest, error) { data, err := s.read(ctx, manifestFile) if errors.Is(err, ErrManifestTooLarge) || errors.Is(err, errReleaseNotFound) { @@ -151,5 +147,11 @@ func (s *fsSource) manifest(ctx context.Context) (*Manifest, error) { if m.CatalogRules == "." || escapesDir(m.CatalogRules) { return nil, fmt.Errorf("%w: catalog_rules %q", ErrUnsafeManifestPath, m.CatalogRules) } + for _, name := range slices.Sorted(maps.Keys(m.Skills)) { + if !IsSkillName(name) { + log.Debugf(ctx, "skills catalog: skipping skill %q: the name is not a valid skill name", name) + delete(m.Skills, name) + } + } return &m, nil } diff --git a/libs/skills/skills.go b/libs/skills/skills.go index 97cf5834835..20d77bcaa00 100644 --- a/libs/skills/skills.go +++ b/libs/skills/skills.go @@ -56,7 +56,8 @@ type FileSizer interface { // Catalog is the set of skills a source serves. type Catalog struct { // Skills are sorted by name. A skill whose name is not in the Agent Skills - // name format (see IsSkillName) is left out. Install also skips reserved + // name format (see IsSkillName) is left out, so every name here is safe to + // print in a command. A Source must meet this. Install also skips reserved // Windows device names and non-portable paths; the catalog checks neither yet. Skills []Skill From ef75ee5ec39b7a7f38e807d8c137961ce2d320d7 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Tue, 1 Dec 2026 09:04:52 +0000 Subject: [PATCH 13/14] skills: explain why an invalid skill name is unknown skills read, read-file and list-files named a skill the catalog leaves out as merely unknown and pointed to skills list, which never shows it. Say the name is outside the Agent Skills format instead. Co-authored-by: Isaac --- acceptance/help/skills/hints-invalid-name/output.txt | 6 +++--- cmd/skills/list_files.go | 3 +++ cmd/skills/read.go | 3 +++ libs/skills/fs.go | 3 +++ libs/skills/fs_test.go | 6 ++++++ libs/skills/skills.go | 8 ++++++++ 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/acceptance/help/skills/hints-invalid-name/output.txt b/acceptance/help/skills/hints-invalid-name/output.txt index 61c44fd5a6e..5dd9ae5d79c 100644 --- a/acceptance/help/skills/hints-invalid-name/output.txt +++ b/acceptance/help/skills/hints-invalid-name/output.txt @@ -6,10 +6,10 @@ Coding agents: read the skills for this command group before you use it. databricks skills read alpha >>> [CLI] skills read -- -foo -Error: unknown skill "-foo": run "databricks skills list" to see the available skills +Error: unknown skill "-foo": a skill name is at most 64 lowercase letters, digits and single hyphens, so the catalog leaves this name out >>> [CLI] skills read-file -- -foo SKILL.md -Error: unknown skill: "-foo" +Error: unknown skill "-foo": a skill name is at most 64 lowercase letters, digits and single hyphens, so the catalog leaves this name out >>> [CLI] skills read a b -Error: unknown skill "a b": run "databricks skills list" to see the available skills +Error: unknown skill "a b": a skill name is at most 64 lowercase letters, digits and single hyphens, so the catalog leaves this name out diff --git a/cmd/skills/list_files.go b/cmd/skills/list_files.go index 287cc2a42ea..86531de01aa 100644 --- a/cmd/skills/list_files.go +++ b/cmd/skills/list_files.go @@ -73,6 +73,9 @@ func runListFiles(cmd *cobra.Command, args []string) error { func findSkill(catalog *libskills.Catalog, name string) (libskills.Skill, error) { i := slices.IndexFunc(catalog.Skills, func(s libskills.Skill) bool { return s.Name == name }) if i < 0 { + if !libskills.IsSkillName(name) { + return libskills.Skill{}, libskills.InvalidSkillNameError(name) + } return libskills.Skill{}, fmt.Errorf("%w: %q", libskills.ErrUnknownSkill, name) } return catalog.Skills[i], nil diff --git a/cmd/skills/read.go b/cmd/skills/read.go index d0fc8cb1f19..c1c0933d477 100644 --- a/cmd/skills/read.go +++ b/cmd/skills/read.go @@ -60,6 +60,9 @@ func runRead(cmd *cobra.Command, src libskills.Source, name string) error { i := slices.IndexFunc(catalog.Skills, func(s libskills.Skill) bool { return s.Name == name }) if i < 0 { + if !libskills.IsSkillName(name) { + return libskills.InvalidSkillNameError(name) + } return fmt.Errorf("%w %q: run \"databricks skills list\" to see the available skills", libskills.ErrUnknownSkill, name) } skill := catalog.Skills[i] diff --git a/libs/skills/fs.go b/libs/skills/fs.go index 20402ac88ce..ee0a3e60b20 100644 --- a/libs/skills/fs.go +++ b/libs/skills/fs.go @@ -105,6 +105,9 @@ func (s *fsSource) filePath(ctx context.Context, skill, file string) (string, er } meta, ok := m.Skills[skill] if !ok { + if !IsSkillName(skill) { + return "", InvalidSkillNameError(skill) + } return "", fmt.Errorf("%w: %q", ErrUnknownSkill, skill) } if !slices.Contains(meta.Files, file) { diff --git a/libs/skills/fs_test.go b/libs/skills/fs_test.go index 49ac600814a..518e7e10d07 100644 --- a/libs/skills/fs_test.go +++ b/libs/skills/fs_test.go @@ -228,3 +228,9 @@ func TestLabelIsKeptAsGiven(t *testing.T) { require.NoError(t, err) assert.Equal(t, `my\skills`, catalog.Label) } + +func TestInvalidSkillNameErrorIsUnknownSkillAndExplainsTheFormat(t *testing.T) { + err := InvalidSkillNameError("-foo") + assert.ErrorIs(t, err, ErrUnknownSkill) + assert.Contains(t, err.Error(), "lowercase letters, digits and single hyphens") +} diff --git a/libs/skills/skills.go b/libs/skills/skills.go index b6babf89083..6cfffac72e7 100644 --- a/libs/skills/skills.go +++ b/libs/skills/skills.go @@ -11,6 +11,7 @@ package skills import ( "context" "errors" + "fmt" "time" ) @@ -97,3 +98,10 @@ type Source interface { Catalog(ctx context.Context) (*Catalog, error) ReadFile(ctx context.Context, skill, path string) ([]byte, error) } + +// InvalidSkillNameError is the error for a requested skill name outside the +// Agent Skills name format. The catalog leaves such a name out, so "skills list" +// never shows it and the plain unknown-skill error would send the user there. +func InvalidSkillNameError(name string) error { + return fmt.Errorf("%w %q: a skill name is at most %d lowercase letters, digits and single hyphens, so the catalog leaves this name out", ErrUnknownSkill, name, MaxSkillNameLength) +} From 58cd940d9c307b5393d6d1a7d98b70f96917d330 Mon Sep 17 00:00:00 2001 From: "simon.faltum" Date: Tue, 1 Dec 2026 15:40:30 +0000 Subject: [PATCH 14/14] skills: tidy the catalog name filter's comment, test home and list golden Co-authored-by: Isaac --- .../help/skills/hints-invalid-name/output.txt | 4 ++++ .../help/skills/hints-invalid-name/script | 3 +++ libs/skills/fs.go | 4 ++-- libs/skills/fs_test.go | 9 --------- libs/skills/manifest_test.go | 17 +++++++++++++++++ 5 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 libs/skills/manifest_test.go diff --git a/acceptance/help/skills/hints-invalid-name/output.txt b/acceptance/help/skills/hints-invalid-name/output.txt index 5dd9ae5d79c..5e3a2bb8a54 100644 --- a/acceptance/help/skills/hints-invalid-name/output.txt +++ b/acceptance/help/skills/hints-invalid-name/output.txt @@ -5,6 +5,10 @@ Use "databricks jobs [command] --help" for more information about a command. Coding agents: read the skills for this command group before you use it. databricks skills read alpha +>>> [CLI] skills list +alpha: A valid skill. +To read a skill, run: databricks skills read + >>> [CLI] skills read -- -foo Error: unknown skill "-foo": a skill name is at most 64 lowercase letters, digits and single hyphens, so the catalog leaves this name out diff --git a/acceptance/help/skills/hints-invalid-name/script b/acceptance/help/skills/hints-invalid-name/script index 3207d3cb497..78b4a99274f 100644 --- a/acceptance/help/skills/hints-invalid-name/script +++ b/acceptance/help/skills/hints-invalid-name/script @@ -1,6 +1,9 @@ # The footer lists only the skills whose names the installer accepts. "-foo" and "a b" are left out, so no printed command starts with a flag or needs quotes. trace $CLI jobs --help | tail -n 4 +# They are also left out of the list. +trace $CLI skills list + # The catalog leaves those names out, so reading them fails as an unknown skill. musterr trace $CLI skills read -- -foo musterr trace $CLI skills read-file -- -foo SKILL.md diff --git a/libs/skills/fs.go b/libs/skills/fs.go index ee0a3e60b20..a6f2a14c8ac 100644 --- a/libs/skills/fs.go +++ b/libs/skills/fs.go @@ -118,8 +118,8 @@ func (s *fsSource) filePath(ctx context.Context, skill, file string) (string, er // manifest reads and checks the release manifest. Every path it names, the // skill files, repo_dir and catalog_rules, must stay inside the release. It -// drops the skills whose name the installer would reject, so every reader sees -// the same skills. +// drops the skills whose name is not in the Agent Skills name format (see +// IsSkillName), so every reader sees the same skills. func (s *fsSource) manifest(ctx context.Context) (*Manifest, error) { data, err := s.read(ctx, manifestFile) if errors.Is(err, ErrManifestTooLarge) || errors.Is(err, errReleaseNotFound) { diff --git a/libs/skills/fs_test.go b/libs/skills/fs_test.go index 518e7e10d07..c6263ab625d 100644 --- a/libs/skills/fs_test.go +++ b/libs/skills/fs_test.go @@ -78,15 +78,6 @@ func TestReadFileRejectsSkillNameTheCatalogLeavesOut(t *testing.T) { assert.ErrorIs(t, err, fs.ErrNotExist) } -func TestIsSkillName(t *testing.T) { - for _, name := range []string{"a", "alpha", "databricks-core", "skill2", strings.Repeat("a", MaxSkillNameLength)} { - assert.True(t, IsSkillName(name), name) - } - for _, name := range []string{"", "-foo", "a b", "Alpha", "a--b", "a_b", "a/b", "a.b", strings.Repeat("a", MaxSkillNameLength+1)} { - assert.False(t, IsSkillName(name), name) - } -} - func TestReadFiles(t *testing.T) { src := fixtureSource() diff --git a/libs/skills/manifest_test.go b/libs/skills/manifest_test.go new file mode 100644 index 00000000000..a71b3b0705e --- /dev/null +++ b/libs/skills/manifest_test.go @@ -0,0 +1,17 @@ +package skills + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIsSkillName(t *testing.T) { + for _, name := range []string{"a", "alpha", "databricks-core", "skill2", strings.Repeat("a", MaxSkillNameLength)} { + assert.True(t, IsSkillName(name), name) + } + for _, name := range []string{"", "-foo", "a b", "Alpha", "a--b", "a_b", "a/b", "a.b", strings.Repeat("a", MaxSkillNameLength+1)} { + assert.False(t, IsSkillName(name), name) + } +}