skilldoc

package
v1.3.50 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package skilldoc derives a structured description of the flashduty CLI's command tree (the "dump") and uses it to generate and validate the command-cards that document the CLI for an LLM operator.

The dump is the single source of truth: it is built in-process from the live cobra tree (see Build), so it can never drift from the binary it describes. The generator turns a dump into per-domain factual fences; the validator checks every documented `fduty …` example against the same dump.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FenceEnd

func FenceEnd(id string) string

func FenceStart

func FenceStart(id string) string

FenceStart / FenceEnd return the literal markers for a fence id (a bare group, or group[prefix,…] — see ParseFenceID), used to locate fences in docs.

func FindFence added in v1.3.44

func FindFence(body, id string) (start, end int, ok bool)

FindFence locates the full fenced block for id in body: start is the byte offset of the start marker, end is the offset just past the end marker. ok is false when either marker is missing.

func GenerateFence

func GenerateFence(d Dump, group string) string

GenerateFence renders the fenced block for a group whose only fence is the catch-all — i.e. all of the group's commands in one block. Groups split across several cards must go through RenderGroupFences instead, which knows the sibling subset fences.

func HasPlaceholder

func HasPlaceholder(tok string) bool

HasPlaceholder reports whether tok is a documentation placeholder rather than a literal argument: angle-bracket tokens (<id>), shell vars ($VAR), the ellipsis (...), or `ou_xxx`-style stand-ins. The validator skips the value of any flag whose token is a placeholder.

func RenderGroupFences added in v1.3.44

func RenderGroupFences(d Dump, group string, ids []string) (map[string]string, []string)

RenderGroupFences renders the fenced block for every fence of one command group. ids must be the complete set of fence ids that exist for the group across all cards — the catch-all fence renders whatever its sibling subset fences leave unclaimed, so a fence cannot be rendered in isolation. Topology problems (a verb claimed twice, a prefix claiming nothing, verbs left over with no catch-all, a duplicated id) come back as violations; rendered blocks are still returned for the fences that parsed.

Types

type Command

type Command struct {
	Path  string `json:"path"`  // space-joined name chain below root, e.g. "status-page change-create"
	Group string `json:"group"` // first path segment, e.g. "status-page"
	Short string `json:"short"`
	// Use is cobra's raw Use string, e.g. "change-create <page-id>". cligen folds
	// a required *_id field into a positional argument and records it here as a
	// <placeholder>; that field is then supplied positionally, NOT via its
	// same-named --flag (passing the flag alone fails the Args check). Capturing
	// Use is what lets the generator render the correct positional invocation —
	// the bare Path alone (which strips the placeholder) cannot.
	Use     string `json:"use"`
	Long    string `json:"long"` // cligen's Request/Response field text (authoritative for enums + nested --data)
	Example string `json:"example"`
	Flags   []Flag `json:"flags"`
}

Command is one runnable leaf of the CLI tree.

type Doc

type Doc struct {
	Path string
	Body string
}

Doc is a documentation file fed to the validator: its display Path (for issue reporting) and raw markdown Body.

type Dump

type Dump struct {
	Commands []Command `json:"commands"`
}

Dump is the structured snapshot of the CLI's command tree. It is the JSON contract shared between the dump oracle, the validator, and the generator.

func Build

func Build(root *cobra.Command) Dump

Build walks the cobra tree rooted at root and returns a structured dump of every runnable, non-hidden leaf command. Group containers (parents with their own subcommands, like "status-page") are descended into but not emitted themselves — see the predicate comment in walk for why this is keyed off subcommands rather than Runnable().

Path is the space-joined chain of cobra command names below the root, using c.Name() so a positional placeholder in Use (e.g. "change-create <page-id>") is stripped to the bare verb. Required flags are detected via cobra's one-required-flag annotation. Enums and nested --data fields are NOT re-derived here; they live verbatim in Long, which cligen authored.

type Example

type Example struct {
	Line   int
	Tokens []string
}

Example is one harvested CLI invocation from a markdown document. Tokens are the whitespace-separated arguments AFTER the `fduty`/`flashduty` binary word (so Tokens[0] is the command group). Line is the 1-based line where the invocation began.

func HarvestExamples

func HarvestExamples(md string) []Example

HarvestExamples pulls every `fduty`/`flashduty` invocation out of markdown: fenced code blocks (```…```) and inline backtick spans alike. A candidate is any line whose first shell word is the binary; trailing-backslash continuations are joined into one example. Prose lines (no binary word) are ignored.

type FenceLoc added in v1.3.44

type FenceLoc struct {
	ID     string
	Offset int // byte offset of the start marker
}

FenceLoc is one GENERATED start marker found in a doc body.

func FenceLocs added in v1.3.44

func FenceLocs(body string) []FenceLoc

FenceLocs returns every GENERATED start marker in body, in document order.

type FenceSpec added in v1.3.44

type FenceSpec struct {
	Group    string
	Prefixes []string // empty → the group's catch-all fence
}

FenceSpec is one parsed fence id.

func ParseFenceID added in v1.3.44

func ParseFenceID(id string) (FenceSpec, error)

ParseFenceID parses a fence id as found in a GENERATED marker.

func (FenceSpec) ID added in v1.3.44

func (s FenceSpec) ID() string

ID renders the spec back to its marker id ("group" or "group[p1,p2]").

type Flag

type Flag struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	Default  string `json:"default"`
	Usage    string `json:"usage"`
	Required bool   `json:"required"`
}

Flag is one flag of a command, as exposed by pflag.

type Issue

type Issue struct {
	Doc    string
	Line   int
	Kind   string // "unknown-command" | "unknown-flag" | "stale-fence" | "fence-topology"
	Detail string
}

Issue is one validation finding against the command oracle.

func CheckFences

func CheckFences(d Dump, docs []Doc) []Issue

CheckFences asserts every GENERATED fence embedded in docs matches a fresh render from the dump, and that each group's fences form a valid partition of the group's commands (see RenderGroupFences). A drifted fence or a start marker with no matching end marker yields a stale-fence issue; a malformed or unknown-group marker, and any partition violation, yields a fence-topology issue anchored at the group's first fence.

func Validate

func Validate(d Dump, docs []Doc) []Issue

Validate checks every harvested `fduty …` example in docs against the dump: an example whose leading words resolve to no command path yields an unknown-command issue; an example flag absent from its command's flag set (and not a global flag) yields an unknown-flag issue. Placeholder tokens are skipped so documentation stand-ins (<id>, $VAR) never trip the validator.

Jump to

Keyboard shortcuts

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