Documentation
¶
Overview ¶
Package agent holds what audd offers coding agents: the documentation topics behind `audd docs`, the skill and rules files `audd agent-setup` writes, and the machine-readable command reference behind `audd commands --json`.
Index ¶
- Constants
- Variables
- func DocsBase() string
- func FetchDocs(ctx context.Context, client *http.Client, base string, t Topic) (string, error)
- func MergeAgentsMD(existing, section string) (string, error)
- func Render(t Target) (string, error)
- func SetRequiredWhen(fs *pflag.FlagSet, name, when string)
- func TopicNames() []string
- type Command
- type ExitCode
- type Flag
- type Output
- type Reference
- type Target
- type Topic
- type WriteResult
Constants ¶
const ( BeginMarker = "<!-- audd:begin (written by audd agent-setup; edits inside are replaced) -->" EndMarker = "<!-- audd:end -->" )
Markers around the audd section in AGENTS.md, so running agent-setup again replaces the section instead of adding another.
const AnnotationAliasOf = "audd:alias_of"
AnnotationAliasOf is the cobra annotation on a top-level shortcut (audd logout) that names the command it runs ("auth logout"). Shortcuts are listed even when hidden from help.
const AnnotationRequiredWhen = "audd_required_when"
AnnotationRequiredWhen is the flag annotation that SetRequiredWhen sets.
const AnnotationStreaming = "audd:streaming"
AnnotationStreaming is the cobra annotation for commands whose piped output is JSON lines (the same key internal/cli uses).
const DefaultDocsBase = "https://docs.audd.io"
DefaultDocsBase is where the AudD docs live. Each page has a markdown twin at the same path plus ".md".
Variables ¶
var AllTargets = []Target{TargetClaude, TargetCursor, TargetAgentsMD}
AllTargets lists the targets in a fixed order.
var CLIDoc string
CLIDoc is the CLI reference served by `audd docs cli`.
var ErrUnclosedSection = errors.New("AGENTS.md has an audd begin marker but no " + EndMarker + " after it")
ErrUnclosedSection means an AGENTS.md has an audd begin marker with no end marker after it, so the end of the audd section is unknown.
var ExitCodes = []ExitCode{
{0, "ok", "success, including no match"},
{1, "unexpected", "unexpected error, or no match with --fail-on-no-match"},
{2, "usage", "invalid arguments or input, or a missing tool such as ffmpeg"},
{3, "auth", "missing or rejected API token, or sign-in needed (audd login)"},
{4, "quota", "quota, plan, or feature not available on the account"},
{5, "network", "network or server error; retrying may help"},
{6, "safety", "a bound is missing (--limit, --max-files), a confirmation is needed (--yes), --max-requests was reached, or an unfinished job for the same files needs --resume or --new"},
{7, "partial", "a batch finished with some files failed"},
{8, "threshold", "usage --check found fewer remaining requests than --min-remaining"},
{130, "interrupted", "stopped with Ctrl-C; a batch keeps finished files (audd jobs resume continues it)"},
}
ExitCodes are the exit codes every command uses.
var Outputs = map[string]Output{ "object": {Description: `one JSON document: {"schema_version":1, ...fields}`}, "list": {Description: `one JSON document with the rows under "items": {"schema_version":1,"items":[...]}`}, "recognition": { Description: `One file or URL: {"schema_version":1,"input","cached","result"} where result is AudD's result object or null for no match; with --enterprise, "matches" (and "tracks" with --tracklist) instead of "result"; with --dry-run (one input or a batch), {"dry_run":true,"input":name|null,"job_id":id|null,"endpoint":"standard"|"enterprise","plan":{"files","cached_files","requests","approximate","cost_usd"}}: input is set for one file or URL, job_id when a batch would resume a job; requests and cost_usd are null with "unbounded":true when enterprise URLs with --limit none (or a dry run without --limit) leave the scan uncapped; with --format jsonl the plan is a "type":"event" line with "event":"dry_run". Folders, globs, lists, and jobs resume print JSON lines: "result" per file, "progress", and a final "summary" whose counts are for the whole job (as in audd jobs list), with "requests_spent_this_run" for this run.`, Schema: obj(map[string]any{ "schema_version": typ("integer"), "input": typ("string"), "cached": typ("boolean"), "result": map[string]any{"type": []string{"object", "null"}, "description": "AudD's result: artist, title, album, release_date, label, timecode, song_link, plus any --return blocks"}, "matches": map[string]any{"type": "array", "description": "enterprise matches, each with start and end positions"}, "tracks": map[string]any{"type": "array", "description": "with --tracklist: merged tracks with start_seconds and end_seconds"}, }), }, "api_response": {Description: `{"schema_version":1, ...the fields of the API's JSON response}: the response as AudD sent it, with "schema_version" added`}, "plays": { Description: `{"schema_version":1,"since","plays":[play...],"gaps":[{"from","to"}...]}: plays newest first; gaps are periods some stream was not recorded, so totals may miss plays there`, Schema: obj(map[string]any{ "plays": map[string]any{"type": "array", "items": playSchema}, "gaps": map[string]any{"type": "array", "items": gapSchema}, }), }, "play_stream": { Description: `JSON lines: {"schema_version":1,"type":"result", ...play} per play, and "event" lines for stream health`, Schema: playSchema, }, "now_playing": { Description: `With --once, one document with the latest song of each stream ({"stations":[{"radio_id","url","stream_running","health","now_playing":{...play,"state","playing","elapsed_seconds","played_seconds","ended_at","ago_seconds","length_seconds"}}]}); otherwise JSON lines, a "result" line with the same fields each time the song changes. state is just_played or last_recognized for results sent when a song ends (the default), playing for streams added with --start; elapsed_seconds only while playing, played_seconds and ended_at only for end-of-song results, length_seconds only with provider metadata`, }, "report": { Description: `{"schema_version":1,"by","since","rows":[{"key","plays","airtime_seconds","stations"}...],"gaps","complete"}; complete is false when gaps mean totals miss plays`, }, "docs": {Description: `The page's markdown as is, piped or not; with --format json, {"schema_version":1,"topic","source","markdown"}. Without a topic, the list of topics`}, "commands": {Description: "this reference"}, "error": { Description: "printed to stderr when a command fails in a machine format", Schema: obj(map[string]any{ "schema_version": typ("integer"), "error": obj(map[string]any{ "code": typ("string"), "api_code": typ("integer"), "message": typ("string"), "hint": map[string]any{"type": "string", "description": "usually the command that fixes it"}, "retryable": typ("boolean"), }), }), }, }
Outputs describes the JSON shapes commands print.
var Topics = []Topic{
{Name: "api", Title: "Recognition API: endpoints, parameters, results, errors", Path: "/.md", Account: "api"},
{Name: "enterprise", Title: "Enterprise endpoint: whole files, every match with timestamps", Path: "/enterprise.md", Account: "enterprise"},
{Name: "streams", Title: "Stream monitoring: streams, callbacks, longpoll", Path: "/streams.md", Account: "streams"},
{Name: "upload", Title: "Sending audio files and URLs", Path: "/upload_audio_endpoint.md", Account: "upload"},
{Name: "mcp", Title: "The AudD MCP server", Path: "/mcp.md"},
{Name: "sdks", Title: "Official SDKs", Path: "/sdks.md"},
{Name: "cli", Title: "This CLI: commands, limits, output, exit codes"},
}
Topics are the documentation topics, in display order.
Functions ¶
func DocsBase ¶
func DocsBase() string
DocsBase returns the docs site, or AUDD_DOCS_URL when set (tests, mirrors).
func FetchDocs ¶
FetchDocs downloads a topic's markdown from the docs site at base. Embedded topics are returned without a request.
func MergeAgentsMD ¶
MergeAgentsMD puts section into an AGENTS.md: it replaces an existing audd section, or appends one after the existing text. A begin marker without an end marker is ErrUnclosedSection: guessing where the section ends could delete the user's own text.
func Render ¶
Render returns the instructions for a target. For AGENTS.md it is the section including its markers.
func SetRequiredWhen ¶
SetRequiredWhen records in the reference when a conditionally required flag must be given. The command still checks it itself.
Types ¶
type Command ¶
type Command struct {
Path string `json:"path"` // "audd streams add"
Aliases []string `json:"aliases,omitempty"`
// AliasOf is the command this one is a shortcut for: audd logout is
// audd auth logout.
AliasOf string `json:"alias_of,omitempty"`
Summary string `json:"summary"`
Usage string `json:"usage"`
// Runnable is false for groups that only hold subcommands.
Runnable bool `json:"runnable"`
Flags []Flag `json:"flags,omitempty"`
Examples []string `json:"examples,omitempty"`
Output string `json:"output,omitempty"` // a key of Reference.Outputs
Streaming bool `json:"streaming,omitempty"`
ExitCodes []int `json:"exit_codes,omitempty"`
}
Command describes one command.
type ExitCode ¶
type ExitCode struct {
Code int `json:"code"`
Name string `json:"name"`
Meaning string `json:"meaning"`
}
ExitCode is one exit code and its meaning.
type Flag ¶
type Flag struct {
Name string `json:"name"`
Shorthand string `json:"shorthand,omitempty"`
Type string `json:"type"`
Default string `json:"default,omitempty"`
Required bool `json:"required,omitempty"`
// RequiredWhen names the case in which the flag is required, for flags
// that are required only sometimes (for example --limit with --enterprise).
RequiredWhen string `json:"required_when,omitempty"`
Usage string `json:"usage"`
}
Flag describes one flag.
type Output ¶
type Output struct {
Description string `json:"description"`
Schema map[string]any `json:"schema,omitempty"`
}
Output describes what a command prints when piped or with --format json.
type Reference ¶
type Reference struct {
Version string `json:"version"`
GlobalFlags []Flag `json:"global_flags"`
Commands []Command `json:"commands"`
ExitCodes []ExitCode `json:"exit_codes"`
Outputs map[string]Output `json:"outputs"`
}
Reference is the output of `audd commands --json`: every command, its flags, what it prints, and the exit codes.
type Target ¶
type Target string
Target is a coding agent's instructions file format.
const ( TargetClaude Target = "claude" // Claude Code skill: .claude/skills/audd/SKILL.md TargetCursor Target = "cursor" // Cursor rule: .cursor/rules/audd.mdc TargetAgentsMD Target = "agents-md" // a section in AGENTS.md (Codex and others) )
Targets audd agent-setup can write.
type Topic ¶
type Topic struct {
Name string `json:"name"`
Title string `json:"title"`
// Path is the markdown page on the docs site; empty for embedded topics.
Path string `json:"-"`
// Account is the topic name the account service's docs tool knows, used
// when the docs site cannot be reached; empty when it has none.
Account string `json:"-"`
}
Topic is one `audd docs` topic.
func (Topic) PageURL ¶
PageURL is the topic's page for people to open: the markdown URL without ".md" ("https://docs.audd.io/" for the api topic), or "" for embedded topics.