Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions claudedocs/decisions/36-agents-block-per-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,61 @@ Two consequences worth naming, so this is not re-derived from the headline:
"satisfies neither arm" of its closing condition, and that is still true: this
ships no install fix. The cause-side remedy is candidate (b), which lives in the
hosted prompt in another repo.

## Fifth: every docs PAGE the block links is the `.md` rendering (2026-10-14)

The `### Docs` section says the `.md` suffix serves the plain-text source an
agent can read directly, and then linked three pages by their HTML route:
`/apps/reference/` (twice, one per SDK arm), `/apps/guide/` and
`/apps/examples`. The `--track api` refusal did the same with `/site/` and
`/orchestration/`. All five now link the `.md` rendering.

Measured 2026-10-14 from this host, redirects NOT followed:

| Spelling | Status | Content-Type | Body starts |
|---|---|---|---|
| `/apps/reference/` | `200` | `text/html` | `<!DOCTYPE html>` (~77 KB) |
| `/apps/reference.md` | `200` | `text/markdown` | front matter (~2.5 KB) |
| `/apps/guide/` | `200` | `text/html` | `<!DOCTYPE html>` (~89 KB) |
| `/apps/guide.md` | `200` | `text/markdown` | front matter (~6 KB) |
| `/apps/examples` | `200` | `text/html` | `<!DOCTYPE html>` (~118 KB) |
| `/apps/examples.md` | `200` | `text/markdown` | front matter (~23 KB) |
| `/site.md`, `/orchestration.md` | `200` | `text/markdown` | front matter |
| `/__civitai-cli-link-probe-must-404__.md` | `404` | — | negative control |

As §"The trailing slash is measured, never tidied" says, each spelling is a
measurement: the `.md` twin of `/apps/guide/` is `/apps/guide.md`, not
`/apps/guide/index.md`, and it was probed rather than inferred.

**The "over 100 KB, so page it" sentence was replaced, not updated.** Agent
fetch tools truncate around 100,000 characters without saying so, and the
large reference pages (`hooks.md`, `generation.md`, `cli.md`) were each well
past that on this date. A split of those pages into hub + sub-pages at the same
URLs was in flight in the docs repo but NOT merged, so the replacement line is
written to be true on both sides of it: it names no size, promises no
sub-page, and tells the agent that missing content was probably truncated —
download and search the page, or fetch a narrower page *if the page links to
one*. It sits in the shared tail, so the `@civitai/sdk` arm (whose
`generation.md` pointer is just as large) gets it too. **Measured cost: +238
bytes of template** (the line added, less the sentence it replaced and the
`.md` suffixes). It is guidance about how to READ the linked pages, not their
contents, so it is not a third named exception to the addresses-only rule.

### Guards

- `TestEveryDocsPageURLAnAgentReceivesIsMarkdown`
(`internal/cmd/agent_setup_markdown_links_test.go`) — every
`developer.civitai.com` address in the WHOLE rendered block, for every shape
under both SDK arms, plus the `--track api` refusal, must end `.md` or be
`/llms.txt`. A rule about the address SHAPE, so a link added later is covered.
Red at `origin/main` `ca9504b` with only the test file added (32 findings:
three HTML routes × 10 rendered blocks, plus the refusal's two); green at HEAD.
- `TestHTMLRouteDetectorCanFail` — its control: the detector flags both HTML
shapes the block shipped (trailing slash, bare) and passes `.md`/`llms.txt`.
- `TestEveryDocsURLSpellingIsLedgered` now also derives, from each `.md`
golden URL, its directory form `<path>/`. Without it, 12 ledger rows that
link pages UNDER `/apps/guide/` (README.md, the scaffolds' `responsive`
pointer, …) went "no longer spells ANY" in this one edit while none of their
URLs changed. The bare `<path>` was rejected as the needle because it also
matches `internal/redact` fixtures that are not a rot surface. Ledger result
unchanged: 17 ledgered, 4 exempt, before and after.
4 changes: 2 additions & 2 deletions internal/cmd/agent_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func agentSetupTrackAPIRefusal() error {
fmt.Fprintf(&b, " %-22s %s\n", srv.Name, srv.URL)
}
b.WriteString("\nRegister both with `civitai agent-setup --track app` (they are the same two servers) and read:\n")
b.WriteString(" https://developer.civitai.com/site/\n")
b.WriteString(" https://developer.civitai.com/orchestration/\n")
b.WriteString(" https://developer.civitai.com/site.md\n")
b.WriteString(" https://developer.civitai.com/orchestration.md\n")
b.WriteString("\nA dedicated API track is coming; until then nothing about the API is unsupported, only this command's setup for it")
return asUsageError(errors.New(b.String()))
}
Expand Down
33 changes: 26 additions & 7 deletions internal/cmd/agent_setup_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ the manifest fields and the scopes are documented on the docs site, and the

- **` + "`https://developer.civitai.com/apps/reference/hooks.md`" + `** — the COMPLETE
hook reference. Fetch it first: a hook you cannot find here probably exists
under a name you have not guessed. It is over 100 KB, so page it rather than
giving up on it.
under a name you have not guessed.
- Capabilities are hooks AND generation body kinds (a multi-step workflow is a
` + "`kind`" + `, not a hook); the kinds are listed at
https://developer.civitai.com/apps/reference/generation.md
- Reference (manifest, scopes, hooks, message bridge, CLI):
https://developer.civitai.com/apps/reference/
- Guide: https://developer.civitai.com/apps/guide/
https://developer.civitai.com/apps/reference.md
- Guide: https://developer.civitai.com/apps/guide.md
- **` + "`https://developer.civitai.com/apps/guide/earning.md`" + `** — the three money
rails. Fetch it before declaring a ` + "`goods`" + ` catalog. The three rules below are
repeated in this file deliberately, because they are the ones a manifest can
Expand All @@ -79,8 +78,12 @@ the manifest fields and the scopes are documented on the docs site, and the
most one** unlock per manifest, and MUST carry a ` + "`justification`" + `. All three are
enforced at submit; the published JSON Schema does not declare them.
- Example apps you can read end-to-end:
https://developer.civitai.com/apps/examples
https://developer.civitai.com/apps/examples.md
- Full doc index for agents: https://developer.civitai.com/llms.txt
- Some reference pages are long enough that a fetch tool cuts them off without
saying so. If what you need is not in what came back, it was probably
truncated, not missing: download the whole page and search it, or, if the
page links to a narrower page for that part, fetch that one.

Reading ` + "`node_modules/@civitai/blocks-react/dist/*.d.ts`" + ` to find out what the
SDK can do is the expensive way round. Fetch the reference.`
Expand Down Expand Up @@ -418,9 +421,25 @@ func TestEveryDocsURLSpellingIsLedgered(t *testing.T) {
// Match on host+path rather than the full URL: the header comment above names
// the examples page without a scheme, and that mention rots exactly like a
// link does.
needles := make([][]byte, 0, len(urls))
//
// 🔴 A `.md` URL ALSO CONTRIBUTES ITS DIRECTORY FORM, `<path>/`. The block
// links the `.md` rendering of each page (TestEveryDocsPageURLAnAgent-
// ReceivesIsMarkdown), while most ledgered files link pages UNDER it by their
// HTML route — README.md's `/apps/guide/local-dev`, the scaffolds'
// `/apps/guide/responsive`. When the block spelled `/apps/guide/`, that
// needle matched those as a PREFIX; `/apps/guide.md` matches none of them,
// and 12 ledger rows went "no longer spells ANY" in one edit without a single
// URL in those files changing. The directory form restores exactly that
// prefix match. It is deliberately not the bare `<path>`, which would also
// match unrelated fixtures (internal/redact's `/apps/guide#scopes`) that are
// not a place a moved page rots.
needles := make([][]byte, 0, 2*len(urls))
for _, u := range urls {
needles = append(needles, []byte(strings.TrimPrefix(strings.TrimPrefix(u, "https://"), "http://")))
hostPath := strings.TrimPrefix(strings.TrimPrefix(u, "https://"), "http://")
needles = append(needles, []byte(hostPath))
if page, ok := strings.CutSuffix(hostPath, ".md"); ok {
needles = append(needles, []byte(page+"/"))
}
}

root := repoRootDir(t)
Expand Down
110 changes: 110 additions & 0 deletions internal/cmd/agent_setup_markdown_links_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package cmd

// Every docs PAGE address an agent receives from `agent-setup` is the `.md`
// rendering, never the HTML route.
//
// 🔴 WHY THIS IS A RULE AND NOT A STYLE. The managed block tells its reader
// that "the `.md` suffix serves the plain-text source an agent can read
// directly", and then — until this guard — linked four pages by their HTML
// route (`/apps/reference/`, `/apps/guide/`, `/apps/examples`). Measured
// 2026-10-14: each of those answers `200 text/html` with a full site shell
// (`<!DOCTYPE html>`, 77–118 KB), while its `.md` twin answers
// `200 text/markdown` at a fraction of the size. An agent following the HTML
// link spends its fetch budget on navigation chrome, and the block contradicts
// its own sentence about the suffix. The `--track api` refusal is held to the
// same rule: it is read by the same agent, at the moment it is deciding where
// to go next.
//
// The rule is about the SHAPE of every address, not a list of addresses, so a
// link added later is covered without anyone editing this file. Liveness of the
// `.md` spellings is TestBlockDocsLinksResolve's job (opt-in, networked); this
// test is offline and runs in `make ci`.

import (
"net/url"
"strings"
"testing"
)

// docsHost is the host the rule governs. Other hosts (the MCP endpoints, GitHub)
// are not docs pages and have no `.md` twin.
const docsHost = "developer.civitai.com"

// htmlRouteDocsURLs returns how many developer.civitai.com addresses `text`
// carries and which of them are HTML routes rather than markdown/plain-text
// renderings. `/llms.txt` is the one non-`.md` address that is already plain
// text; a bare host (no path) names the site, not a page.
func htmlRouteDocsURLs(text string) (checked int, bad []string) {
for _, raw := range docsLinkRe.FindAllString(text, -1) {
u, err := url.Parse(strings.TrimRight(raw, ".,;:"))
if err != nil || u.Host != docsHost {
continue
}
checked++
p := u.Path
if p == "" || p == "/" || strings.HasSuffix(p, ".md") || p == "/llms.txt" {
continue
}
bad = append(bad, raw)
}
return checked, bad
}

// TestHTMLRouteDetectorCanFail is the control for htmlRouteDocsURLs: it must
// flag each HTML-route shape the block actually shipped before this guard
// (trailing slash, no suffix), pass the `.md` and `llms.txt` spellings, and
// ignore other hosts. Without it a detector that matched nothing would report
// every block clean.
func TestHTMLRouteDetectorCanFail(t *testing.T) {
const in = "a https://" + docsHost + "/apps/guide/ b https://" + docsHost + "/apps/examples " +
"c https://" + docsHost + "/apps/guide/earning.md d https://" + docsHost + "/llms.txt " +
"e https://mcp.civitai.com/mcp f `https://" + docsHost + "/apps/reference/x.md`"
checked, bad := htmlRouteDocsURLs(in)
if checked != 5 {
t.Errorf("checked %d docs-host address(es), want 5 — the extractor is not seeing what the block spells", checked)
}
want := []string{"https://" + docsHost + "/apps/guide/", "https://" + docsHost + "/apps/examples"}
if strings.Join(bad, " ") != strings.Join(want, " ") {
t.Errorf("flagged %q, want exactly %q", bad, want)
}
}

// TestEveryDocsPageURLAnAgentReceivesIsMarkdown renders the managed block for
// every project shape under BOTH `{{ if .ElementsSDK }}` arms — the whole block,
// not only `### Docs`, so `### Before you submit` is covered too — plus the
// `--track api` refusal, and requires every docs-host address to be `.md` (or
// `/llms.txt`).
func TestEveryDocsPageURLAnAgentReceivesIsMarkdown(t *testing.T) {
type surface struct{ name, text string }
var surfaces []surface
for _, sdk := range []bool{false, true} {
for _, shape := range allProjectShapesForTest() {
shape.ElementsSDK = sdk
block, err := agentsManagedBlock(shape)
if err != nil {
t.Fatalf("rendering kind %q (ElementsSDK=%t): %v", shape.Kind, sdk, err)
}
surfaces = append(surfaces, surface{
name: "managed block, kind " + string(shape.Kind) + map[bool]string{false: " (blocks-react)", true: " (@civitai/sdk)"}[sdk],
text: block,
})
}
}
surfaces = append(surfaces, surface{"`agent-setup --track api` refusal", agentSetupTrackAPIRefusal().Error()})

for _, s := range surfaces {
checked, bad := htmlRouteDocsURLs(s.text)
// Positive control per surface: a surface that yields no docs address
// at all is a surface this guard says nothing about.
if checked == 0 {
t.Errorf("CONTROL failure, not a finding: %s carries no %s address — either it lost its docs "+
"links or the extractor stopped matching", s.name, docsHost)
continue
}
for _, u := range bad {
t.Errorf("%s links the HTML route %s. An agent reads this; link the `.md` rendering instead "+
"(curl it first: 200, `text/markdown`, body not starting `<!DOCTYPE`) and update the pins "+
"(wantDocsSection, TestAgentSetupTrackAPIRefuses).", s.name, u)
}
}
}
4 changes: 2 additions & 2 deletions internal/cmd/agent_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,8 +593,8 @@ func TestAgentSetupTrackAPIRefuses(t *testing.T) {
for _, want := range []string{
"https://mcp.civitai.com/mcp",
"https://orchestration.civitai.com/mcp",
"https://developer.civitai.com/site/",
"https://developer.civitai.com/orchestration/",
"https://developer.civitai.com/site.md",
"https://developer.civitai.com/orchestration.md",
"coming",
} {
if !strings.Contains(msg, want) {
Expand Down
15 changes: 9 additions & 6 deletions internal/cmd/templates/agents-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ docs site, and the `.md` suffix serves the plain-text source an agent can read
directly:

- Reference (manifest, scopes, message bridge, CLI):
https://developer.civitai.com/apps/reference/
https://developer.civitai.com/apps/reference.md
- Capabilities include generation body kinds (a multi-step workflow is a
`kind`); the kinds are listed at
https://developer.civitai.com/apps/reference/generation.md
Expand All @@ -37,15 +37,14 @@ the manifest fields and the scopes are documented on the docs site, and the

- **`https://developer.civitai.com/apps/reference/hooks.md`** — the COMPLETE
hook reference. Fetch it first: a hook you cannot find here probably exists
under a name you have not guessed. It is over 100 KB, so page it rather than
giving up on it.
under a name you have not guessed.
- Capabilities are hooks AND generation body kinds (a multi-step workflow is a
`kind`, not a hook); the kinds are listed at
https://developer.civitai.com/apps/reference/generation.md
- Reference (manifest, scopes, hooks, message bridge, CLI):
https://developer.civitai.com/apps/reference/
https://developer.civitai.com/apps/reference.md
{{- end }}
- Guide: https://developer.civitai.com/apps/guide/
- Guide: https://developer.civitai.com/apps/guide.md
- **`https://developer.civitai.com/apps/guide/earning.md`** — the three money
rails. Fetch it before declaring a `goods` catalog. The three rules below are
repeated in this file deliberately, because they are the ones a manifest can
Expand All @@ -54,8 +53,12 @@ the manifest fields and the scopes are documented on the docs site, and the
most one** unlock per manifest, and MUST carry a `justification`. All three are
enforced at submit; the published JSON Schema does not declare them.
- Example apps you can read end-to-end:
https://developer.civitai.com/apps/examples
https://developer.civitai.com/apps/examples.md
- Full doc index for agents: https://developer.civitai.com/llms.txt
- Some reference pages are long enough that a fetch tool cuts them off without
saying so. If what you need is not in what came back, it was probably
truncated, not missing: download the whole page and search it, or, if the
page links to a narrower page for that part, fetch that one.
{{- if not .ElementsSDK }}

Reading `node_modules/@civitai/blocks-react/dist/*.d.ts` to find out what the
Expand Down
Loading