commands

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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.

View Source
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

func BuildVerbs(root *cobra.Command) map[string]*Verb

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

func GenerateHowto(w io.Writer, l *Listing) error

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

func RequiredScopesForResource(l *Listing, resource string) []string

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

func RequiredScopesUnion(l *Listing) []string

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

func ResolveAlias(name string) string

ResolveAlias resolves a resource alias to its canonical name. Returns the original name if no alias exists.

func WriteTo

func WriteTo(w io.Writer, l *Listing, format string) error

WriteTo writes the listing to w in the given format ("json", "yaml"/"yml", or "toon"). Any other format value defaults to JSON.

func WriteValue

func WriteValue(w io.Writer, v any, format string) error

WriteValue serializes any value to w in the given format ("json", "yaml"/"yml", or "toon"). Any other format value defaults to JSON. It is used to emit the minimal/brief/full catalog variants, which are distinct types.

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 Build

func Build(root *cobra.Command) *Listing

Build walks the Cobra command tree rooted at root and returns a Listing.

func FilterByResource

func FilterByResource(l *Listing, name string) (*Listing, bool)

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.

func NewBrief

func NewBrief(l *Listing) *Listing

NewBrief returns a copy of the listing with verbose fields stripped for reduced token count. It preserves mutating status since agents always need it. 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

func NewMinimal(l *Listing) *Minimal

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, ...).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL