Skip to content

Phase 1: AI crawler tokens in robots.txt and a sitemap with real lastmod #285

Closed

Description

@neuromechanist

Replace the bare allow-all in src/pages/robots.txt.ts (production hosts only) with an explicit block that stacks every AI crawler token (GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, Claude-SearchBot, Claude-User, PerplexityBot, Google-Extended, Applebot, Applebot-Extended, meta-externalagent, CCBot) over one Allow rule, keep non-production hosts disallowed, and add a Sitemap line. Add sitemap.xml (@astrojs/sitemap with a customPages callback, since dataset routes are API-driven) whose per-dataset lastmod comes from the dataset's own last change (version, DOI, or metadata timestamp served by the API), never the build time. Never emit rel=canonical to openneuro.org; sameAs stays the only cross-repository link. Tests: robots output per host, sitemap contains every public dataset with a lastmod that matches the API field.

Part of #284. Constraint: descriptive only, no live contract changes. Evidence: nemarOrg/nemar-cli .context/research-agent-findability.md.

Activity

  1. added
    enhancement
    on Sep 3, 2026
  2. neuromechanist commented on Sep 3, 2026

    @neuromechanist
    ContributorAuthor

    Implementation brief (phase 1 of epic #284)

    Branch feature/issue-285-phase1-robots-sitemap, worktree /Users/yahya/Documents/git/nemar/phase1-robots-sitemap, PR targets the epic branch feature/issue-284-epic-agent-readiness.

    Scope

    Two surfaces, both host-aware, both backed by pure helpers in src/lib so they are unit-testable without a running server.

    src/lib/robots.ts (new, pure). Exports the ordered AI crawler token list and a robotsBody(hostname) builder. On a production host (isProductionHost) the body is a short human-readable comment header naming the data host and the CLI, then one block of stacked User-agent: lines for GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, Claude-SearchBot, Claude-User, PerplexityBot, Google-Extended, Applebot, Applebot-Extended, meta-externalagent and CCBot sharing a single Allow: /, then User-agent: * with Allow: /, then a Sitemap: line pointing at ${MARKETING_BASE_URL}/sitemap.xml. On every other host the body stays byte-identical to today's User-agent: *\nDisallow: /\n with no Sitemap line, so the staging and preview noindex policy is unchanged. src/pages/robots.txt.ts becomes a thin route over that builder.

    src/lib/sitemap.ts (new, pure). A sitemapLastmod(row) that turns the catalog row's updated_at (falling back to created_at) into a W3C datetime and returns null for anything that does not parse, an entry builder that keeps only rows that are status === "active", visibility === "public" and whose id matches /^(nm|on)\d{6}$/, and a buildSitemapXml(entries) that XML-escapes and emits <urlset>. Dataset URLs are ${MARKETING_BASE_URL}/dataset/<id>; a small fixed list of public marketing routes (/, /discover, /about, /support, /privacy, /terms) is included without a lastmod. App-host routes are never listed.

    src/pages/sitemap.xml.ts (new, SSR route). Pages the catalog through the existing listAllDatasets client, builds the XML, and responds application/xml; charset=utf-8 with public, max-age=300, s-maxage=3600, stale-while-revalidate=86400.

    Decisions already made, do not relitigate

    An SSR route, not @astrojs/sitemap. The plugin writes the document at build time, so every lastmod would freeze at the deploy that produced it. The issue's requirement is a lastmod tied to the dataset's own last change, and the routes are API-driven, so a build-time snapshot cannot satisfy it. This also adds no dependency.

    The id filter is nm/on only, because /dataset/ds<digits> 301-redirects to its canonical in [id].astro. A sitemap must not list a URL that redirects.

    A catalog fetch failure returns 503 with Cache-Control: no-store, never an empty <urlset>. An empty sitemap is a positive assertion that the site has no pages, and it would be cached.

    Absolute URLs come from MARKETING_BASE_URL, matching what canonicalOriginFor already resolves for these marketing routes. Nothing anywhere emits a canonical or any other link to openneuro.org.

    Tests

    src/lib/robots.test.ts and src/lib/sitemap.test.ts, vitest, pure inputs only. Cover: every token present exactly once and each on its own User-agent: line; the wildcard Allow: / still present on production; the exact non-production body; the Sitemap line present on production hosts and absent elsewhere; localhost keeps today's behaviour. For the sitemap, drive the entry builder with catalog rows shaped like the real API response (capture a fixture under test/fixtures/ from https://api.nemar.org/datasets?limit=... rather than inventing rows), and assert lastmod equals the row's own updated_at, that a private, non-active or ds-prefixed row is excluded, that & and < in a value are escaped, and that no output contains openneuro.org.

    If a route-level test is worth having, stub only globalThis.fetch the way src/lib/api.test.ts already does; never stub the builders themselves.

    Gates

    bun run lint, bun run typecheck, bun run test and NEMAR_SKIP_OG_GENERATE=1 bun run build all green before the PR. Descriptive only: no API response shape, Zarr contract, data.nemar.org layout or served field changes.

  3. neuromechanist commented on Sep 3, 2026

    @neuromechanist
    ContributorAuthor

    Shipped in #290, squash-merged into the epic branch feature/issue-284-epic-agent-readiness as 8be4174.

    Closing by hand: the PR merged into the epic branch rather than the default branch, so GitHub's closing keyword does not fire (the same gap AGENTS.md documents for every staging merge in this repo).

    robots.txt on production hosts now stacks GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, Claude-SearchBot, Claude-User, PerplexityBot, Google-Extended, Applebot, Applebot-Extended, meta-externalagent and CCBot over a single Allow: /, keeps the general User-agent: * allow, and points at /sitemap.xml. Non-production hosts keep a byte-identical User-agent: * / Disallow: /, so the staging and preview noindex policy is unchanged.

    The sitemap is a server-rendered route rather than @astrojs/sitemap, because the plugin writes its document at build time and every lastmod would freeze at the deploy that produced it. Per-dataset lastmod comes from the row's own updated_at, falling back to created_at, and is omitted rather than guessed when the value does not parse. Rows that are not active, not public, or not addressed by an nm/on id are excluded, so the sitemap never lists a URL that redirects.

    Verified against the live catalog on a dev server: 761 URLs (six static marketing routes plus all 755 public datasets), 755 <lastmod> values, valid XML per xmllint, and zero openneuro.org references. Spot-check: nm000281's lastmod is 2026-08-31T11:09:05.000Z against the API's own updated_at of 2026-08-31 11:09:05.

    Review found one moderate issue (the crawler-block test could not detect the rule group being split, because both halves carry the same Allow: / today) plus three smaller ones. All four were fixed and re-reviewed; the re-review reproduced the mutation and confirmed the strengthened assertions now fail on it. The sitemap route also gained an isNoindexHost gate so a stray probe on a staging or preview host no longer triggers a full catalog fan-out, while local dev still serves it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions