agentleFS
MongoDBKnown publishermongodb/js-bson/AGENTS.md

js-bson

AGENTS.md1.2k starsChanged 4 months agoApache-2.0View on GitHub

Instructions for AI coding agents working in this repository. This file is the source of truth; tool-specific files (e.g. CLAUDE.md) should only import it. bson is the BSON codec library for JavaScript (Node.js and browser), implementing the BSON specification. It provides BSON type classes, serialization/deserialization to and from BSON bytes, and Extended JSON (EJSON) support. It is the codec used by the node-mongodb-native driver, and also a standalone library external users depend on. All benchmark runs first measure a CPU…

Trending

Quiet since October.about the whole repository

Jan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 1 mentionJul 2026: 2 mentionsAug 2026: 3 mentionsSep 2026: 6 mentionsOct 2026: 2 mentionsNov 2026: 0 mentionsDec 2026: 0 mentions
Jan 2026Jul 2026Dec 2026
Mentions a month of the mongodb/js-bson repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about mongodb/js-bson

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

See all 23

Talked about on GitHub (23 times).

On GitHub · 23

18 more on GitHub
  • 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,736 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 repositoryOne other file it gives its agents.

The file

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

4 rules. About 0 are common, 0 are distinctive, and 4 are 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.

  • 4

    Very specific

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

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

    Run a single test file: npx mocha test/node/<file>.test.ts.

    line 20
  2. Very specific:

    All benchmark runs first measure a CPU baseline (check:baseline-bench) so results are normalized across machines.

    line 25
  3. Very specific:

    Use these to validate perf-tagged changes — run before and after on the same machine and compare.

    line 33
  4. Very specific:

    Before making key changes to anything within src/parser/*, consider performance implications and run benchmark test passes to ensure no …

    line 58

≈ “Common” is an estimate: at least 1 in 5 of the 16,597 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

Instructions for AI coding agents working in this repository. This file is the source of truth; tool-specific files (e.g. CLAUDE.md) should only import it.

Project Overview

bson is the BSON codec library for JavaScript (Node.js and browser), implementing the BSON specification. It provides BSON type classes, serialization/deserialization to and from BSON bytes, and Extended JSON (EJSON) support. It is the codec used by the node-mongodb-native driver, and also a standalone library external users depend on.

Commands

npm run build          # tsc + api-extractor (bson.d.ts) + rollup bundles into lib/
npm run check:lint     # eslint + api-extractor + tsd type tests
npm run format         # attempts to automatically fix lint errors
npm run check:node     # mocha test/node (Node target). Run `build` first
npm run check:web      # same suite with WEB=true (browser code paths)
npm test               # builds (pretest), then check:node + check:web
  • Run a single test file: npx mocha test/node/<file>.test.ts; filter cases with --grep.
  • Tests use mocha + chai + sinon. Type-level tests live in test/types (tsd).

Benchmarks

All benchmark runs first measure a CPU baseline (check:baseline-bench) so results are normalized across machines. Sources live in test/bench/.

npm run check:granular-bench   # per-BSON-type micro-benchmarks (test/bench/granular)
npm run check:spec-bench       # cross-driver spec benchmark suite (test/bench/spec)
npm run check:custom-bench     # ad-hoc/scenario benchmarks (test/bench/custom)

Use these to validate perf-tagged changes — run before and after on the same machine and compare.

Structure

  • src/index.ts — the public API surface. api-extractor rolls it into bson.d.ts.
  • src/*.ts — BSON type classes (ObjectId, Long, Decimal128, Binary, …), all extending BSONValue; extended_json.ts for EJSON.
  • src/parser/ — the eager codec: recursive serializer/deserializer that converts whole JS objects to/from BSON bytes in one pass, plus size calculation used to pre-allocate output buffers.
  • src/parser/on_demand — the lazy path: scans a BSON buffer into document metadata without materializing JS values, so they can be independently decoded.
  • src/utils/ — shared helpers (byte utils, number parsing, platform detection).
  • test/node/ — main test suite; bson_corpus* tests run the cross-driver BSON corpus spec.

Code Conventions

  • Public API stability — Everything exported from src/index.ts lands in the published bson.d.ts. Renaming, removing, or narrowing exported types/signatures is a breaking change; confirm with a maintainer first.
  • No export default — all exports named. No TypeScript enums — use as const objects or string unions.
  • No Buffer in src/ — use Uint8Array. Code must run in browsers.
  • No node: import prefix in src/. Tests may use it.
  • Null checks — loose equality (== null), not === null/=== undefined.
  • Type imports — inline: import { type Foo }.
  • Errors — throw BSONError or its subclasses (BSONRuntimeError, BSONOffsetError, …) from src/error.ts; messages in sentence case, no trailing period.
  • Formatting — Prettier: single quotes, 2-space indent, 100-char width, no trailing commas.

Other Important Information

  • Changes must be compliant with bson spec, and should conform to specification tests for bson (e.g: bson-corpus).
  • Before making key changes to anything within src/parser/*, consider performance implications and run benchmark test passes to ensure no significant performance degradation.

Commit Messages

Conventional Commits optionally with a Jira ticket: <type>(NODE-XXXX): <subject> — types: feat, fix, docs, style, refactor, perf, test, chore; breaking changes use ! (e.g. feat(NODE-XXXX)!: …). This rule is mandatory for PR descriptions, because that is what ends up in the history. The individual commits inside a PR do not have to follow this convention, because we squash PR commits.

Further Reading

  • CONTRIBUTING.md — contributor workflow
  • docs/ — upgrade guides (v4, v5)

Related Repositories

MongoDB-maintained repos with a direct dependency relationship to bson. Changes here ripple into these; check them when altering public API or serialization behavior.

RepoRelationshipUsed inWhy it matters
node-mongodb-nativeimports bsonsourceThe Node.js driver; primary consumer. Every public API and wire-format behavior change surfaces there.
mongodb-client-encryptionimports bsonsourceCSFLE/QE bindings; serializes/deserializes BSON when talking to libmongocrypt.
mongoshimports bsonsourceThe MongoDB shell; exposes BSON type classes (ObjectId, Long, …) directly to end users.
compassimports bsonsourceCompass GUI; consumes via the compass:exports condition in package.json.
specificationsconsumed by bsontestsSource of the bson-corpus spec tests run by test/node/bson_corpus*. Behavior changes must stay conformant.

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.