Repository navigation
Add a hidden --skills-invoked flag for experimental skill tracking #7783
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,16 +11,23 @@ import ( | |
| "github.com/databricks/cli/libs/log" | ||
| "github.com/databricks/cli/libs/telemetry" | ||
| "github.com/databricks/databricks-sdk-go/useragent" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // Experimental skill-usage tracking: the databricks-core agent skill | ||
| // (https://github.com/databricks/databricks-agent-skills/tree/main/skills/databricks-core) | ||
| // tells agents to prefix CLI calls with this env var, set to the comma-separated | ||
| // bare names of the skills they loaded. It may change or be removed without | ||
| // notice. It is an env var rather than a flag so removing it doesn't change the | ||
| // CLI's interface, and because older CLIs ignore unknown env vars but reject | ||
| // unknown flags. | ||
| const skillsInvokedEnvVar = "DATABRICKS_SKILLS_INVOKED" | ||
| // tells agents to pass the comma-separated bare names of the skills they loaded. | ||
| // It may change or be removed without notice. | ||
| // | ||
| // skillsInvokedFlag is what agents use: a command that still starts with | ||
| // "databricks" keeps matching agent permission allowlists such as Claude Code's | ||
| // Bash(databricks:*), which an env var prefix does not. It is hidden from help | ||
| // and completion so it isn't part of the advertised interface. The env var is | ||
| // kept for callers that set it in the environment. | ||
| const ( | ||
| skillsInvokedFlag = "skills-invoked" | ||
| skillsInvokedEnvVar = "DATABRICKS_SKILLS_INVOKED" | ||
| ) | ||
|
|
||
| // skillUserAgentKey is repeated once per skill: "skill/databricks-core skill/databricks-jobs". | ||
| const skillUserAgentKey = "skill" | ||
|
|
@@ -55,10 +62,10 @@ func parseSkills(ctx context.Context, raw string) []string { | |
| switch { | ||
| case name == "": | ||
| case len(name) > maxSkillLength || !skillNamePattern().MatchString(name): | ||
| log.Debugf(ctx, "dropping invalid %s entry %q", skillsInvokedEnvVar, entry) | ||
| log.Debugf(ctx, "dropping invalid skill entry %q", entry) | ||
| case slices.Contains(skills, name): | ||
| case size+pairSize > maxSkillsUserAgentLength: | ||
| log.Debugf(ctx, "dropping %s entry %q: skills exceed %d user agent bytes", skillsInvokedEnvVar, name, maxSkillsUserAgentLength) | ||
| log.Debugf(ctx, "dropping skill entry %q: skills exceed %d user agent bytes", name, maxSkillsUserAgentLength) | ||
| default: | ||
| skills = append(skills, name) | ||
| size += pairSize | ||
|
|
@@ -67,14 +74,24 @@ func parseSkills(ctx context.Context, raw string) []string { | |
| return skills | ||
| } | ||
|
|
||
| // withSkillsInUserAgent adds one skill/<name> pair per skill in | ||
| // skillsInvokedEnvVar (experimental tracking), unless the user opted out of | ||
| // telemetry. | ||
| func withSkillsInUserAgent(ctx context.Context) context.Context { | ||
| // initSkillsInvokedFlag registers the hidden skillsInvokedFlag on cmd. | ||
| func initSkillsInvokedFlag(cmd *cobra.Command) { | ||
| cmd.PersistentFlags().String(skillsInvokedFlag, "", "comma-separated agent skills that invoked this command") | ||
| cmd.PersistentFlags().MarkHidden(skillsInvokedFlag) | ||
| } | ||
|
|
||
| // withSkillsInUserAgent adds one skill/<name> pair per skill from the | ||
| // skillsInvokedFlag flag, or skillsInvokedEnvVar when the flag isn't set | ||
| // (experimental tracking), unless the user opted out of telemetry. | ||
| func withSkillsInUserAgent(ctx context.Context, cmd *cobra.Command) context.Context { | ||
| if telemetry.Disabled(ctx) { | ||
| return ctx | ||
| } | ||
| for _, skill := range parseSkills(ctx, env.Get(ctx, skillsInvokedEnvVar)) { | ||
| raw := env.Get(ctx, skillsInvokedEnvVar) | ||
| if f := cmd.Flag(skillsInvokedFlag); f.Changed { | ||
| raw = f.Value.String() | ||
| } | ||
| for _, skill := range parseSkills(ctx, raw) { | ||
|
Member
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] Both debug messages in
Contributor
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. Fixed in e4d58d0: both messages now say "skill entry" without naming the source. |
||
| // Each skill adds its own pair to the same context; this is accumulation, | ||
| // not the accidental nesting fatcontext flags. | ||
| ctx = useragent.InContext(ctx, skillUserAgentKey, skill) //nolint:fatcontext | ||
|
|
||
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.
[nit] Please add a brief doc comment for
initSkillsInvokedFlag, as required by.agents/rules/comments.md(starting with the function name and ending with a period).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.
Added in e4d58d0.