agentleFS
CloudflareKnown publishercloudflare/workerd/src/per_isolate/crypto/AGENTS.md

workerd / crypto

AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub

TypeScript reimplementations of crypto APIs that must be replaced when the typescript_implemented_streams compat flag is on. Parent directory conventions (primordials discipline, private-brand dispatch, no instanceof) apply — see src/per_isolate/AGENTS.md. DigestStream is one of only two WritableStream subclasses in the runtime. When the streams flag swaps globalThis.WritableStream for the TypeScript class, a C++ subclass of the C++ WritableStream no longer passes the brand checks used by pipeTo, and instanceof WritableStream becomes false. Reimplementing the subclass in TypeScript is what restores the…

Trending

Quiet since August.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 2 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the cloudflare/workerd repository that our weekly crawl found: only 12 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about cloudflare/workerd

The biggest 5 of 12 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 12

Talked about on GitHub, Bluesky and Hacker News (12 times).

On GitHub · 6

1 more on GitHub

On Hacker News · 2

The file

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

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When the streams flag swaps globalThis.WritableStream for the TypeScript class, a C++ subclass of the *C++* WritableStream no longer passes …

    line 11

≈ “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

src/per_isolate/crypto/

TypeScript reimplementations of crypto APIs that must be replaced when the typescript_implemented_streams compat flag is on. Parent directory conventions (primordials discipline, private-brand dispatch, no instanceof) apply — see src/per_isolate/AGENTS.md.

WHY THIS EXISTS

DigestStream is one of only two WritableStream subclasses in the runtime. When the streams flag swaps globalThis.WritableStream for the TypeScript class, a C++ subclass of the C++ WritableStream no longer passes the brand checks used by pipeTo, and instanceof WritableStream becomes false. Reimplementing the subclass in TypeScript is what restores the hierarchy.

The other subclass, FileSystemWritableFileStream, is fixed the same way in src/per_isolate/webfs/. Its construction runs the other direction — instances come from FileSystemFileHandle.createWritable() rather than a user-callable constructor — so that method is replaced on the prototype as well.

FILE MAP

FileRole
digest-stream.tsDigestStream — WritableStream subclass over a native digest

THE C++ CONTRACT

digest-stream.ts owns only the stream semantics. Hashing is done by a native DigestContextHandle (src/workerd/api/crypto/crypto.h), reached through utils.createDigestContext(name), which is registered in src/workerd/io/per-isolate-bootstrap.c++ via the deliberately crypto-free declaration in src/workerd/api/crypto/digest-bootstrap.h.

Two parts of that contract are easy to break:

  • update() takes strings, and returns a byte count. Strings are NOT encoded on the TypeScript side, because the default encoding is not expressible in JavaScript: a lone surrogate is hashed as WTF-8 (ED A0 80), and TextEncoder can only produce the U+FFFD substitution. The return value exists because a string's UTF-8 length is not observable from JavaScript.
  • The string encoding is fixed at context creation, by createDigestContext(name, toWellFormed). toWellFormed: true opts into the U+FFFD substitution; the default is WTF-8 and must stay that way for backwards compatibility. crypto-streams-test.js pins both directions for both implementations — stringChunksAreNotTextEncodedByDefault catches a changed default, toWellFormedMatchesTextEncoder catches an ignored option.
  • toWellFormed is a streaming encoder, so it is stateful. A surrogate pair can be split across two writes, so a lead surrogate ending a chunk is held back until the next chunk decides whether it pairs. Consequences for the contract: update() can return 0 for a non-empty chunk, and flush() must be called before digest() to account for a lead that was never paired (3 bytes, U+FFFD). digest() flushes internally too, so forgetting flush() costs an accurate bytesWritten, never a correct digest. The default WTF-8 encoding is stateless and joins nothing — that is the historical behavior, so the two encodings can disagree on bytesWritten across chunks (4 bytes for a joined pair vs 3+3 for two lone surrogates).
  • The option bag is coerced, not type-checked. JSG unwraps jsg::Optional<bool> with ToBoolean, so {toWellFormed: 'false'} opts in. The TypeScript side reproduces this with !!, and toWellFormedIsCoerced/toWellFormedDefaultsToFalse hold the two together.
  • Chunks are not copied. The digest consumes bytes synchronously inside update(), so a copy would be pure overhead — unlike webstreams/identity.ts, which copies because it enqueues. The consequence is that SharedArrayBuffer-backed views are read in place.

PARITY

Both implementations run crypto-streams-test.js unmodified, under crypto-streams-test.wd-test (C++) and crypto-streams-ts-test.wd-test (TypeScript). Behavior shared between them belongs in that file so drift fails one config or the other. TypeScript-only behavior — and the one intentional divergence below — belongs in ts-digest-stream-test.js.

ts-digest-stream-test.js's isRealWritableStreamSubclass is the canary that the main.ts install actually took effect; without it the rest of the suite would pass against the C++ implementation too.

INTENTIONAL DIVERGENCE

The digest promise is marked handled (utils.markPromiseHandled), so abandoning it produces no unhandled-rejection report. The C++ implementation does report in that case. This is accepted: consuming digest is optional, an abort is already surfaced through the writer's ready/closed promises, and marking does not propagate to derived promises — stream.digest.then(f) with no catch still reports.

ANTI-PATTERNS

  • NEVER encode string chunks here; forward them to update().
  • NEVER reference this in the sink closures passed to super() — they are evaluated before super() returns, while this is still in its temporal dead zone. Build the state object first and capture that.

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.