Repository navigation
libs/skills: leave out skills whose names the installer rejects #8132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4243c2a
2d36604
2a5b94f
7f56db9
e1931fe
ca906e3
6893f66
6403bb5
f9d6226
91029cf
c18cfe7
e580301
e73a6a0
68ee73a
ef83edd
c84a3c4
40353c0
c625005
4276299
233bb76
d52e263
2f77918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "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"]} | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Cloud = false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| >>> [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 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # 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" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Env.DATABRICKS_SKILLS_DIR = "." | ||
| Env.DATABRICKS_SKILLS_HINTS = "1" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,19 +116,18 @@ 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 | ||
| } | ||
| // 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) | ||
| fmt.Fprintf(&b, " databricks skills read-file %s%s %s\n", endOfFlags, name, quotedFile) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in d52e263 as the contract option: the Catalog.Skills comment now says every name there is safe to print in a command and that a Source must meet this. The manifest-level filter means fsSource, which every Source wraps, meets it. Kept the print path unchanged. |
||
| } | ||
| } | ||
| _, err := io.WriteString(w, b.String()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ran ./task aitools-full at d52e263: lint, tests, acceptance and deadcode all pass. |
||
| 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" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,10 @@ import ( | |
| "bytes" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/cli/internal/testutil" | ||
| "github.com/databricks/cli/libs/env" | ||
| "github.com/spf13/pflag" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
@@ -43,9 +41,11 @@ func TestWriteGroupHint(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestWriteGroupHintRunsLeadingHyphenSkillAsPrinted(t *testing.T) { | ||
| func TestWriteGroupHintLeavesOutSkillNameTheInstallerRejects(t *testing.T) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] This test uses the same
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept. The ticket names this test: its acceptance criteria ask for the footer line in the k2hint test to use require.Equal. The acceptance test runs the CLI, while this one calls WriteGroupHint directly with a manifest that has the hyphen name, so it is not only a copy. No code change. |
||
| 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) | ||
|
|
@@ -54,15 +54,8 @@ 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"+ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] This is the test's last check of the result, not a precondition, so per
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept require.Equal. The ticket asks for require.Equal on this footer line, and that is the acceptance criterion this change is checked against. testing.md would use assert for a last check, so if the owner prefers that, it is a one-word change. No code change in this push. |
||
| " databricks skills read alpha\n", buf.String()) | ||
| } | ||
|
|
||
| // With the preview unset, a non-empty bundled copy must not produce a footer, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nice to have] The user-visible change is that
skills read -- -fooandskills read-file -- -foo SKILL.mdnow fail. The old script ran the printed command, but this one only records the footer, so no golden shows the new error. Could you addmusterr $CLI skills read -- -fooandmusterr $CLI skills read-file -- -foo SKILL.mdhere? The directory already has the manifest. An"a b"entry would also cover the space case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in e580301. The hints acceptance test now runs
skills read -- -foo,skills read-file -- -foo SKILL.mdandskills read "a b"under musterr, so their unknown skill errors are in the golden. The manifest adds an "a b" entry for the space case, and the footer is unchanged.