## 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>
75 lines
2.5 KiB
Go
75 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"path"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/coder/coder/v2/scripts/docgenenv"
|
|
)
|
|
|
|
// stateOrigin records the route that first sets a state value.
|
|
type stateOrigin struct {
|
|
file string
|
|
crumb string
|
|
}
|
|
|
|
// repeatedStates reports every route in the sidebar sources under dir whose
|
|
// state repeats a value already set on an ancestor route, or lists a value
|
|
// more than once. A state applies to all of a route's descendants, so a
|
|
// descendant sets only the states its ancestors lack. Includes are followed,
|
|
// so an ancestor in another file counts. Children of a children_from route
|
|
// are overlays and are checked the same way; the generated fragment itself is
|
|
// not. Call it only after docgenenv.BuildManifest succeeds, so every file
|
|
// decodes and every include resolves exactly once.
|
|
func repeatedStates(dir string) []error {
|
|
var idx docgenenv.ManifestIndex
|
|
if err := docgenenv.DecodeSourceFile(filepath.Join(dir, docgenenv.ManifestIndexFile), &idx); err != nil {
|
|
return []error{err}
|
|
}
|
|
var errs []error
|
|
for _, section := range idx.Sections {
|
|
checkStateFile(dir, path.Clean(section), nil, nil, &errs)
|
|
}
|
|
return errs
|
|
}
|
|
|
|
func checkStateFile(dir, name string, crumb []string, inherited map[string]stateOrigin, errs *[]error) {
|
|
var r docgenenv.Route
|
|
if err := docgenenv.DecodeSourceFile(filepath.Join(dir, filepath.FromSlash(name)), &r); err != nil {
|
|
*errs = append(*errs, err)
|
|
return
|
|
}
|
|
checkStateRoute(dir, name, r, crumb, inherited, errs)
|
|
}
|
|
|
|
func checkStateRoute(dir, name string, r docgenenv.Route, crumb []string, inherited map[string]stateOrigin, errs *[]error) {
|
|
crumb = append(slices.Clip(crumb), r.Title)
|
|
where := strings.Join(crumb, " > ")
|
|
states := make(map[string]stateOrigin, len(inherited)+len(r.State))
|
|
for k, v := range inherited {
|
|
states[k] = v
|
|
}
|
|
for _, s := range r.State {
|
|
if o, ok := inherited[s]; ok {
|
|
*errs = append(*errs, xerrors.Errorf("%s: %s: state %q is already set on ancestor %q in %s; remove it, because a route inherits its ancestors' states", name, where, s, o.crumb, o.file))
|
|
continue
|
|
}
|
|
if _, ok := states[s]; ok {
|
|
*errs = append(*errs, xerrors.Errorf("%s: %s: state %q is listed more than once", name, where, s))
|
|
continue
|
|
}
|
|
states[s] = stateOrigin{file: name, crumb: where}
|
|
}
|
|
for _, c := range r.Children {
|
|
if c.Include != "" {
|
|
checkStateFile(dir, path.Clean(c.Include), crumb, states, errs)
|
|
continue
|
|
}
|
|
checkStateRoute(dir, name, c, crumb, states, errs)
|
|
}
|
|
}
|