Files
coder/scripts/docsmanifestgen/main.go
T
Nick Vigilanteanddefault 1271dcb570 docs: inherit feature states from ancestor routes in the docs sidebar (#31975)
## Summary

A feature `state` in `docs/manifest/` now applies to a route and all its
descendants, so each state is set once on the highest route it applies
to.
`docsmanifestgen check` rejects a route that repeats an ancestor's
state, and the repeated states on `main` are removed.

## State model

- Put a state on the highest route it applies to.
- Add a state to a descendant only when it is new, such as an early
access page inside a Premium section.
- The sidebar shows a pill on the route that sets the state and on
descendants whose state differs.
- Every page shows its full state, own plus inherited, under the title.

## Changes

- `docsmanifestgen check` (`make lint/docs-manifest`) fails when a route
repeats an ancestor's state, following include files and overlays, or
lists a state twice.
  It runs only after the manifest builds cleanly.
  Table-driven tests in `scripts/docsmanifestgen/state_test.go`.
- Keep `state: [premium]` on AI Governance and External provisioners
only.
Remove the 27 states their descendants repeat in
`docs/manifest/ai-governance/**` and
`docs/manifest/install/operate/provisioners.yml`, and regenerate
`docs/manifest.json`.
- Document the model in `contributing/documentation.md` (new "Feature
states" section with a YAML example),
`docs/.style/content-guidelines.md`, and the doc-check skill.

> [!IMPORTANT]
> Inherited pills under the page title and the new sidebar behavior need
the matching docs-engine change
([DOCS-1440](https://linear.app/codercom/issue/DOCS-1440)).
> Merge this after that ships, or child pages show no state pill until
it does.

## Testing

- `go test ./scripts/docsmanifestgen/... ./scripts/docgenenv/...`
- `golangci-lint run ./scripts/docsmanifestgen/...`
- `GOOS=windows` and `GOOS=darwin` `go vet ./scripts/docsmanifestgen/`
- `make lint/docs-manifest`, `make lint/markdown`, `make
lint/docs-redirects`
- `make gen/docs-manifest` leaves the tree clean.

<details>
<summary>Decision log: rebase onto main after #31645</summary>

- #31645 (merged 2026-11-04) moved AI Governance to a top-level section
with Agent Firewall and AI Gateway nested under it, and added the
`ai-coder/...` redirects.
That covered this PR's move commits, link and URL updates, and
redirects, which caused the conflicts.
- The branch was rebuilt on `main`: the two move commits were dropped,
and the four state-tooling and guidance commits were cherry-picked.
The manifest cleanup was redone as a new commit against `main`'s layout,
using the new lint's output as the list of repeated states.
- Agent Relay is now top-level with `state: [premium, beta]` and no
child states, so it needs no change.
- Conflicts in `content-guidelines.md` and the doc-check skill were
resolved to keep `main`'s newer text (Vale word-choice updates and
relative redirect syntax) and apply only the feature-states lines.
- The pre-rebase head was `a797f59737`.

</details>

> Generated by Coder Agents on behalf of @nickvigilante.


Supersedes #31481, reopened under a human author for attribution.

---------

Co-authored-by: default <default@example.com>
2026-11-12 13:19:38 -05:00

79 lines
2.0 KiB
Go

// Command docsmanifestgen compiles the YAML sidebar sources under
// docs/manifest into docs/manifest.json, formats those sources, and checks
// them.
//
// Usage:
//
// docsmanifestgen build [-docs docs] [-out docs/manifest.json]
// docsmanifestgen fmt [-docs docs]
// docsmanifestgen check [-docs docs]
package main
import (
"errors"
"flag"
"fmt"
"os"
"path/filepath"
"golang.org/x/xerrors"
"github.com/coder/coder/v2/scripts/atomicwrite"
"github.com/coder/coder/v2/scripts/docgenenv"
)
func main() {
if err := run(os.Args[1:]); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(args []string) error {
if len(args) == 0 {
return xerrors.New("usage: docsmanifestgen <build|fmt|check> [flags]")
}
fs := flag.NewFlagSet("docsmanifestgen "+args[0], flag.ContinueOnError)
docsDir := fs.String("docs", "docs", "Docs directory. Sources are read from its manifest subdirectory.")
out := fs.String("out", "", "Output path for build. Defaults to manifest.json in the docs directory.")
if err := fs.Parse(args[1:]); err != nil {
return err
}
sourcesDir := filepath.Join(*docsDir, docgenenv.ManifestSourcesDir)
switch args[0] {
case "build":
m, err := docgenenv.BuildManifest(sourcesDir, *docsDir)
if err != nil {
return err
}
b, err := docgenenv.MarshalJSON(m)
if err != nil {
return err
}
if *out == "" {
*out = filepath.Join(*docsDir, "manifest.json")
}
return atomicwrite.File(*out, b)
case "fmt":
return formatSources(sourcesDir)
case "check":
var errs []error
if _, err := docgenenv.BuildManifest(sourcesDir, *docsDir); err != nil {
errs = append(errs, err)
} else {
errs = append(errs, repeatedStates(sourcesDir)...)
}
unformatted, err := unformattedSources(sourcesDir)
if err != nil {
errs = append(errs, err)
}
for _, f := range unformatted {
errs = append(errs, xerrors.Errorf("%s: not formatted; run make fmt/docs-manifest", f.rel))
}
return errors.Join(errs...)
default:
return xerrors.Errorf("unknown subcommand %q: want build, fmt, or check", args[0])
}
}