Repository navigation
docs(agents): keep AGENTS.md chains inside Codex's 32 KiB budget #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7f072bb
8d63871
8dc6b1d
07e0e44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // @effect-diagnostics nodeBuiltinImport:off -- This test reads the repository's agent docs from disk. | ||
| import { existsSync, globSync, statSync } from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| const repoRoot = path.resolve(import.meta.dirname, "../../.."); | ||
|
|
||
| const projectDocMaxBytes = 32 * 1024; | ||
|
|
||
| const ignoredDirs = new Set([ | ||
| ".agent_sources", | ||
| ".git", | ||
| "node_modules", | ||
| "vendor", | ||
| ]); | ||
|
|
||
| const agentsDocs = globSync("**/AGENTS.md", { cwd: repoRoot }).filter( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include instruction files inside maintained dot-directories. In Node 24.18.0, Use directory traversal that includes dot-directories and prunes
|
||
| (doc) => !doc.split("/").some((part) => ignoredDirs.has(part)) | ||
| ); | ||
|
|
||
| const chainDirectories = (doc: string) => { | ||
| const dir = path.posix.dirname(doc); | ||
| const parts = dir === "." ? [] : dir.split("/"); | ||
|
|
||
| return [".", ...parts.map((_, index) => parts.slice(0, index + 1).join("/"))]; | ||
| }; | ||
|
|
||
| const chainBytes = (doc: string) => { | ||
| let total = 0; | ||
|
|
||
| for (const dir of chainDirectories(doc)) { | ||
| const candidate = | ||
| dir === "." ? "AGENTS.md" : path.posix.join(dir, "AGENTS.md"); | ||
|
|
||
| const file = path.join(repoRoot, candidate); | ||
|
|
||
| if (existsSync(file)) { | ||
| total += statSync(file).size; | ||
| } | ||
| } | ||
|
|
||
| return total; | ||
| }; | ||
|
|
||
| describe("AGENTS.md byte budget", () => { | ||
| it("keeps every root-to-leaf chain inside Codex's default project_doc_max_bytes", () => { | ||
| const overBudget = agentsDocs | ||
| .map((doc) => ({ bytes: chainBytes(doc), doc })) | ||
| .filter(({ bytes }) => bytes > projectDocMaxBytes); | ||
|
|
||
| const report = overBudget | ||
| .map(({ bytes, doc }) => `${doc} chain totals ${bytes} bytes`) | ||
| .join("; "); | ||
|
|
||
| expect( | ||
| overBudget, | ||
| `AGENTS.md chain exceeds ${projectDocMaxBytes} bytes. Codex reads at most project_doc_max_bytes across the AGENTS.md files from repo root to the working directory, so the tail sections never load. Fix: move task-conditional material behind a pointer like skills/rat-stack-mode/references/packages.md. ${report}` | ||
| ).toEqual([]); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Package roles | ||
|
|
||
| The package map in [AGENTS.md](/AGENTS.md#packages) names each workspace and its job. This reference keeps the full role note per workspace: boundaries, seams, removal steps, and extras. | ||
|
|
||
| - **`@rat-stack/catalog`** (`packages/catalog`): Private monitoring Domain model. `Item` owns observations and Keep/Drop decisions per canonical URL. Its event log is authoritative; `ItemHistory` is a rebuildable summary with cursor-paged event history. `CatalogIndex` writes replay-idempotent `stream:seq` rows through `CatalogStore`; native `Rising` and `RepeatAuthors` Queries read that derived index with bounded windows and keyset pages. The memory store runs in stories. The domain package imports only `@alchemy.run/domain` and `effect`; tests also use the test harness. | ||
| - **`@rat-stack/catalog-server`** (`apps/catalog`): Cloudflare Worker hosting Catalog on Domain Durable Objects, with operator bearer-token middleware, the D1 catalog index and its migrations. Worker props explicitly bind a configured `CATALOG_OPERATOR_TOKEN` as a redacted secret; missing or empty configuration denies every Api call. The `smoke <url>` script tests unauthenticated and authenticated reads through the native Api client without printing credentials. `apps/infra` registers the Worker and Domain providers. No catalog contents reach the public site. | ||
| - **`@rat-stack/capability`** (`packages/capability`): `defineContract`, `implement`, and the `toCommand`, `toHttpApi`, `toToolkit`, `toRpc`, `toCodeMode`, and browser-safe `toWebMcp` projections | ||
| - **`@rat-stack/core`** (`packages/core`): Shared `inspectFile`, `search`, and `read` contracts; `inspectFile` handler, lifecycle machine, and `FileInspector` | ||
| - **`@rat-stack/database`** (`packages/database`): Database cartridge: the `RunLog` service and the `DatabaseVendor` choice (D1 or Hyperdrive Postgres), with each vendor's schema, migrations, and resources | ||
| - **`@rat-stack/auth`** (`packages/auth`): Better Auth cartridge over the chosen `DatabaseVendor`: `Auth`, `CurrentPerson`, and the RPC middleware that provides it; only `Unauthenticated` crosses the wire. `@rat-stack/auth/devtools` adds `runAsPerson`, the dev-only `rat_test_person` capability, and `testPersonLayer` | ||
| - **`@rat-stack/flags`** (`packages/flags`): Typed flags cartridge: scoped evidence ladders, Config and memory adapters, cartridge-owned Alchemy KV, and a default Durable Object ledger. The DO commits values, receipts, and projection markers together; alarms project to KV. Readers never call the DO. Empty KV uses Config or declared defaults; read failures follow the catalog's `failurePolicy`. `EVENTS_ENABLED` stays deploy-time Config. Core owns declarations and the `flip_feature_flag`, `record_flag_evidence`, and `read_flag_ledger` contracts. Climbs use capability approval; `off` bypasses approval but stays audited. Only the CLI mounts operator capabilities; its default composition has no live ledger. Public readers and the sandbox stay read-only. Replace both exports in `apps/site/src/flags.ts` with `Flags.defaults(eventFlags)` to remove the adapter package. | ||
| - **`@rat-stack/events`** (`packages/events`): Events cartridge: capture-first request analytics. `withEventCapture` records one `request` event per HTTP request into core's `EventSink` port and owns visitor ids, the visitor salt, identity modes, and query and geography redaction. `src/basin.ts` provides the Basin-backed sink and salt; `src/memory.ts` is the in-memory sink for tests. `@rat-stack/events/site` is the one seam: `apps/site/src/events.ts` is the only file outside the package that imports it, and `rat-stack-boundaries/no-cross-layer-imports` enforces that. Removal is one line in that file plus deleting the package and its `apps/site/package.json` line; `packages/events/README.md` has the steps. Core owns the `EventSink` port (no-op default), the `RawEvent` wire schemas, `@rat-stack/core/events-off`. Tests are property and model based (`it.prop`, `it.effect.prop`). `EVENTS_ENABLED` (default false) turns capture and the catalog, sink, and pipeline on, and reads `EVENTS_SINK_TOKEN` at deploy time only; off still declares the bucket, stream, and salt so their state survives. `EVENTS_IDENTITY_MODE` picks `daily` or `persistent` visitor ids | ||
| - **`@rat-stack/turbo-cache`** (`packages/turbo-cache`): Thin project declaration of `alchemy-turbo-cache` `0.1.0`, pinned to Git commit `b38115bee650aceb6e7dd1eb503209a4d32a5381`. The external package owns the binary-protocol Worker, lifecycle-expiring R2 bucket, team-scoped writer and opt-in reader credentials and read-only state-to-stdin handoff. Its Git `prepare` builds exports during installation, authorized by the package-specific `allowBuilds` entry. Rat-stack supplies prefix `TurboCache`, team and reader `rat-stack`, seven-day retention and prod-only resource retention. The Stack includes it with `yield* turboCache`. The local seam test preserves the exact four resource FQNs and both credential handoffs, including reader PUT refusal; the README records trust limits and removal steps. | ||
| - **`@rat-stack/crash`** (`packages/crash`): Private crash-trace archive: trace schemas, `captureCrashes`, and the R2 archive layer (`@rat-stack/crash/r2`). Mischief's tail consumer provides it in `apps/site/src/crash-tail.ts` | ||
| - **`@rat-stack/subscriber-delivery`** (`packages/subscriber-delivery`): External subscriber intake and confirmation adapter; implements core's job-shaped `SubscriberIntake` and `SubscriberConfirm` ports, provided by the Worker, never imported by core | ||
| - **`@rat-stack/learn`** (`packages/learn`): Source-derived public concept deck and the learning lifecycle. Stateless capabilities return compact progress; `@rat-stack/learn/local` owns the local JSONL adapter and capabilities. The CLI provides the filesystem platform for core's `LearnerProgress` port. | ||
| - **`@rat-stack/og`** (`packages/og`): Build-only social cards. Renders 1200×630 PNGs with bundled fonts and emoji. The site export and Foldkit prerender builds check cards and HTML metadata against their published routes. Workers serve generated assets and never import the package. | ||
| - **`@rat-stack/motion`** (`packages/motion`): Motion for Foldkit apps. The `src/*.pure.ts` core (Penner and CSS easings, tweens, fixed-step springs, number, tuple, OKLab colour and 2D transform interpolation) imports nothing, so consumers can vendor it. `@rat-stack/motion/foldkit` adds the Model schemas, the `Motion.Message` union, `advance`, and subscriptions for animation frames and `prefers-reduced-motion`; Foldkit and Effect are optional peers. No Worker graph imports it | ||
| - **`@rat-stack/lore`** (`packages/lore`): Public content graph and traversal service | ||
| - **`@rat-stack/devtools`** (`packages/devtools`): 🐀 devtools cartridge: `CallLog`, `record`, and the `rat_*` capabilities that list, read, dispatch, replay, and diff capability calls | ||
| - **`@rat-stack/web`** (`apps/web`): Default UI bin: Foldkit on Vite, deployed through Alchemy's `Cloudflare.Website.Foldkit` as `Website` (`apps/web/src/website.ts`). Server rendering and prerendering are the default: one `foldkit({ ssr: { serverEntry, clientEntry, build: { prerender } } })` call in `vite.config.ts` builds the client bundle, the server fetch handler, and an HTML file for every path in `src/entry.server.ts`'s `prerenderPaths`. The Website serves those files, sends every other request to the handler, and the browser hydrates. System page: `.brain/areas/web.svx`. Browser `client/` Commands call an Effect `RpcClient` built from the contracts' `toRpcGroup`. The reader program mounts the document browser (`features/app.ts`, `client/docs`) as a Submodel at `/search`, where it calls `search` and `read` over that client. In production, the Worker that `@foldkit/vite-plugin` generates from `src/entry.server.ts` forwards `/rpc` through `src/server/website-bindings.ts` to the private `RpcBackend` in `apps/site/src/rpc-worker.ts`. `pnpm --filter @rat-stack/web dev` loads the `#backend` import, which resolves only under the `development` condition in `apps/web/package.json`, and serves the content capabilities in process from `src/dev/backend.ts`. In dev, `src/dev/backend.ts` runs the content capabilities under devtools: `/rpc` calls are recorded, `/__rat/rpc` serves the 🐀 overlay (`#devtools-overlay`, `src/dev/features/overlay`, ⌘K), and `/__rat/mcp` serves every `rat_*` tool to agents, with memory-Auth test people. `src/dev/client` and `src/dev/features` follow the browser rules. `test/production-bundle.test.ts` proves no `src/dev` module, no devtools code, and no test people reach a production build. Include it in the Stack with `const website = yield* Website;` | ||
| - **`@rat-stack/cli`** (`apps/cli`): Composition root: `stats`, `catalog`, `openapi`, `serve [--devtools]`, `mcp [--code-mode] [--devtools]` commands. Also builds the published `ratstack` npm package: `src/ratstack.ts` bundles the local learn commands and a learn-only `mcp` into `dist/npm` with Vite. `test/ratstack.e2e.test.ts` proves the package holds no devtools and serves only the learn tools | ||
| - **`@rat-stack/infra`** (`apps/infra`): Alchemy Stack: the project's cloud footprint as one Effect program | ||
| - **`@rat-stack/site`** (`apps/site`): Cloudflare Worker: the public site, agent discovery, and sandboxed execute surface. Startup report: `scripts/startup-report.ts` measures Alchemy's actual upload for each Worker. It follows static imports from each entry, counts shared chunks once and excludes dynamic-only chunks. It logs entry, static startup and total upload bytes, the change since the last run, and the share of Cloudflare's real limit (64 MiB uncompressed per Worker; startup must finish within 1 second). Size never fails the build. It warns past half of Cloudflare's limit. The behaviour checks still fail: no auth code in the public Worker, no build-only modules, Workshop isolation, and lazy learning code. Growing page data stays in static assets outside the startup code. Measurement and profiling: `apps/site/STARTUP.md`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Describe the motion clock, tween, and spring as Model state.
The
@rat-stack/motionpackage defines no clock, tween, or spring Messages. ItsMessageunion contains onlyTickedFrameandChangedReducedMotion. The clock, tween, and spring values are fields of theMotionstate, which the demo stores in its Model throughMotion.motionSchema. The demo's own Messages areClickedTarget,ClickedReplayCurves, andGotMotionMessage, andGotMotionMessagewraps the package'sTickedFrameandChangedReducedMotion.Restore the Model wording on that row so developers look for this state in the Model, not in Message categories.