Repository navigation
libs/skills: leave out skills whose names the installer rejects - #8132
simonfaltum wants to merge 22 commits into
Conversation
`skills read` printed `databricks skills read-file <name> <path>` 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 <no-reply@databricks.com>
…p footer The help footer for a command group printed "databricks skills read <name>" 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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
Merge skills/k2dash-printed-read-file-commands-survive-file at 2a5b94f. Keep both release fixture changes: guide-skill gets -notes.md, and the hint fixture adds the -foo skill. Co-authored-by: Isaac <no-reply@databricks.com>
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 <no-reply@databricks.com>
…ls/kname-the-skills-catalog-skips-skill-names-the Co-authored-by: Isaac <no-reply@databricks.com>
Regression test report ✅Commit: Selected 3 changed tests (limit=20, 0 not selected) 3 tests: regression=1 unreleased=2 coverage=0 failing=0
TestAccept/cmd/skills/list: branch ✅ | main (d1d57e6) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/help/skills/hints: branch ✅ | main (d1d57e6) ✅ | latest (v1.28.0) ❌latest (v1.28.0): TestAccept/help/skills/hints-invalid-name: branch ✅ | main (d1d57e6) ❌ | latest (v1.28.0) ❌main (d1d57e6): latest (v1.28.0): |
✅ Integration test reportCommit: d52e263
Top 3 slowest tests (at least 2 minutes):
|
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 <no-reply@databricks.com>
There was a problem hiding this comment.
Automated review at 91029cf. Each finding was verified against the code.
No blocking issues found. 6 non-blocking comment(s) below.
This PR moves the installer's skill-name check into libs/skills as IsSkillName. The catalog and ReadFile now leave out skills with names the installer rejects, so the printed skills read commands no longer need -- or quoting for the name. The change itself is correct: fsSource is the only Source, and both Catalog and filePath enforce the check. The main gap is the user experience. When a manifest lists a bad name, the skill disappears with only a debug log line, and no acceptance test shows what skills read prints after that. There are also a few test-rule and wording nits.
| 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) |
There was a problem hiding this comment.
[nice to have] Say a DATABRICKS_SKILLS_DIR manifest lists -foo. databricks skills read -- -foo used to print the skill. Now it fails with unknown skill "-foo": run "databricks skills list", but the manifest plainly lists it, skills list is notImplemented, and the only reason given is a debug-level log line. AGENTS.md asks us not to silently ignore config we can't honor. Could this be a visible warning, or could the name check go into CheckManifestPaths (libs/skills/manifest.go) so the manifest fails with a clear error?
There was a problem hiding this comment.
Not changed. The ticket asks for the catalog to skip a name the installer rejects and to log the skipped name at debug level, and its acceptance criteria expect the catalog to return the valid skill. Failing the whole manifest on one bad name would hide every other skill. The user-visible effect is now in the golden of acceptance/help/skills/hints-invalid-name: skills read -- -foo, skills read-file -- -foo SKILL.md and skills read "a b" each fail with an unknown skill error that names the skill (e580301).
| @@ -0,0 +1,2 @@ | |||
| # 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 | |||
There was a problem hiding this comment.
[nice to have] The user-visible change is that skills read -- -foo and skills read-file -- -foo SKILL.md now fail. The old script ran the printed command, but this one only records the footer, so no golden shows the new error. Could you add musterr $CLI skills read -- -foo and musterr $CLI skills read-file -- -foo SKILL.md here? The directory already has the manifest. An "a b" entry would also cover the space case.
There was a problem hiding this comment.
Done in e580301. The hints acceptance test now runs skills read -- -foo, skills read-file -- -foo SKILL.md and skills 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.
| } | ||
|
|
||
| func TestWriteGroupHintRunsLeadingHyphenSkillAsPrinted(t *testing.T) { | ||
| func TestWriteGroupHintLeavesOutSkillNameTheInstallerRejects(t *testing.T) { |
There was a problem hiding this comment.
[nit] This test uses the same -foo/alpha manifest and asserts the same footer as acceptance/help/skills/hints-invalid-name. TestCatalogLeavesOutSkillNamesTheInstallerRejects already covers the filtering. testing.md says not to add a unit test that only duplicates an acceptance test, so can this one go?
There was a problem hiding this comment.
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.
| 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()) | ||
| require.Equal(t, "\nCoding agents: read the skills for this command group before you use it.\n"+ |
There was a problem hiding this comment.
[nit] This is the test's last check of the result, not a precondition, so per testing.md it should be assert.Equal. The same applies to require.Empty at line 75.
There was a problem hiding this comment.
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.
| assert.Equal(t, []string{"-foo"}, fs.Args()) | ||
| // 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) { |
There was a problem hiding this comment.
[nit] TestWriteGroupHintIsOffWithoutPreview tests that DATABRICKS_SKILLS_PREVIEW gates the footer. It passes with or without this change, and its -foo entry has no effect on the result. Could it go in a separate PR, or become a case in the TestWriteGroupHint table?
There was a problem hiding this comment.
Done in e580301. The standalone test is removed. Its check is now a preview off case in TestWriteGroupHint, with the preview value as a table field, so it fails if the guard is broken. The case also uses assert.Equal, which covers the require.Empty point on the same test.
| 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, the Agent Skills |
There was a problem hiding this comment.
[nit] In "A name IsSkillName rejects, the Agent Skills name format, is left out", it reads as if the rejected name is the Agent Skills name format. Maybe: "Skills are sorted by name, and a skill whose name is not in the Agent Skills name format (see IsSkillName) is left out."
There was a problem hiding this comment.
Done in e580301. The Catalog comment now reads: a skill whose name is not in the Agent Skills name format (see IsSkillName) is left out.
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
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 <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
…-before Brings in the squash-merged skills read change (#8121). Its acceptance manifest conflicted with this branch's hyphen fixture; the branch side is kept, which adds the -foo skill. Co-authored-by: Isaac <no-reply@databricks.com>
…-before Keep the hyphen-name fixture alongside the preview skill from main, and update the list golden for the new skill. Co-authored-by: Isaac <no-reply@databricks.com>
Take in the parent branch's merge with main. Leave the leading-hyphen skill out of the shared acceptance release again, since the catalog skips names the installer rejects, and update the resolve test count and the list golden to match. Co-authored-by: Isaac <no-reply@databricks.com>
…mes-the Take origin/main's hints test layout and keep this branch's skip for skill names the installer rejects: drop the leading-hyphen footer case and the -foo fixture skill, and keep the hints-invalid-name test. Co-authored-by: Isaac <no-reply@databricks.com>
…atabricks#8127) ## Changes The group help footer now prints `databricks skills read -- <name>` for a skill whose name starts with `-`. Before, the printed command read the name as a flag and failed. Ordinary names print exactly as before. - `WriteGroupHint` in `libs/skills/hints.go` adds `-- ` only when the name starts with `-`. - The footer stays behind `DATABRICKS_SKILLS_PREVIEW` and the hints switch, so output is unchanged while those are off. ## Why A skill name starting with `-` passes `CheckManifestPaths`, so the footer can list one. `skills read` had the same bug and was fixed the same way in `cmd/skills/read.go` by databricks#8121, which is merged. This branch merges `main` and carries only the footer change. ## Decisions to review - The check is inline in `WriteGroupHint` rather than a shared helper. The check in `cmd/skills/read.go` is inline too, and `libs/skills` cannot import `cmd/skills`, so sharing it would move code across packages in this pull request. - Names with spaces, `;`, `$(...)` or a newline are not quoted here. databricks#8132 makes the installer reject such names, so they never reach the footer. - `skills list` still prints the generic line `databricks skills read <name>`, which fails for `-foo`. Adding `--` there changes every list golden, not only the `-foo` line, so it is left for a follow-up. ## Tests - `TestWriteGroupHintRunsLeadingHyphenSkillAsPrinted` checks the footer line for a skill named `-foo`, then parses the printed arguments with pflag to show they resolve to the name. - `acceptance/help/skills/hints` prints the footer for `jobs`, checks the printed line with `contains.py`, and runs it with `eval`. - The `-foo` skill is added to the shared acceptance release fixture. That changes the count in `TestLocalCatalogFromAcceptanceFixture` and adds the skill to the `acceptance/cmd/skills/list` golden. That golden is the only existing one that changes. Every other golden is unchanged. - The existing `TestWriteGroupHint` cases are unchanged. Its hints-off case covers the guard. - `go test ./libs/skills/... ./cmd/skills/...`, `./task fmt-q lint-q`, `go test ./acceptance -run TestAccept/cmd/skills` and `-run TestAccept/help/skills` pass. This pull request and its description were written by Isaac. --------- Co-authored-by: Isaac <no-reply@databricks.com>
rugpanov
left a comment
There was a problem hiding this comment.
No blocking problem found. The change moves the installer's skill-name check into libs/skills as IsSkillName, and the catalog now leaves out skills that fail it. All read paths (skills read, read-file, list-files, the help footer) go through the same filter, and the installer keeps the same regex, length limit and messages.
I do not approve yet, because one design point is still open: the catalog hides an invalid name with only a debug log (see the inline question, and the open thread #8132 (comment)).
Risk: LOW. The skills command group is hidden and gated by DATABRICKS_SKILLS_PREVIEW, and Resolve serves only a local DATABRICKS_SKILLS_DIR today. The installer refactor keeps its behavior, and a revert is simple.
CI: 20 checks pass and 8 are skipped (test-sandbox, test-pipelines, test-exp-ssh matrices). task test-exp-aitools passes on linux and macos.
Already reported and still open (not repeated here): require.Equal as the main assertion (#8132 (comment)) and the duplicate unit test (#8132 (comment)).
| 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) |
There was a problem hiding this comment.
[Question] Is a debug-level skip the wanted behavior here? The installer reports the same name at the default log level: log.Warnf(ctx, "Skipping skill %q: %s", ...) for a full install, and a SkillError for a named install (libs/aitools/installer/installer.go:491-496). Here, skills list leaves the skill out, and skills read -- -foo says only unknown skill "-foo". A developer with a hand-written DATABRICKS_SKILLS_DIR manifest cannot see why the skill is missing. AGENTS.md also says: "Never silently ignore a flag or config field the current mode can't honor." If a visible message is wanted, use log.Warnf here, as the installer does. This adds the installer evidence to the open thread #8132 (comment).
There was a problem hiding this comment.
Not changed. I tried log.Warnf here. The catalog is built for the jobs --help footer too, so every help run printed a timestamped WARN line in the middle of the help text, and each skills read printed one line per bad entry before its error. That is a lot of noise for help output, which is why the ticket asks for debug level. The skill is still visible as missing: the acceptance golden hints-invalid-name shows the unknown skill error that names it. If you want a visible message, a better place is an error in CheckManifestPaths or a note in skills list, which I would do as a follow-up rather than here.
| catalog.Rules = string(data) | ||
| } | ||
| for _, name := range slices.Sorted(maps.Keys(m.Skills)) { | ||
| if !IsSkillName(name) { |
There was a problem hiding this comment.
[Question] Do you want the installer name format for skills read too? On main, a local manifest skill named Alpha, a_b or a.b works with skills read, and -foo works with skills read -- -foo. At this head, all four names are unknown skills. The first three names are safe in the shell, so the printed-command problem alone does not need this filter. If only the printed commands are the problem, a smaller fix is to keep -- and quote the name with shellquote.Arg in WriteGroupHint. The answer decides if this filter is in scope for this PR.
There was a problem hiding this comment.
Yes, the filter applies to skills read on purpose. The ticket for this change is that the catalog accepts only names the installer would accept, so a name that skills read shows to an agent can also be installed. Names like Alpha, a_b and a.b are not installable today, so a manifest listing them is already inconsistent with the installer. Quoting with shellquote.Arg would fix only the printed commands, not that mismatch. No code change; if you would rather take the smaller fix, say so and I will switch.
| @@ -0,0 +1,4 @@ | |||
| Cloud = false | |||
There was a problem hiding this comment.
[nit] Cloud = false and Env.DATABRICKS_SKILLS_PREVIEW = "1" (line 4) repeat inherited values. acceptance/test.toml already sets Cloud = false, and acceptance/help/skills/test.toml already sets the preview variable. The sibling hints/test.toml sets neither. Remove the two lines, as .agents/rules/testing.md says: "Put common test.toml options in a parent directory."
There was a problem hiding this comment.
Done in 233bb76. Removed Cloud = false and the preview variable from this test.toml; the parent directories set them.
| {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"}, |
There was a problem hiding this comment.
[nit] The preview off case tests the DATABRICKS_SKILLS_PREVIEW gate, not the skill-name check. main has no such test, so this is a new test that is not related to the change. AGENTS.md says: "Keep each PR focused on one change." Move this case to a separate PR.
There was a problem hiding this comment.
Done in 233bb76. Removed the preview off case and the preview table field, so TestWriteGroupHint is back to its original shape.
Co-authored-by: Isaac <no-reply@databricks.com>
rclarey
left a comment
There was a problem hiding this comment.
[nit] The Tests section still lists "TestWriteGroupHint: a preview off case…", but 233bb76 removed that case. It also says help/skills/hints-invalid-name was "renamed from hints-hyphen". hints-hyphen existed only in this branch's earlier commits, and against main this is a new directory. Could you update the description so it matches the final diff?
[nit] IsSkillName is defined in manifest.go, but TestIsSkillName is in fs_test.go. Moving it to a manifest_test.go would keep each test next to its code.
[nit] (non-blocking, raised by 2 sources) Windows device names. Is a follow-up planned to share the installer's device-name check with the catalog, for example by moving isWindowsDeviceName into libs/skills next to IsSkillName? A manifest skill named con with commands: ["jobs"] is still listed in skills list, shown in the jobs --help footer and readable with skills read con, but aitools install skips it. The description says this is deferred. I'm asking only to confirm that a follow-up is tracked, since the stated goal is to list what the installer can install.
| catalog.Rules = string(data) | ||
| } | ||
| for _, name := range slices.Sorted(maps.Keys(m.Skills)) { | ||
| if !IsSkillName(name) { |
There was a problem hiding this comment.
[nit] Catalog and filePath each repeat IsSkillName. If a future fsSource method reads m.Skills and forgets the check, it will serve a skill that Catalog hides. If manifest() dropped invalid names once (with the debug log), both places would see the same view and the extra || !IsSkillName(skill) could go. This is optional.
There was a problem hiding this comment.
Done in d52e263. manifest() now drops names IsSkillName rejects once, with the debug log, so Catalog and filePath see the same view. The extra check in filePath is gone.
| 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) |
There was a problem hiding this comment.
[nit] The skill name is now printed raw because "the catalog lists" only valid names. That is true today: every Source wraps fsSource, and runRead looks the name up in the catalog first. But the Source interface doesn't promise it, and the test for the -guide-skill case was deleted. One option is to keep a cheap check, libskills.IsSkillName(name), before printing the commands. Another is to state the guarantee on the Catalog.Skills field as a contract every Source must meet. Either way, a new source can't bring back flag-like names in printed commands without anyone noticing.
There was a problem hiding this comment.
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.
| 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) { |
There was a problem hiding this comment.
[nit] This PR touches libs/aitools, and .agents/rules/aitools-verification.md says to run ./task aitools-full before opening the PR. The Tests section lists only targeted go test runs and fmt-q lint-q. Could you run it, or note it in the description? CI test-exp-aitools (linux) passed and macOS was still pending.
There was a problem hiding this comment.
Ran ./task aitools-full at d52e263: lint, tests, acceptance and deadcode all pass.
Co-authored-by: Isaac <no-reply@databricks.com>
…mes-the Co-authored-by: Isaac <no-reply@databricks.com>
The skills catalog now leaves out any skill whose name the installer would reject: a name longer than 64 characters, or one that is not lowercase letters, digits and single hyphens. A hand-written
DATABRICKS_SKILLS_DIRmanifest could list such a name, and the printeddatabricks skills readcommands then broke. Each skipped name is logged at debug level.Changes
libs/aitools/installerintolibs/skillsasIsSkillNameandMaxSkillNameLength. The installer calls it from there, with unchanged messages and behavior.skills readand the help footer print a skill name without quotes or--, since the catalog never lists a name that starts with-. A file name that starts with-still gets--.ReadFilereturnsErrUnknownSkillfor a name the catalog leaves out, soskills read-filecannot serve a skipped skill.Why
The printed commands are not quoted, so a name with a space, a shell metacharacter or a leading hyphen cannot be run as printed. The installer already refuses these names. Skipping them in the catalog keeps the printed commands valid.
Skipping one skill, rather than failing the whole manifest, matches how the installer treats a skill it cannot install.
Decisions to review
IsSkillNameis the Agent Skills name format. The installer also rejects Windows device names such ascon. The installer still checks those, but the catalog does not check them yet, so such a name is listed.IsSkillNameis exported so the installer and the catalog use one check and cannot drift apart.Tests
TestCatalogLeavesOutSkillNamesTheInstallerRejects: a manifest withalpha,-fooanda blists onlyalpha.TestReadFileRejectsSkillNameTheCatalogLeavesOut:ReadFileon-fooreturnsErrUnknownSkill.TestIsSkillName: valid and invalid names, including the 64-character limit.TestWriteGroupHintLeavesOutSkillNameTheInstallerRejects: the footer lists only the valid skill, checked withrequire.Equal.TestWriteGroupHint: apreview offcase checks that the footer is empty withDATABRICKS_SKILLS_PREVIEWunset, even with hints on.TestWriteReadTextEndsFlagsBeforeLeadingHyphenFilestill checks a file name that starts with-.help/skills/hints-invalid-name(renamed fromhints-hyphen) shows a footer that lists only the valid skill, and thatskills readandskills read-filefail for-fooandskills readfails fora b.go testpasses for./libs/skills/...,./cmd/skills/...and./libs/aitools/installer/....TestAccept/cmd/skills,TestAccept/help/skillsandTestAccept/quickstart/skillspass, and./task fmt-q lint-qreports 0 issues.This pull request and its description were written by Isaac.