Documentation
¶
Overview ¶
Package meta turns the live binary into a machine-readable inventory of the CLI surface: providers, commands, flags, configuration keys and the MCP review tool's arguments.
It exists because documentation drifted from code (ADR-0039). Prose in README.md, the wiki and the site claimed provider counts, flag names and model ids that nobody re-derived when the code moved. Everything here is read out of the same structures the binary actually runs on, so a rendered docs block cannot describe a CLI that does not exist.
No import cycle ¶
Build takes the cobra root and the MCP tool schema as PARAMETERS. meta must never import internal/cli, because internal/cli is what calls Build (behind the hidden --gen-surface flag). The dependency runs cli -> meta, one way.
The registry trap ¶
provider.AllMetadata reports only what has been linked in, and the metadata registry is populated by the blank imports in cmd/commitbrief/main.go. A test in this package that reads it without those blank imports observes an empty registry and passes vacuously — which is why meta's own tests carry them and assert all ten shipped providers are present.
No build stamp ¶
Nothing here records a version, commit or build date. The generated artifact (internal/meta/surface.json) is committed to git; a build-stamped field would change on every build, churn in every diff and make the drift check fail on a clean tree.
Index ¶
Constants ¶
const SchemaVersion = 1
SchemaVersion is the version of the surface.json contract. Bump it only for a breaking shape change; adding an optional field is not one. The consumers are this repo's own doc renderers, so the value exists to make a stale artifact detectable, not to support old readers.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command struct {
// Path is cobra's full command path, e.g. "commitbrief cache prune".
// It is a command path, not a filesystem path: the separator is a space
// on every platform and nothing here touches the OS path rules.
Path string `json:"path"`
Short string `json:"short,omitempty"`
Hidden bool `json:"hidden,omitempty"`
}
Command is one command in the tree.
type ConfigKey ¶
type ConfigKey struct {
// Path is the dotted YAML path. A free-form map contributes a
// placeholder segment rather than a real key: providers.<name>.model.
Path string `json:"path"`
// Type is the YAML-facing shape: bool, int, float, string, []string,
// object, []object, map[string]object.
Type string `json:"type"`
// Default is the value rendered as text — either config.Default()'s
// actual field value, or an entry from effectiveDefaults when the real
// behavioral default is applied downstream instead of in config.Default()
// (review.architecture_file: config.Default() leaves it "" on purpose so
// arch.Discover's own auto-discovery stays a silent no-op, but the
// documented default is arch.DefaultFilename). Meaningful only when
// HasDefault is true.
Default string `json:"default,omitempty"`
// HasDefault distinguishes "the default is the empty string" (e.g.
// command.default, whose real default IS "") from "there is no default to
// report" (a struct/slice/map node, or anything below a free-form map key
// or inside a slice element). Default's omitempty alone cannot tell those
// apart — both render as an absent "default" key — which is exactly how
// review.architecture_file and command.default used to look identical in
// the generated inventory despite one of them having a real default and
// the other legitimately having none.
HasDefault bool `json:"has_default,omitempty"`
// FreeForm marks a key that lives under a user-chosen map key, so its
// Path contains a placeholder segment and its name is not fixed.
FreeForm bool `json:"free_form,omitempty"`
}
ConfigKey is one settable key in .commitbrief.yml.
func ConfigKeys ¶
func ConfigKeys() []ConfigKey
ConfigKeys reflects over config.Config and returns every key, sorted by dotted path.
The sort is what makes the committed artifact stable: the walk itself is in struct declaration order, but map fields are walked too and a future refactor that reorders fields should not reshuffle the whole file. Sorting by path also groups each section together, which is how the docs read.
The reflection rules mirror internal/config/schema.go's ValidateKeys (yamlFields / walkValue) on purpose: the same yaml-tag resolution, the same inline flattening, and above all the same stop-at-the-key treatment of map[string]T. Two different answers to "what is a legal config key" is exactly the drift this package exists to prevent. The difference is that schema.go walks a decoded YAML document and meta walks the TYPE, so this side needs no value to descend.
type EnvVar ¶
type EnvVar struct {
// Name is the exact variable name os.Getenv reads.
Name string `json:"name"`
// Effect is a one-line, hand-written description. env.go's source has
// no room for prose (they are bare `const` declarations), so this
// cannot be reflected the way ConfigKeys() reflects over the Config
// struct — it is maintained here, next to the name that anchors it to
// the constant that would break the build if it drifted.
Effect string `json:"effect"`
// ConfigKey is the dotted config.Config path this variable overrides,
// using the same <name> placeholder ConfigKeys() uses for a free-form
// provider entry (COMMITBRIEF_MODEL applies to whichever provider is
// currently active, not a fixed one).
ConfigKey string `json:"config_key,omitempty"`
}
EnvVar is one environment variable ApplyEnv (internal/config/env.go) reads.
This list exists because rendering "env-vars" straight from provider.Metadata's APIKeyEnv would silently under-report: that field only carries the SIX provider-credential variables, while ApplyEnv also reads OLLAMA_HOST, COMMITBRIEF_PROVIDER and COMMITBRIEF_MODEL. Every name below is either one of the config.*Env constants (so a rename in internal/config/env.go is caught by the Go compiler) or one of the two ApplyEnv still spells as a literal (COMMITBRIEF_PROVIDER, COMMITBRIEF_MODEL) — TestEnvVarsCoverApplyEnv parses ApplyEnv's own source and fails if it reads a variable that isn't listed here, so a future env var added to ApplyEnv cannot go silently undocumented the way DEEPSEEK_API_KEY / MISTRAL_API_KEY / COHERE_API_KEY did (README's old, hand-written table named only three of the six provider credentials).
It deliberately does NOT cover every environment variable CommitBrief reads anywhere (COMMITBRIEF_CONFIG in internal/cli/context.go, NO_COLOR / COMMITBRIEF_NO_COLOR in internal/ui/color.go, or LANG's explicit non-effect per ADR-0021) — those aren't config OVERRIDES ApplyEnv applies, so a "linked config key" column has nothing to point them at. README documents them as ordinary hand-written prose immediately after the generated env-vars region instead.
type Flag ¶
type Flag struct {
Command string `json:"command"`
Name string `json:"name"`
Shorthand string `json:"shorthand,omitempty"`
Type string `json:"type"`
Default string `json:"default,omitempty"`
NoOptDefVal string `json:"no_opt_def_val,omitempty"`
Usage string `json:"usage,omitempty"`
Scope Scope `json:"scope"`
Hidden bool `json:"hidden,omitempty"`
Deprecated string `json:"deprecated,omitempty"`
// MutexGroups lists the mutually-exclusive groups this flag belongs to,
// each one its members space-joined, in the order cobra recorded them
// (which is the order of the MarkFlagsMutuallyExclusive calls).
MutexGroups []string `json:"mutex_groups,omitempty"`
}
Flag is one flag, attributed to the command that declares it.
Flags are NOT deduplicated by name and must not be. doctor --quiet/-q, cache prune --provider, cache prune --model and guard --unstaged deliberately re-declare names that also exist on root's persistent set; pflag resolves local-over-persistent silently, so a name-keyed map would quietly under-report the real surface and hide the shadowing entirely. Command + Scope is what makes a row unique.
type MCPArg ¶
type MCPArg struct {
Name string `json:"name"`
Type string `json:"type"`
Items string `json:"items,omitempty"`
Enum []string `json:"enum,omitempty"`
Required bool `json:"required,omitempty"`
Description string `json:"description,omitempty"`
}
MCPArg is one argument of the MCP `review` tool, lifted out of the tool's JSON Schema.
It is flattened deliberately: the schema is the contract, but documentation wants a table, and a table wants one row per argument with the enum and the element type already resolved.
type Scope ¶
type Scope string
Scope says where a flag was declared, which is the only thing that distinguishes two flags with the same name.
const ( // ScopeGlobal is a flag declared on a command's PersistentFlags: it // applies to that command and everything below it. Root's persistent set // is what users call "the global flags". ScopeGlobal Scope = "global" // ScopeCommand is a flag declared on a command's own Flags: it applies to // that one command only. ScopeCommand Scope = "command" )
type Surface ¶
type Surface struct {
Schema int `json:"schema"`
Providers []provider.Metadata `json:"providers"`
Commands []Command `json:"commands"`
Flags []Flag `json:"flags"`
ConfigKeys []ConfigKey `json:"config_keys"`
MCPToolArgs []MCPArg `json:"mcp_tool_args"`
// EnvVars is appended last rather than slotted next to ConfigKeys: it
// was added in a later phase (ADR-0039 follow-up) purely to feed the
// "env-vars" generated README block, and appending avoids reshuffling
// every existing field's json output for consumers that index the
// artifact positionally.
EnvVars []EnvVar `json:"env_vars"`
}
Surface is the whole code-derived inventory of the CLI.
Field order here is the order the marshalled artifact reads in, chosen so a human skimming surface.json meets the sections in the order the documentation presents them. Every slice is non-nil after Build so the JSON carries `[]` rather than `null` for an empty section — a renderer should never have to distinguish the two.
func Build ¶
func Build(root *cobra.Command, mcpSchema json.RawMessage) Surface
Build walks a fully constructed cobra tree and returns the inventory.
root must be the root command; mcpSchema is the MCP review tool's input schema (internal/cli's reviewToolInputSchema). Both arrive as parameters so this package never imports internal/cli — see the package comment.
Build does not mutate the tree. In particular it does not call cobra's InitDefaultHelpFlag / InitDefaultHelpCmd to normalize what cobra injects; an inventory that rewrites the thing it is inventorying is a trap. It filters cobra's own additions out instead.
There is no error return. Every input is a program-internal structure, and the only thing that can go wrong — an unparseable MCP schema — is better reported as an empty section than as a failure that blocks generating the other four.
func (Surface) MarshalIndent ¶
MarshalIndent renders the inventory as the committed artifact: two-space indent and a trailing newline, so the file is an ordinary POSIX text file that git diffs sanely and an editor does not "fix" on save.