agentleFS
oleg-vasilyevoleg-vasilyev/FoolProof/CLAUDE.md

FoolProof

CLAUDE.md2 starsChanged 52 days agoMITView on GitHub

This file is loaded before every session, so it holds only what has to be known before the first edit; anything for one job lives in a skill or beside the code. This file does not route jobs to skills. A skill is loaded because its own description: says when — a hand-kept table here drifted for weeks and cost a phase its sequencing. The roster and the order the jobs come in are DEVELOPMENT-FLOW.md, gated in both directions. Five…

  • Reads credentials

The file

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

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    It is the whole configuration for its run: No fallback to another. Node loads it and we do not parse it.

    line 372

≈ “Common” is an estimate: at least 1 in 5 of the 27,641 CLAUDE.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
CLAUDE.md

FoolProof — how the code here is written

This file is loaded before every session, so it holds only what has to be known before the first edit; anything for one job lives in a skill or beside the code.

This file does not route jobs to skills. A skill is loaded because its own description: says when — a hand-kept table here drifted for weeks and cost a phase its sequencing. The roster and the order the jobs come in are DEVELOPMENT-FLOW.md, gated in both directions.

Five documents, one job each:

  • README.md — what the bot is and how to run it, for someone arriving cold.
  • deploy/README.md — the operator's half: provisioning, the units, the deploy timer, the backup, and what to do when the bot is unwell; beside the units it describes.
  • PLAN.md — what the bot does and why: state machine, data model, invariants, edge cases, and the design dead ends already paid for.
  • CLAUDE.md — this file. Style, layering, testing, gates.
  • TECH-DEBT.md — what is deliberately unfinished, each entry with the trigger that would make it worth doing. It is a to-do list, so an entry is deleted when done rather than ticked.

The dividing question is would this still be true if the bot were rewritten in Python? If yes it belongs in PLAN.md — the Bot API's limits, the state machine, the schema. If no, it belongs here. A fact lives where its reason lives; the other file gets a pointer, never a retelling. When the two disagree, PLAN.md wins on behaviour and this file wins on style.

That rule has needed enforcing twice, so it is enforced: node scripts/gates/gate-runner.ts check-docs holds every document against the repository it describes — links, tables, the schema, the pictures, the flow drawing, every path a document names, and a line budget on this file, on TECH-DEBT.md, on every skill and on each page beside one. The budget makes appending cost something: a rule that pushes a file over displaces an older one into the file loaded when it applies, and write-a-doc routes a fact to its home.

Code style

Anything a machine can check is a lint rule, not a paragraph — see What enforces what. What is left needs judgement:

  • A file must read as a skeleton, not an implementation. Opening it shows the idea before any detail: the exported factory is a table of contents that names the steps and delegates, and the steps are module-level functions taking an explicit context object instead of reaching into closure scope. src/main.ts, src/feature-installer.ts and features/live-game/bot/card/card-service.ts are the reference shape. A function that needs a comment to explain its sections is asking to be split.
  • A file name has to survive being read on its own. An editor tab shows the basename without its folder, so card-state.ts, not state.ts; callback-data-codec.ts, not callback.ts. Repeating the folder is the cheap price of that — repository/repository-contract.ts reads worse in a path and better in a tab, and the tab wins. index.ts promises a re-export, so logic never goes in one.
  • A name says what is inside, not what the file is about. The test is cold: shown only the basename, guess the exports. evening.ts was specific and still failed it; session-appearances.ts predicts the Appearance type and the per-player helpers actually in it. A topic passes the rule above and fails this one, so both have to be asked.
  • The same thing is called the same thing in every feature. User copy is copy.en.ts, the entry point is <feature>-feature.ts, a stub for third-party code is named after that code (grammy-api.stub.ts). Two files named feature.ts in two folders are two tabs a reader cannot tell apart.
  • Dispatch on a union with switch, never a chain of if. Actions, phases and transition outcomes are closed unions: a switch makes the compiler check exhaustiveness, so adding a case becomes a compile error everywhere obliged to handle it. Keep if for guards and priority chains.
  • Prefer a discriminated union over a nullable plus a separate reason. A lookup that can fail returns { ok: true, … } | { ok: false, notice }, so the narrowing survives the call and the caller reads as one early return.
  • Keep functions pure where you can — a function works off its arguments, not module-level state, and never mutates them; return a new value. Wiring belongs in a composition root, not inside the logic.
  • Separate semantically distinct blocks with a single blank line so they do not visually merge.
  • No comments in src/ and scripts/ — naming carries the intent. A magic number still gets a named const, but the intent has to fit in the name (ABANDON_AFTER_MS, EDIT_DEBOUNCE_MS); if it genuinely cannot, the explanation belongs in PLAN.md. Config files (tsconfig.json, eslint.config.js) are exempt — a non-obvious compiler flag has nowhere else to live.
  • No console.* for app logging — take one from createLogger("scope") in #shared/logging/logger.ts. LOG_LEVEL (debug|info|warn|error, default info) sets the threshold; the three places raw console.* is still allowed are in the table below.

strict: true and no any. There is no build step: tsconfig.json mirrors how Node actually runs the code. erasableSyntaxOnly and verbatimModuleSyntax keep the source type-strippable (no enums, no namespaces, import type for types), and allowImportingTsExtensions matches the explicit .ts import paths.

Everything a user can read lives in a copy table

Code, identifiers, commits and docs are English. What the bot says is whichever language the chat picked, so every feature carries copy.en.ts, copy.ru.ts and a copy.ts whose copyIn(locale) switches between them. copy.en.ts declares the shape (export type Copy = typeof copy) and every other table is annotated with it, so a key missing from one language is a compile error.

No string literal a user can read may appear anywhere else — not in the state machine, not in a handler, not in an answerCallbackQuery call, and not as the separator a render/ file joins two of them with. Keep the table flat.

Copy is a parameter, never an import. A render/ or bot/ function that speaks takes copy: Copy first; only an entry point and its handlers resolve one, from the chat's language. A module-level import { copy } pins the bot to one language.

A copy function interpolates; it never decides. Choosing between 1 game and 2 партии is a render/ job — the table holds { one, few, many } and shared/locale/plural-rules.ts picks by the table's own locale. Specs leave copy tables real on purpose, so a decision made inside one is compared against itself and no test can catch it breaking; write-a-spec has the mutants that proved it, and check-docs fails the shape on sight.

The site's pages are held like copy. Each page pair has a language-neutral fact tree in docs/text/; a language's page is written from it by the site-writer agent, never from the other language's page, and check-docs holds both pages to the tree's blocks, order, numbers and commits. Why that replaced translation is finish-phase's.

Player names are user data, not copy. Matching normalises via Unicode NFC and lower case, plus ё → е, and the parser must not assume latin (shared/table/name-list.ts; live-game only strips the command off first).

Architecture

A feature is a folder you can delete. Removing features/scoresheet/ must leave the rest compiling and passing, and adding a feature must not require editing another one. Deleting one was tested by deleting it, twice: the only failures are in main.ts and main.spec.ts, the composition root and the one spec supposed to know the roster. Nothing in scripts/ may import a feature — the tooling asks what features offer through shared/drawings/drawings-contract.ts and finds them at run time, so a deleted folder simply stops being listed, and check-docs reports the pictures it left behind instead of failing to compile. The procedure for adding one is the add-a-feature skill.

The commands a feature declares are the list of its sub-features. scoresheet declares /stats, /stats_chronology, /stats_awards and /personal, so it gives the player three pictures; the commands live-game declares between them open a card and change the table. When a layer holds files serving more than one of those things, each gets a subfolder named after that thing — a picture, a screen, an entity the commands are about: render/chronology/, render/seating-screen/, bot/lineup/. Only what all of them use stays at the layer root. Never a bucket (helpers/, common/) and never a process; a single-command feature never subdivides. The add-a-feature skill has both traps and why check-docs fails a layer root above nine files.

A feature folder is named after what the player gets, not after an internal noun. diagnostics/ is the exception that proves the rule — its reader is whoever runs the bot, and what they get is a diagnosis.

src/
  supervisor.ts         starts main.ts again when it dies
  main.ts               names the features and wires them
  feature-installer.ts  registers whatever it was given
  features/
    live-game/          playing a game on a live card
    merge-names/        the /merge screen that makes two names one player
    replace-names/      the /replace screen that puts an evening under the right name
    scoresheet/         the pictures /stats and /personal send back
    diagnostics/        the /status report about the bot itself
    language/           the /language screen a chat picks its language on
  shared/
    config/             reading the environment, and where the project root is
    drawing/            turning one SVG string into pixels
    drawings/           what a feature offers to be drawn, and by which tool
    fonts/              the faces the posters are drawn in, and the refusal
    lifecycle/          draining the stops, restarting after a crash
    locale/             the language table, the plural rules, the chat's choice
    logging/            the scoped logger
    repository/         the connection, the contract, the SQL
    table/              how many may sit down, how a list of names is read, and how
                        a table is rotated so the same one always reads the same
    telegram/           context types, the feature contract, api retries and
                        what they cost, the client options pointing a run elsewhere,
                        the question a command asks when it came without its argument,
                        and the one such question a chat may have standing
    text/               HTML escaping
    timing/             the edit debouncer, the slowest render this run drew

Everything in shared/ lives in a folder named after its subject, including the ones holding a single module plus its spec. A platform/ or infra/ bucket would be the vagueness the file-name rules above refuse.

There are no relative imports in src/ — every specifier is a # alias, even for a sibling, so every import line reads the same way and a violation is visible in the line rather than in the folder you happen to be looking at. They are Node's own subpath imports, declared in package.json: the only aliasing that survives having no build step.

Layers live inside a feature

Each feature has the same three, and imports point only downward — bot may reach render and domain, render may reach domain, domain reaches nothing:

features/<name>/
  <name>-feature.ts   the entry point: builds the parts and declares the commands
  <name>-drawings.ts  what the tools may draw of it, and the tools it offers them
  copy.en.ts          every string this feature shows a user
  domain/             the pure core — no framework, no I/O, no rendering
  render/             state in, message text and SVG out; still pure
  samples/            the states it is worth drawing at, built for a human to judge
  bot/                the impure edge: grammY handlers, the debouncer, rasterizing

samples/ holds the sample evening and every edge the gallery draws. A sample is a state, not a picture, so it sits beside render/ under the same fence and never rasterizes, reads a file or talks to Telegram. It is not scaffolding and gets no exemption: it carries specs, and write-a-spec says what they must assert.

The entry point sits at the feature root, not inside a layer: it is the feature's composition root, the same job src/main.ts does one level up. There is no integrations/ layer — grammY is the Telegram client and is imported directly.

Purity and independence are lint rules, not aspirations: domain/, render/ and samples/ may not import grammy, node:* or the rasterizer, one feature may not import another, and scripts/ may import none of them. Specs and stubs sit beside their subject, so a feature carries its own tests out of the door with it.

The domain layer is a pure reducer

domain/ holds (state, action) => state and nothing else. No database access, no grammY, no Date.now(), no I/O of any kind — the clock and the storage are passed in. Every transition in PLAN.md must be exercisable without a Telegram token and without a database file. This is the rule that makes the product testable at all; it is worth defending against convenience.

Derive rather than store: CardState carries no phase field, phaseOf() computes it, and everything about a live card is rebuilt from game_players and game_events on every tap — which is what makes a restart mid-game a non-event. The /merge screen goes further and keeps its selection in callback_data, so it has no state to go stale at all.

render/ is the same shape one layer out: state in, message text and inline keyboard out, pure. A drawing is a string; only the edge may turn it into pixels — scoresheet/render/ produces SVG text and the native rasterizer lives alone in shared/drawing/rasterize.ts, beside the fonts it draws with, because the bot and the website's build both need it and neither may reach into the other's feature. shared/text/html-escape.ts and scoresheet/render/svg-tags.ts are each the only place their kind of markup is assembled, so a name cannot reach the output unescaped. Geometry belongs in card-metrics.ts and each poster's own *-layout.ts or *-metrics.ts beside it; a drawing file never computes a coordinate of its own.

One Bot API fact that is easy to get backwards, and PLAN.md explains why: escape user data reaching the message body, never button captions — Telegram does not parse HTML in captions, so escaping there renders &amp; literally.

A feature that cannot work refuses at construction, not on first use. The scoresheet calls requireFonts() as it is built, because a missing font makes resvg draw the picture with no text on it rather than fail. A copy of such a call owes the same refusal — the site's image writer took the render without the guard, and six blank posters passed every gate, the weight matching better. Import the guard.

Two things live in one place on purpose

  • Retrying. shared/telegram/api-retry.ts is installed once with bot.api.config.use(), so no feature ever writes a retry. A transformer sees every outgoing call, which nothing at a call site can. The decision of what to do with a failure is the pure planFor(); which calls may be retried is a PLAN.md question. Note the two shapes are not interchangeable: a network error throws, a refusal from Telegram resolves as { ok: false, error_code }.
  • Data access. Features never touch the database; they depend on shared/repository/repository-contract.ts and call named domain methods. sqlite-repository.ts is the only file allowed to contain SQL; the coercions (column-values.ts) and the row mappers (row-records.ts) stay out of it, because a file that imports the connection can only be tested against a real SQLite — and that split took the layer's mutation score from 90.48% to 98.51% in July 2026. Adding a query has a procedure: the add-repository-method skill.
import { repository } from "#shared/repository/repository-instance.ts";

const card = repository.liveCardInChat(chatId);

The lifecycle is split three ways so it can be tested

supervisor.ts resolves a path and hands it to shared/lifecycle/child-supervisor.ts; whether to restart is a pure function in restart-policy.ts. That is what makes a restart loop testable at all — the policy is exercised as arithmetic, the supervisor against a fake child process. What the restarts do is PLAN.md's What survives a failure.

shared/lifecycle/crash-exit.ts installs both handlers on purpose: main.ts ends in a top-level await bot.start(), so a rejection there arrives as uncaughtException, not unhandledRejection. Both log and exit non-zero; neither carries on, because the state is unknown by definition.

Tests

The write-a-spec skill has everything about writing one. Two facts shape the source tree, so they are here:

  • Specs sit next to the code as *.spec.ts, and so do the stubs — one for code we did not write (grammY's Api, a Context) sits beside its only consumer.
  • A spec mocks through a stub, never a hand-written fake — every feature entry point has one, and a shared/ module mocked without one earns it in the same edit.

e2e/ is a different world with its own rules — the write-an-e2e-scenario skill and e2e/README.md — and a gate, not an experiment. One obligation reaches back here: a keyboard whose buttons carry callback_data gets scenarios, because whether a tap reaches the feature owning it is a fact about real grammY.

Checks

This project is written by an agent, and the agent is the harness's only user. Every script, gate, hook and report is designed for it first: a result is a file it can open (reports/runs/, reports/tools/), never a stream it sees only the tail of; a red gate names its reasons and the one command that re-runs it; nothing waits on a terminal. A person's convenience is second and is never the reason a script exists — the owner said so on 9 September 2026, after a month of gates read through grep.

package.json keeps eight scripts — prepare, start, start:prod, e2e:watch and the four check* batteries — and every gate is a row in scripts/gates/shared/gate-list.ts that runs only through node scripts/gates/gate-runner.ts <gate>, in prose too, which check-docs holds. A gate's own knowledge, its config included, lives in that gate's folder, named by the runner and the hooks, so a bare eslint finds none; only what every gate needs sits at the root of scripts/gates/, and tsconfig.json at the repo's. README.md lists the scripts and the gates, by the rules in the write-a-doc skill.

What enforces what

A rule that can be checked mechanically is a lint rule, not a paragraph — prose is for judgement. eslint.config.js holds the checkable ones, several with no core equivalent:

RuleEnforced by
No comments in src/ and scripts/project/no-comments
An import belongs in the header, not further downproject/imports-first
Two blank lines after the last importproject/blank-lines-after-imports (autofixed)
A number must be named by a constproject/named-numbers
A \b beside a non-ASCII character never matches, so the pair is refusedproject/no-ascii-word-boundary
A state is read from its own table, specs includedproject/named-states
Only sqlite-repository.ts opens the databaseproject/one-door-to-the-database
A screen's way off and way on are drawn in one placeproject/one-control-row
Braces on every if, const over letcurly, prefer-const, no-var
console.* only in the logger, in scripts/ outside scripts/gates/, and in scripts/gates/shared/say.tsno-console
Imports point downward, features stay independent, e2e/ stays outsideno-restricted-imports, one zone per layer
An alias ban (#live-game/**) fires, and survives await import(…)a regex pattern, and the same bans as no-restricted-syntax

Nothing that refuses is finished until it has been seen refusing: a lint zone, a check-docs rule, a hook, a gate, a config a gate reads — break its subject on purpose, watch the red, then move to the next file; the break is chosen from the rule's own scope, because four probes in one phase hit nothing the rule watched and read as broken gates. The zones that never fired, and how to prove one, are the add-a-feature skill's.

A PostToolUse hook lints each file as it is written, so a violation surfaces at the edit instead of at the end of the turn; a PreToolUse hook refuses a shell command that runs a gate's tool by hand, so the runner is the only door for the agent too.

Finishing a phase

Any list of changes to this repository is a phase, feature or not — closing findings, refactoring, tooling. A phase is done when the code is releasable, not when it works, and what that costs is the finish-phase skill's gates, with their numbers in the commit message; three of them may not be run by whoever wrote the diff, which is why the flow drawing hands each to an agent of its own. A tag is cut only when a player or the operator gets something new; everything else rides the next one. Say how big the phase is before starting it, in a line, so it can be argued down; the list somebody hands you never contains the gates.

Configuration

One npm script starts the real bot, and the server's unit calls that script — so start:prod is production rather than a description of it, and the two cannot drift. It is also the only script that loads an env file: the server's, the only one that exists. .env.example is its template and must list every key the app reads. Read the environment in one place, shared/config/env.ts, and pass values down — no process.env in feature code. Two rules follow from one loaded file:

  • It is the whole configuration for its run. No fallback to another. Node loads it and we do not parse it; a hand-rolled reader once inherited a missing key from a second file instead of reporting it.
  • A key left empty counts as missing. requireEnv refuses it, optionalEnv falls back; .env.example has the outage that made it a rule.

What a run costs whoever operates it is in deploy/README.md.

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.