Documentation
¶
Overview ¶
Package commands builds a machine-readable catalog of dtctl's command tree. It walks the Cobra command hierarchy and produces a structured listing that AI agents and MCP servers can use for automated tool registration.
Index ¶
- Constants
- Variables
- func BuildVerbs(root *cobra.Command) map[string]*Verb
- func GenerateHowto(w io.Writer, l *Listing) error
- func RequiredScopesForResource(l *Listing, resource string) []string
- func RequiredScopesUnion(l *Listing) []string
- func ResolveAlias(name string) string
- func WriteTo(w io.Writer, l *Listing, format string) error
- func WriteValue(w io.Writer, v any, format string) error
- type Flag
- type Listing
- type Minimal
- type MinimalVerb
- type TimeFormats
- type Verb
Constants ¶
const SchemaVersion = 3
SchemaVersion is incremented on breaking changes to the listing structure. v2 adds per-verb `access`, per-(verb,resource) `required_scopes_by_resource`, per-verb `required_scopes` (DQL verbs), and a top-level `resource_scopes` canonical table. v3 adds the stability axis: per-verb and per-flag `stability` / `stability_since`, per-verb `deprecated`, and the top-level `min_stability` / `stability_exceptions` that describe the active floor.
Variables ¶
var MutatingVerbs = map[string]string{
"apply": "OperationCreate",
"create": "OperationCreate",
"edit": "OperationUpdate",
"delete": "OperationDelete",
"restore": "OperationUpdate",
"share": "OperationUpdate",
"claim": "OperationCreate",
"unshare": "OperationUpdate",
"update": "OperationUpdate",
"exec": "OperationCreate",
"enable": "OperationUpdate",
"disable": "OperationUpdate",
}
MutatingVerbs maps verb names to their safety operation type. Verbs not listed here are read-only (mutating: false).
This map must be kept in sync with actual safety-check call sites in cmd/ (both NewSafetyChecker and SetupWithSafety helpers). The TestMutatingVerbsMatchSafetyCheckerUsage test in cmd/commands_test.go cross-references this map against the real command tree to detect drift.
var ResourceAliases = map[string]string{
"wf": "workflows",
"sr": "scheduling-rules",
"dash": "dashboards",
"db": "dashboards",
"nb": "notebooks",
"bkt": "buckets",
"ec": "edgeconnect",
"fn": "functions",
"func": "functions",
"ad": "anomaly-detectors",
}
ResourceAliases are the standard resource aliases built into dtctl.
This map must be kept in sync with Cobra command Aliases fields in cmd/. The TestResourceAliasesMatchCobraAliases test in cmd/commands_test.go cross-references this map against the real command tree to detect drift.
Functions ¶
func BuildVerbs ¶
BuildVerbs walks the Cobra command tree rooted at root and returns the Listing's verbs alone. Unlike Build it does no I/O: Build also discovers plugins, which reads the directories on PATH.
func GenerateHowto ¶
GenerateHowto writes an LLM-optimized markdown reference guide to w. The content is derived from the given Listing to stay in sync with the actual command tree.
func RequiredScopesForResource ¶
RequiredScopesForResource returns the sorted union of scopes needed to run every verb in the listing against a single resource — the minimal token scope set for a pipeline that only touches that resource. The resource name may be an alias or plural; it is resolved against the canonical table.
func RequiredScopesUnion ¶
RequiredScopesUnion returns the sorted, de-duplicated union of every scope required by the verbs in the listing (per-resource scopes, DQL scopes, and subcommand scopes). Combined with FilterByResource it yields the minimal token scope set for a filtered command set, e.g. the scopes a CI pipeline that only runs `get`/`apply` on workflows needs.
func ResolveAlias ¶
ResolveAlias resolves a resource alias to its canonical name. Returns the original name if no alias exists.
Types ¶
type Flag ¶
type Flag struct {
Type string `json:"type" yaml:"type"`
Default string `json:"default,omitempty" yaml:"default,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
// Stability is the flag's own declared tier, omitted when it is the default
// `stable`. A flag may make a weaker promise than its command — that is how
// a new idea ships without inventing a new command — so the tier is carried
// per flag rather than inherited from the verb.
Stability string `json:"stability,omitempty" yaml:"stability,omitempty"`
// StabilitySince is the dtctl version at which the flag entered that tier.
StabilitySince string `json:"stability_since,omitempty" yaml:"stability_since,omitempty"`
}
Flag describes a CLI flag.
type Listing ¶
type Listing struct {
SchemaVersion int `json:"schema_version" yaml:"schema_version"`
Tool string `json:"tool" yaml:"tool"`
Version string `json:"version" yaml:"version"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
CommandModel string `json:"command_model" yaml:"command_model"`
// Profile is the active command profile shaping this catalog, if any. Omitted
// (empty) when the full command tree is exposed. Advertising it lets an agent
// see that it is looking at a reduced surface. See COMMAND_PROFILES_DESIGN.md.
Profile string `json:"profile,omitempty" yaml:"profile,omitempty"`
// SafetyLevel is the effective safety level of the active context, the
// orthogonal permission axis. Surfaced alongside Profile so both active
// constraints are visible at once.
SafetyLevel string `json:"safety_level,omitempty" yaml:"safety_level,omitempty"`
// MinStability is the active stability floor: the weakest contract a command
// or flag may offer and still be usable here. Surfaced so an agent can tell
// "this command does not exist" from "this command exists but is below the
// floor this deployment accepts". Omitted when nothing is filtered.
MinStability string `json:"min_stability,omitempty" yaml:"min_stability,omitempty"`
// StabilityExceptions are the individual commands and flags admitted below
// the floor, each rendered as it is written in config
// ("query --decode-snapshots").
// Without them a reader of min_stability could not explain why a
// below-floor command is present in the tree.
StabilityExceptions []string `json:"stability_exceptions,omitempty" yaml:"stability_exceptions,omitempty"`
GlobalFlags map[string]*Flag `json:"global_flags,omitempty" yaml:"global_flags,omitempty"`
Verbs map[string]*Verb `json:"verbs" yaml:"verbs"`
Aliases map[string]string `json:"resource_aliases,omitempty" yaml:"resource_aliases,omitempty"`
// ResourceScopes is the canonical (resource, access) → scopes table. Agents
// can derive any command's required scopes from this table plus each verb's
// access, which is what --brief relies on.
ResourceScopes map[string]auth.AccessScopes `json:"resource_scopes,omitempty" yaml:"resource_scopes,omitempty"`
TimeFormats *TimeFormats `json:"time_formats,omitempty" yaml:"time_formats,omitempty"`
Patterns []string `json:"patterns,omitempty" yaml:"patterns,omitempty"`
Antipatterns []string `json:"antipatterns,omitempty" yaml:"antipatterns,omitempty"`
// Plugins are the dtctl-* executables discovered on PATH. Each runs as
// `dtctl <name>` (exec convention); agents cannot see them any other way,
// so the catalog is their discovery surface. Flags and behavior are the
// plugin's own — dtctl only knows the name and binary.
Plugins []plugin.Plugin `json:"plugins,omitempty" yaml:"plugins,omitempty"`
}
Listing is the top-level output of `dtctl commands`.
func FilterByResource ¶
FilterByResource returns a new listing containing only verbs that operate on the given resource name. The name is matched against resources, subcommands, and aliases. Returns the filtered listing and true if any verbs matched. The original listing is not modified.
type Minimal ¶
type Minimal struct {
SchemaVersion int `json:"schema_version" yaml:"schema_version"`
Tool string `json:"tool" yaml:"tool"`
Version string `json:"version" yaml:"version"`
CommandModel string `json:"command_model" yaml:"command_model"`
// Profile and SafetyLevel advertise the active command profile and effective
// safety level (the two constraints shaping the surface), so agents see them
// even in the minimal overview. Omitted when unconstrained.
Profile string `json:"profile,omitempty" yaml:"profile,omitempty"`
SafetyLevel string `json:"safety_level,omitempty" yaml:"safety_level,omitempty"`
// MinStability and StabilityExceptions advertise the third constraint, the
// stability floor, for the same reason: an agent bootstrapping from the
// compact catalog must be able to tell "this command does not exist" from
// "this command is below the contract this deployment accepts".
MinStability string `json:"min_stability,omitempty" yaml:"min_stability,omitempty"`
StabilityExceptions []string `json:"stability_exceptions,omitempty" yaml:"stability_exceptions,omitempty"`
Verbs map[string]*MinimalVerb `json:"verbs" yaml:"verbs"`
Aliases map[string]string `json:"resource_aliases,omitempty" yaml:"resource_aliases,omitempty"`
// Examples are runnable starting points, listed only when their command is in the catalog.
Examples []string `json:"examples,omitempty" yaml:"examples,omitempty"`
}
Minimal is an ultra-compact overview of the command tree: just verbs, their resources, their stability, and nested subcommands. It carries no descriptions, flags, scopes, or mutating status. It is the default `dtctl commands` output — a quick map of what exists, since most verb-noun commands are self-explanatory. Use --brief or --full for progressively more detail.
func NewMinimal ¶
NewMinimal returns an ultra-compact overview of the command tree. The original listing is not modified.
type MinimalVerb ¶
type MinimalVerb struct {
Resources []string `json:"resources,omitempty" yaml:"resources,omitempty"`
// Stability is carried even here: this is the documented agent bootstrap
// path, and "may change in any release" is not something an agent should
// have to discover by having its automation break. Omitted for `stable`.
Stability string `json:"stability,omitempty" yaml:"stability,omitempty"`
// ResourceStability is carried here for the same reason as Stability: a
// resource-style command (`get breakpoints`) has no other slot in which to
// state its contract.
ResourceStability map[string]string `json:"resource_stability,omitempty" yaml:"resource_stability,omitempty"`
Subcommands map[string]*MinimalVerb `json:"subcommands,omitempty" yaml:"subcommands,omitempty"`
}
MinimalVerb is a verb reduced to its resources and nested subcommands.
type TimeFormats ¶
type TimeFormats struct {
Relative []string `json:"relative" yaml:"relative"`
Absolute string `json:"absolute" yaml:"absolute"`
Unix string `json:"unix" yaml:"unix"`
}
TimeFormats describes the time input formats dtctl accepts.
type Verb ¶
type Verb struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Mutating bool `json:"mutating" yaml:"mutating"`
SafetyOp string `json:"safety_operation,omitempty" yaml:"safety_operation,omitempty"`
Access string `json:"access,omitempty" yaml:"access,omitempty"`
Resources []string `json:"resources,omitempty" yaml:"resources,omitempty"`
// ResourceStability maps a resource to its tier, for the resources whose
// tier is not the default `stable`. Resources are rendered as a bare name
// list to keep the catalog compact, so there is nowhere on the resource
// itself to carry a contract — yet `get breakpoints` being experimental is
// exactly what an agent must not learn by having its automation break.
// Omitted entirely when every resource under the verb is stable, which is
// the overwhelming majority, so the common case costs nothing.
ResourceStability map[string]string `json:"resource_stability,omitempty" yaml:"resource_stability,omitempty"`
// Stability is the effective stability tier (the weakest along the path from
// root), omitted when it is the default `stable`. An agent that reads no
// `stability` key is looking at surface it may safely automate against.
Stability string `json:"stability,omitempty" yaml:"stability,omitempty"`
// StabilitySince is the dtctl version at which the command entered that
// tier, so a caller can judge how long it has sat there.
StabilitySince string `json:"stability_since,omitempty" yaml:"stability_since,omitempty"`
// Deprecated carries the scheduled-removal note for a still-stable command
// ("since 0.40.0, remove in 1.0.0, use `get workflows`").
Deprecated string `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
// RequiredScopes is the scope list for verbs whose scopes are not
// per-resource (e.g. `query`/`verify`/`wait`, which read Grail via DQL).
RequiredScopes []string `json:"required_scopes,omitempty" yaml:"required_scopes,omitempty"`
// RequiredScopesByResource maps each resource the verb operates on to the
// scopes required for this verb's access level. Materialized in full mode so
// agents need zero client-side computation; omitted in --brief.
RequiredScopesByResource map[string][]string `json:"required_scopes_by_resource,omitempty" yaml:"required_scopes_by_resource,omitempty"`
Flags map[string]*Flag `json:"flags,omitempty" yaml:"flags,omitempty"`
// ResourceFlags maps each resource to the names of its own flags. Names
// only, to keep the full catalog small: `dtctl <verb> <resource> --help`
// gives types and descriptions. Omitted in --brief.
ResourceFlags map[string][]string `json:"resource_flags,omitempty" yaml:"resource_flags,omitempty"`
RequiredArgs []string `json:"required_args,omitempty" yaml:"required_args,omitempty"`
Subcommands map[string]*Verb `json:"subcommands,omitempty" yaml:"subcommands,omitempty"`
}
Verb represents a top-level verb (get, describe, apply, ...).