You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Phase 1: AI crawler tokens in robots.txt and a sitemap with real lastmod #285
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.
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.
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.
Activity
neuromechanist commentedon Sep 3, 2026
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 branchfeature/issue-284-epic-agent-readiness.Scope
Two surfaces, both host-aware, both backed by pure helpers in
src/libso they are unit-testable without a running server.src/lib/robots.ts(new, pure). Exports the ordered AI crawler token list and arobotsBody(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 stackedUser-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 singleAllow: /, thenUser-agent: *withAllow: /, then aSitemap:line pointing at${MARKETING_BASE_URL}/sitemap.xml. On every other host the body stays byte-identical to today'sUser-agent: *\nDisallow: /\nwith no Sitemap line, so the staging and preview noindex policy is unchanged.src/pages/robots.txt.tsbecomes a thin route over that builder.src/lib/sitemap.ts(new, pure). AsitemapLastmod(row)that turns the catalog row'supdated_at(falling back tocreated_at) into a W3C datetime and returns null for anything that does not parse, an entry builder that keeps only rows that arestatus === "active",visibility === "public"and whose id matches/^(nm|on)\d{6}$/, and abuildSitemapXml(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 existinglistAllDatasetsclient, builds the XML, and respondsapplication/xml; charset=utf-8withpublic, 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 everylastmodwould 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/ononly, 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 whatcanonicalOriginForalready resolves for these marketing routes. Nothing anywhere emits a canonical or any other link to openneuro.org.Tests
src/lib/robots.test.tsandsrc/lib/sitemap.test.ts, vitest, pure inputs only. Cover: every token present exactly once and each on its ownUser-agent:line; the wildcardAllow: /still present on production; the exact non-production body; the Sitemap line present on production hosts and absent elsewhere;localhostkeeps today's behaviour. For the sitemap, drive the entry builder with catalog rows shaped like the real API response (capture a fixture undertest/fixtures/fromhttps://api.nemar.org/datasets?limit=...rather than inventing rows), and assert lastmod equals the row's ownupdated_at, that a private, non-active ords-prefixed row is excluded, that&and<in a value are escaped, and that no output containsopenneuro.org.If a route-level test is worth having, stub only
globalThis.fetchthe waysrc/lib/api.test.tsalready does; never stub the builders themselves.Gates
bun run lint,bun run typecheck,bun run testandNEMAR_SKIP_OG_GENERATE=1 bun run buildall green before the PR. Descriptive only: no API response shape, Zarr contract, data.nemar.org layout or served field changes.neuromechanist commentedon Sep 3, 2026
Shipped in #290, squash-merged into the epic branch
feature/issue-284-epic-agent-readinessas8be4174.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
stagingmerge 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 generalUser-agent: *allow, and points at/sitemap.xml. Non-production hosts keep a byte-identicalUser-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 everylastmodwould freeze at the deploy that produced it. Per-datasetlastmodcomes from the row's ownupdated_at, falling back tocreated_at, and is omitted rather than guessed when the value does not parse. Rows that are not active, not public, or not addressed by annm/onid 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 perxmllint, and zeroopenneuro.orgreferences. Spot-check: nm000281'slastmodis2026-08-31T11:09:05.000Zagainst the API's ownupdated_atof2026-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 anisNoindexHostgate so a stray probe on a staging or preview host no longer triggers a full catalog fan-out, while local dev still serves it.