agentleFS
CloudflareKnown publishercloudflare/polystella/AGENTS.md

polystella

AGENTS.md16 starsChanged 5 months agoMITView on GitHub

PolyStella — an Astro integration that translates content into additional locales at build time using AI, caches translations in Cloudflare R2, and injects locale-prefixed routes. This file is the entry point for coding agents working on the PolyStella package itself. Four companion docs: - PACKAGE_ARCHITECTURE.md — post-migration package ownership, dependency direction, key files, and boundary checks. - ARCHITECTURE.md — system design, invariants, glossary, per-subsystem reference. The "why" answers. - skills/polystella-contributor/SKILL.md — step-by-step recipes for common contributor tasks (add an adapter,…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository4 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

8 rules. About 1 is common, 1 is distinctive, and 6 are very specific to this project.

  • ≈1

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    All cross-references use stable slug anchors (#cache-key), not section numbers.

    line 22
  2. Distinctive:

    No lint step yet.

    line 38
  3. Very specific:

    If your task isn't on this list, the answer is in packages/astro/src/<area>/ matching one of the subsystem sections in ARCHITECTURE.md.

    line 66
  4. Very specific:

    Run pnpm test before pushing.

    line 99
  5. Very specific:

    Add a Changesets entry for every change that affects the published package, its documented behaviour, or release-facing contributor …

    line 100
  6. Common:

    Commit R2 credentials or live API keys to fixtures.

    line 129
  7. Very specific:

    Use any. Use unknown and narrow with type guards.

    line 133
  8. Very specific:

    Use ! non-null assertions outside test code.

    line 134

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

PolyStella — an Astro integration that translates content into additional locales at build time using AI, caches translations in Cloudflare R2, and injects locale-prefixed routes.

This file is the entry point for coding agents working on the PolyStella package itself. Four companion docs:

  • PACKAGE_ARCHITECTURE.md — post-migration package ownership, dependency direction, key files, and boundary checks.
  • ARCHITECTURE.md — system design, invariants, glossary, per-subsystem reference. The "why" answers.
  • skills/polystella-contributor/SKILL.md — step-by-step recipes for common contributor tasks (add an adapter, add a CLI subcommand, debug a translation, etc.).
  • skills/polystella-consumer/SKILL.md — for agents working in a downstream Astro project that depends on this package.

All cross-references use stable slug anchors (#cache-key), not section numbers. Inserting new sections never breaks links.


Commands

CommandWhat it does
pnpm testRun all package, Astro, workerd, and boundary tests.
pnpm test:watchRun the Astro package tests in watch mode.
pnpm buildBuild all four public packages. Astro and EmDash emit standalone CLI entries.
pnpm typecheckBuild all four packages, then typecheck every public package against its package-local tsconfig.json.
pnpm check:packagesPack all four public packages and exercise every export from a clean temporary consumer.
pnpm changesetAdd a Changesets entry for package-affecting work. Use pnpm changeset add --empty only for changes that intentionally do not need a package release.

No lint step yet.

Test counts age. The authoritative count is pnpm test's output; the number here is a snapshot pinned by packages/astro/tests/docs.test.ts.


Where do I make changes?

Task → entry-point file(s) → key contract → deep-dive link.

TaskEntry pointContractSee
Add a file-format adapterpackages/core/src/adapters/<name>.ts; wrap/register in packages/astro/src/parsing/FileAdapter in packages/core/src/adapters/adapter.ts#adapter-contract; recipe in contributor SKILL
Add a shared catalog CLI subcommandHandler in packages/core/src/cli/<name>.ts; register in packages/core/src/cli/run-command.tsArgv parser + run<Name>(args, deps)Recipe in contributor SKILL
Add a translation providerFactory in packages/core/src/providers/; map config in packages/astro/src/translation/provider.tsTranslator in packages/core/src/translator.ts#translator-contract; recipe in contributor SKILL
Change cache key formulapackages/astro/src/storage/hash.tsInvariant 1 — cache-wide invalidation#cache-key
Edit translation batchingpackages/core/src/{batch,translate-segments}.tsInvariant 2 — flat(groups) === segments#translation-batching
Modify cache/storage behaviourpackages/astro/src/storage/{cache,r2,prune,local-cache,report}.tsApply-before-PUT (Invariant 3); index isolation (Invariant 4)#cache-write-order, #local-staging-index
Modify runtime APIs (entry/collection/href/middleware)packages/astro/src/runtime/*Bridge timing (Invariant 5); per-locale closures#runtime-bridge
Modify routing shimspackages/astro/src/routing/{shim,expand-routes,walk-pages}.tsStale shims nuked per build; CSS via routesImports#routing-shims
Edit UI-string handlingpackages/core/src/catalog/translate.ts, packages/core/src/cli/{drift,sync,translate-ui}.tsThree drift modes; layout-aware writer; {{token}} preservation#ui-strings
Edit catalog-only adoptionpackages/core/src/catalog/index.ts, packages/astro/src/catalog/*Pure imports; middleware binds only t + lhref#ui-strings; consumer SKILL
Modify the EmDash pluginpackages/emdash/src/*Provider/locale/model bounds stay server-owned; collection policy is administrator-owned; Git catalogs stay canonical#package-boundaries
Edit content-collection wiringpackages/astro/src/content/*Sibling collections; custom-loader wrapper; bridge timing#runtime-bridge
Debug a translation that's wrongStart: pnpm translate --dry-run to inspect planned R2 keys; LOG_LEVEL=debug for batch detail—Recipe in contributor SKILL
Tune cold-cache build performancer2.bulkListOnStart, concurrency, batchInputTokenBudget knobs—#bulk-prelist, #translation-batching

If your task isn't on this list, the answer is in packages/astro/src/<area>/ matching one of the subsystem sections in ARCHITECTURE.md.

The root is private. Reusable package code uses standard Web APIs and must work without nodejs_compat, although consumers may enable it. Import low-level contracts from core, formats from the @cloudflare/polystella-core/adapters subpath, and transports from the @cloudflare/polystella-core/providers subpaths; do not add compatibility shims to the Astro package.


Invariants

Hard contracts. Don't violate without thinking carefully — link back to the explanatory section when adding code that touches one.

  1. Cache key formula — sha256(body + selectedFrontmatterValues + glossaryHash + modelId + optionalExtractionPolicyHash). Changing any input is a cache-wide invalidation. → #cache-key
  2. Group flattening — flat(adapter.groupSegments(...)) === segments (reference-equal, order-preserved). Asserted at runtime. → #translation-batching
  3. Apply before PUT — applyTranslations produces the exact bytes PUT to R2; markers woven inside apply, never after. → #cache-write-order
  4. Local cache index write isolation — workers write to nextLocalCacheIndex only; read only from localCacheIndex. → #local-staging-index
  5. Bridge timing — translation runs in astro:config:setup, NOT build:start. → #hook-timing
  6. URL-rewrite idempotence — both layers safe to apply twice. → #url-rewriting
  7. Path separators — R2 keys use /, local paths use path.sep.
  8. Permanent vs retriable provider errors — only PermanentProviderError short-circuits the retry loop. → #translator-contract
  9. Strict tsconfig — no any, no ! outside tests; use unknown + type guards; declare callable-undefined optionals as foo?: T | undefined.

Boundaries

Always

  • Run pnpm test before pushing. Tests must stay green.
  • Add a Changesets entry for every change that affects the published package, its documented behaviour, or release-facing contributor guidance. Use pnpm changeset for release notes; use pnpm changeset add --empty only when the change deliberately does not require a package release (for example, docs-site-only or CI-only maintenance).
  • Let Changesets version core and EmDash independently while keeping Astro and its compatibility package in one fixed group; do not manually bump individual manifests. POLYSTELLA_VERSION in packages/astro/src/version.ts reads the Astro manifest at module-load time and flows to packages/astro/dist/version.js after pnpm build. → #version-constant
  • Mirror filesystem path semantics across OS: forward slashes for R2 keys, path.sep for local I/O.
  • Forward signal: AbortSignal when adding a new async function on the hot path; signal?.throwIfAborted() at await boundaries that could otherwise run indefinitely. → #abortsignal

Ask first

  • Adding a new runtime dependency.
  • Adding a new adapter (introduces a new file extension).
  • Widening the permanent-provider-error set (HTTP status → PermanentProviderError).

Never

  • Re-introduce long-form design comments that were removed; they live in ARCHITECTURE.md now. In-code comments stay tight ("why" only).
  • Commit R2 credentials or live API keys to fixtures.
  • Widen the AI-translation marker contract without bumping the cache key formula. Cache hits return the marker verbatim, so an existing cache must remain interpretable.
  • Use any. Use unknown and narrow with type guards.
  • Use ! non-null assertions outside test code.

Footguns by severity

Tiered so you can scan the ones that matter for your change.

Will break production data or correctness

  • Cache-key formula stability (#cache-key). Any change is a cache-wide invalidation; coordinate via changelog.
  • Apply-before-PUT (#cache-write-order). The marker MUST be woven inside apply. Doing it after the PUT lets cache hits return marker-less bytes.
  • Bridge timing (#hook-timing). Moving translation to build:start makes sibling collections see empty staging dirs at content-sync time.
  • Workers AI default maxTokens is too low (#translator-contract). Default in our schema is 8192. Lowering it truncates multi-segment translations into invalid JSON.
  • {{token}} validation runs outside translateBatch (#ui-strings). The orchestrator's retry wrapper sets maxRetries: 0 on translateBatch so the retry loop is single-layer. Don't add a second retry layer.

Will produce confusing failures

  • Override files at i18n/overrides/{locale}/<path> win over AI output verbatim. They run through the URL rewriter (idempotent) but are NOT written to R2. Cache key changes don't affect overrides.
  • MDX vs MD — .mdx uses MDX syntax rules (imports/exports, JSX, expressions); .md stays plain Markdown. Route by extension; never apply MDX rules to .md.
  • Drift check fails on empty placeholders (#ui-strings). pnpm i18n:sync alone leaves the tree non-shippable until pnpm i18n:translate (or a hand-edit) fills the placeholders. Intentionally-blank labels are supported via matching "" in the source dict.
  • UI-string sync writer is layout-aware (#ui-strings). Running prettier --write on a synced file collapses the blank-line section breaks. The pre-commit hook only runs prettier --check, so it doesn't trip — but a manual pnpm format will churn diffs.
  • translate-ui pre-scans, then runs queued locales in parallel (#ui-strings). Complete locale JSONs are skipped before provider setup. Queued locales are capped at 3 concurrent workers; each locale is internally split into small sequential request batches. Workers MUST catch every error internally and record it on the per-locale outcome — never re-throw. Re-throwing kills the rest of the run.
  • adapter.parse is called once per source per live run (#dry-run-vs-live). Adapter parse should still be idempotent — calling it twice during debugging or in tests must not produce different output.

Performance tuning, not correctness

  • R2 bulk pre-list (#bulk-prelist). Disable via r2.bulkListOnStart: false for caches with >10k keys per locale.
  • Vitest singleThread: true is faster than multi-worker at current scale (~1.5s vs ~1.6s; per-worker startup dominates). Revisit when the suite outgrows the overhead.
  • Heartbeat setInterval is unref()'d (#heartbeat) so a stalled pool doesn't block process exit. Don't remove the unref.

Verification

Before pushing:

  • pnpm test must pass.
  • pnpm typecheck must pass (strict mode).
  • pnpm check:packages must pass for packaging or export changes.
  • For changes to the translation pipeline, run end-to-end against a real consumer's fixtures: polystella translate --dry-run walks the full pipeline without hitting AI/R2.
  • For changes to UI-string sync / translate: polystella check-ui (read-only), polystella sync-ui --check (read-only), polystella translate-ui --sync-only (offline, mutates JSONs).

Resources

  • ARCHITECTURE.md — system design and rationale.
  • README.md — user-facing introduction.
  • skills/polystella-contributor/SKILL.md — recipes for contributor tasks.
  • skills/polystella-consumer/SKILL.md — for agents in downstream consumer repos.
  • llms.txt — index for retrieval-time discovery.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.