{"modulePath":"github.com/intentdriven/abcd","version":"v0.17.1","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package cli\n\nPackage cli is abcd's default front door: a Cobra command tree that marshals internal/core results to the terminal (human text or, with --json, machine output). It holds no business logic — every command delegates to core and only formats the result, so an MCP or other front door can expose the same core verbs without duplicating behaviour.\n\n## Constants\n\n```go\nconst (\n\tCommandFactsBegin    = \"\u003c!-- generated: command-facts --\u003e\"\n\tAskTheBinaryBegin    = \"\u003c!-- generated: ask-the-binary --\u003e\"\n\tGeneratedBeginPrefix = \"\u003c!-- generated:\"\n\tGeneratedEnd         = \"\u003c!-- /generated --\u003e\"\n)\n```\nThe markers fencing the two generated blocks of a command page. The end marker is the one every generated block in the repository closes with, and every begin marker opens with GeneratedBeginPrefix, this file's two and asking-sync's alike.\n\n```go\nconst CommandFactsDir = \"docs/reference/cli/commands\"\n```\nCommandFactsDir is the directory the per-verb JSON files are written to, repo-relative. It sits beside the generated CLI reference and outside commands/, which hosts read as command pages (the spec's first decision).\n\n```go\nconst CommandPagesDir = \"commands\"\n```\nCommandPagesDir is the plugin's command pages, repo-relative.\n\n```go\nconst ReferencePagePath = \"docs/reference/cli/commands.md\"\n```\nReferencePagePath is the committed CLI reference page, relative to the repo root. The generator writes it and the drift test (reference\\_test.go) diffs the freshly-walked tree against it, so the two agree on one location.\n\n```go\nconst SurfaceSnapshotPath = surface.SnapshotPath\n```\nSurfaceSnapshotPath is the committed compatibility snapshot, relative to the repo root. The generator writes it, the drift test (surface\\_test.go) diffs the freshly-walked surface against it, and the release guardrail reads the baseline copy of it out of the last release tag — so all three agree on one location, declared once beside the type in internal/core/surface. It sits under the development record rather than under docs/ because it is a release-gate input, not something a reader of the documentation consumes.\n\n```go\nconst UseWhenCap = 300\n```\nUseWhenCap is the most characters a page's use-when text may run to. The longest use-when clause of the deleted pages whose trigger phrases it carries ran to about 200.\n\n## Functions\n\n```go\nfunc AskTheBinaryBlock(name, rung string) string\n```\nAskTheBinaryBlock is the block that stands straight after a page's H1 heading, from its begin marker through its end marker: one sentence sending the agent to the running binary's \\`abcd explain\\` before it fills in an input, spelled with the page's own rung.\n\n```go\nfunc CommandFacts() []surface.Facts\n```\nCommandFacts is every command's facts (spc-2610301431075964 step 1), in canonical order, from a fresh tree that is never executed, for the same reason SurfaceSnapshot builds one.\n\n```go\nfunc CommandFactsBlock(facts []surface.Facts, name, rung string) string\n```\nCommandFactsBlock is the block that stands at the end of a page, from its begin marker through its end marker. Its first line names the facts' format version and sends the reader to the running binary where the two disagree. For each command the page covers it lists the usage line, each input with its schema version, and the example. A page whose commands declare no visible flag and read no input gets the first line alone.\n\n```go\nfunc CommandFactsFiles(facts []surface.Facts) (map[string][]byte, error)\n```\nCommandFactsFiles renders every per-verb JSON file from facts, keyed by its repo-relative path: one file per visible top-level verb holding that verb's visible subtree, and one named for the root holding the root command alone, whose persistent flags every verb inherits. A verb with no plugin page gets its file too.\n\n```go\nfunc EncodeCommandFacts(doc CommandFactsDocument) ([]byte, error)\n```\nEncodeCommandFacts encodes a facts document as the derived copies hold it: indented by two spaces, with no HTML escaping, so a usage line's \\\u003cverb\u003e reads as written, and with a closing newline.\n\n```go\nfunc GenerateReference() string\n```\nGenerateReference walks the abcd command tree and renders it as a single, deterministic Markdown reference page — the source of truth for docs/reference/cli/commands.md. Hidden commands (the operator-internal \\`hook\\` subtree) and the stubs of spellings that moved are omitted, and children are emitted in a stable alphabetical order, so the output depends only on the command tree — never on registration order or the clock. That determinism is what lets a \\`go test\\` diff detect drift.\n\n```go\nfunc GenerateSurface(repoRoot string) ([]byte, error)\n```\nGenerateSurface renders the current surface as the committed artefact's bytes. Both the generator and the drift test call it, so the file that is written and the file that is checked are produced by one code path and can never disagree on formatting.\n\n```go\nfunc GuardSurface(repoRoot string) (changelog.SurfaceGuard, error)\n```\nGuardSurface runs the release surface guardrail for the repository at repoRoot: it builds the CURRENT compatibility surface from the live command tree and the live manifests, and hands it to the core guardrail, which reads the baseline out of the last release tag and answers whether a narrowing was declared.\n\nThis is the split the architecture requires. Building the current surface means walking cobra, which internal/core may not do; judging a break is domain logic, which must not depend on a transport. The front door therefore owns the walk and core owns the verdict, and the dependency points one way only.\n\nIt is the entry point the ship flow calls. There is deliberately no \\`launch ship\\` verb yet — the write path is a later phase — so today this is reached from tests and from whatever front door composes the cut next; the guardrail itself is complete and does not change when that verb arrives.\n\n```go\nfunc IdentityGenSource(title, tagline string) []byte\n```\nIdentityGenSource is the single template for the generated identity file: the identitygen command writes it, and the drift test regenerates and byte-compares the committed file against it — one source, so the file can drift in neither values nor form (the livery RenderSVG shape).\n\n```go\nfunc InputShapes() ([]surface.InputShape, error)\n```\nInputShapes is every registered input's shape, sorted by command path and flag.\n\n```go\nfunc NewRootCommand() *cobra.Command\n```\nNewRootCommand builds the abcd command tree. Bare \\`abcd\\` renders a read-only status board (abcd's convention: bare invocation never mutates); subcommands carry the actions.\n\n```go\nfunc Run(args []string, stdout, stderr io.Writer) int\n```\nExecute runs the root command; main sets the process exit code on error. Run builds the command tree, executes it against args, and renders any error as a single diagnostic line — the one place that maps a command error to a process exit code, so main stays a thin shell. stdout/stderr are injected so the whole front door (including its error surface) is testable.\n\n```go\nfunc SurfaceChapters(repoRoot string) ([]surface.RegeneratedChapter, error)\n```\nSurfaceChapters regenerates every brief surface chapter's appendix from the live command tree (itd-147). It walks the tree with commandSurface — the walk that builds the compatibility snapshot — so the snapshot and the chapters are derived from one traversal and cannot disagree about what the tree holds. The generator (cmd/abcd-gen-surface) writes each chapter's Want and the drift test compares it with Committed, so both come from this one call.\n\nWhich shipped surfaces are host-delegated is read from the record-lint config's surface\\_coverage host\\_delegated list, the one place it is declared, so an appendix calls a command host-delegated only when that list does (iss-2609302306003610).\n\n```go\nfunc SurfaceSnapshot(repoRoot string) (surface.Snapshot, error)\n```\nSurfaceSnapshot builds the current compatibility surface: every command in the tree with its flags, plus the declared entries of the two plugin manifests under repoRoot.\n\nIt walks the shared NewRootCommand() tree — the one canonical root command, the same one the CLI executes — rather than the Markdown reference walker. GenerateReference emits prose, returns early on hidden commands, and carries no structured requiredness or manifest data; reusing it would bake those blind spots into a compatibility gate. What is shared is the tree, which is the part that must not diverge.\n\nThe tree is built fresh here and never executed. Cobra lazily attaches its default \\`help\\` and \\`completion\\` machinery during execution, so snapshotting an executed tree would record surface that a freshly-built one does not have, and the answer would depend on what else ran first in the process.\n\n```go\nfunc SyncCommandPage(page []byte, name string, facts []surface.Facts) ([]byte, error)\n```\nSyncCommandPage returns page with both generated blocks rendered from facts for the page named name, every byte outside the blocks kept. A block that is present is rewritten where it stands, which must be its place: the ask-the-binary block straight after the H1 heading, with nothing but blank lines between, and the command-facts block last, followed by nothing but the closing user-input line. A block that is absent is written into its place. A page with no H1 heading, a block opened twice or never closed (before the page ends, or before another generated block opens), a block out of its place, or a name the tree has no visible verb for is a fault: the generator never guesses.\n\n## Types\n\n```go\ntype CommandFactsDocument struct {\n\tFormatVersion int             `json:\"format_version\"`\n\tCommands      []surface.Facts `json:\"commands\"`\n}\n```\nCommandFactsDocument is the shape of every derived JSON copy of the facts: each per-verb file and \\`abcd explain --json\\` for one command. It carries the facts' format version and no binary version, so a file changes only when a fact does.\n\n```go\ntype SentencePage struct {\n\tFile      string\n\tCommitted string\n\tWant      string\n}\n```\nSentencePage is one plugin command page: its repo-relative path, the bytes committed, and the bytes it holds once its description is the verb's sentence and the page's use-when text, if it declares one. The generator writes Want where the two differ, and the drift test fails on any page where they do.\n\n```go\nfunc SentencePages(repoRoot string) ([]SentencePage, error)\n```\nSentencePages renders every plugin command page that backs a visible verb of the tree: commands/\\\u003cverb\u003e.md for each visible top-level verb, and the root's own page, commands/abcd.md. A verb with no page (abcd has verbs no page documents on its own) contributes nothing, and a page with no verb (a page whose work runs in the host) is not this manifest's to rewrite.\n\nA page that exists but carries no frontmatter description is an error naming the page, rather than a description inserted at a guessed position.\n\n","path":"github.com/intentdriven/abcd/internal/surface/cli","name":"cli","synopsis":"Package cli is abcd's default front door: a Cobra command tree that marshals internal/core results to the terminal (human text or, with --json, machine output).","isRedistributable":true}
