AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
84/100
Scores the file, not the repository.Length
3,242 words
31 headings · 13 code blocksRepository
36k
— · pushed 0 days agoLast changed
2 days ago
First indexed 2 days ago.1# Agent Guide to pnpm Repository23This document provides context and instructions for AI agents working on the pnpm codebase.45The repository contains three products:67- The **TypeScript pnpm CLI** — the main TypeScript workspaces outside `pnpm/` and `pnpr/`.8- The **Rust pacquet port** — `pnpm/`. See [`pnpm/AGENTS.md`](./pnpm/AGENTS.md) for pacquet-specific rules; it adds to (and never contradicts) the conventions below.9- The **Rust pnpr registry server** — `pnpr/`. See [`pnpr/AGENTS.md`](./pnpr/AGENTS.md) for pnpr-specific rules; it adds to (and never contradicts) the conventions below.1011Sections below marked "(TypeScript only)" apply to TypeScript code only; they do not apply to Rust code in `pnpm/` or `pnpr/`. Everything else applies repo-wide unless a nested `AGENTS.md` specializes it.1213## Keep pnpm and pacquet in sync1415The two stacks are parallel implementations of the same CLI, kept behaviorally identical — the same flags, defaults, error codes, file formats, and lockfile shape. They are now at near-complete feature parity and are developed together, so **any user-visible change has to land in both at the same time.** Neither stack is downstream of the other: pacquet is a source of truth in its own right, not a port that trails the TypeScript CLI.1617When you change one side, do the equivalent change on the other in the same PR if you can. If you can't (different expertise, scope too large, or pacquet hasn't ported the surrounding feature yet), open the PR with just your side — call out in the description what still needs porting, and someone else will push the matching commits to the same PR before it lands.1819"User-visible" means anything that affects the CLI surface or the on-disk contract: command-line flags and defaults, environment-variable handling, lockfile/manifest/state-file format, error codes and messages, log emissions parsed by `@pnpm/cli.default-reporter`, store layout, hook semantics. Pure internal refactors, perf wins, and TS-only test cleanups don't need mirroring.2021**Any user-visible change to either stack must be replicated in the other.**2223The pacquet-side conventions for keeping the two stacks aligned are in [`pnpm/AGENTS.md`](./pnpm/AGENTS.md#the-cardinal-rule).2425## Repository Structure2627The pnpm codebase is a monorepo managed by pnpm itself. The root contains functional directories organized by domain:2829### Core Directories3031- `pnpm/`: The CLI entry point and main package.32- `pkg-manager/`: Core package management logic (installation, linking, etc.).33- `resolving/`: Dependency resolution logic (resolvers for npm, tarballs, git, etc.).34- `fetching/`: Package fetching logic.35- `store/`: Store management logic (content-addressable storage).36- `lockfile/`: Lockfile handling, parsing, and utilities.3738### CLI & Configuration3940- `cli/`: CLI command implementations and infrastructure.41- `config/`: Configuration management and parsing.42- `hooks/`: pnpm hooks (readPackage, etc.).43- `completion/`: Shell completion support.4445### Other Functional Directories4647- `network/`: Network-related utilities (proxy, fetch, auth).48- `workspace/`: Workspace-related utilities.49- `exec/`: Execution-related commands (run, exec, dlx).50- `env/`: Node.js environment management.51- `cache/`: Cache-related commands and utilities.52- `patching/`: Package patching functionality.53- `reviewing/`: License and dependency review tools.54- `releasing/`: Release and publishing utilities.5556### Shared Utilities5758- `packages/`: Shared utility packages (constants, error handling, logger, types, etc.).59- `fs/`: Filesystem utilities.60- `crypto/`: Cryptographic utilities.61- `text/`: Text processing utilities.6263### Rust Projects6465- `pnpm/`: The pnpm CLI ported to Rust. Self-contained sub-project with its own crates, tests, and tooling — see [`pnpm/AGENTS.md`](./pnpm/AGENTS.md).66- `pnpr/`: The pnpm-compatible npm registry server. Self-contained sub-project with its own crates, tests, and tooling — see [`pnpr/AGENTS.md`](./pnpr/AGENTS.md).6768## Setup & Build (TypeScript only)6970To set up the environment and build the project:7172```bash73pnpm install74pnpm run compile75```7677To compile a specific package:7879```bash80pnpm --filter <package_name> run compile81```8283**Important:** The pnpm CLI e2e tests (in `pnpm/test/`) use the **bundled** `pnpm/dist/pnpm.mjs`, not the individual package `lib/` outputs. After changing any package, you must rebuild the bundle before running e2e tests:8485```bash86pnpm --filter pnpm run compile87```8889This runs `tsgo --build`, linting, and `pnpm run bundle` (which bundles all packages into `pnpm/dist/pnpm.mjs`). Without this step, e2e tests will use a stale bundle and your changes won't be tested.9091## Testing (TypeScript only)9293Never run all tests in the repository as it takes a lot of time.9495Run tests for a specific project instead:9697```bash98# From the project directory99pnpm test100101# From the root, filtering by package name102pnpm --filter <package_name> test103```104105Or better yet, run tests for a specific file:106107```bash108pnpm --filter <package_name> test <file_path>109```110111Or a specific test case in a specific file:112113```bash114pnpm --filter <package_name> test <file_path> -t <test_name_pattern>115```116117## Linting (TypeScript only)118119To run all linting checks:120121```bash122pnpm run lint123```124125## Never ignore test failures126127Do not dismiss a failing test as a "pre-existing" failure that is unrelated to your changes. Every test failure must be investigated and fixed. If a test was already broken before your changes, fix it as part of your work — do not silently skip it or treat it as acceptable.128129## AI Review Guidance130131The repository's review framework lives in **[REVIEW_GUIDE.md](./REVIEW_GUIDE.md)** — how changes are accepted or rejected, the security-first / performance-second priorities, the security checklist and advisory regression themes, and the test/changeset/parity expectations. Apply it when reviewing pull requests. (TypeScript-specific code style and engineering conventions for the CLI are documented in the "Code Style" section of this file; pacquet and pnpr follow their own `AGENTS.md` and style guides.)132133Security is the first review priority and performance the second. Surface only issues tied to the changed code, and explain the exploit path, impact, or hot path affected. See the guide's Security and Performance review sections for the full checklist.134135## Code Reuse and Avoiding Duplication136137**Before writing new code, always analyze the existing codebase for similar functionality.** This is a large monorepo with many shared utilities — duplication is a real risk.138139- **Search before you write.** Before implementing any non-trivial logic, search the codebase for existing functions, utilities, or patterns that do the same or similar thing. Check `packages/`, `fs/`, `crypto/`, `text/`, and other shared directories first.140- **Extract shared code.** If you find that the logic you need already exists in another package but is not exported or reusable, refactor it into a shared package rather than duplicating it. If you are adding new code that is similar to code that already exists elsewhere in the repo, move the common parts into a shared package that both locations can use.141- **Prefer open source packages over custom implementations.** Do not reimplement functionality that is already available as a well-maintained open source package. Use established libraries for common tasks (e.g., path manipulation, string utilities, data structures, schema validation). Only write custom code when no suitable package exists or when the existing packages are too heavy or unmaintained.142- **Keep the dependency on the right level.** When adding a new open source dependency, add it to the most specific package that needs it, not to the root or to a shared package unless multiple packages depend on it.143144## Commit Messages145146Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification.147148- `feat`: a new feature149- `fix`: a bug fix150- `docs`: documentation only changes151- `style`: formatting, missing semi-colons, etc.152- `refactor`: code change that neither fixes a bug nor adds a feature153- `perf`: a code change that improves performance154- `test`: adding missing tests155- `chore`: changes to build process or auxiliary tools156157### Install the git hooks before committing158159The git hooks in `.husky/` (including the `commit-msg` check described below) only run once husky has wired them into git. A fresh clone does **not** have them active until installed. **Before making any commit, ensure the hooks are installed** by running one of:160161```bash162pnpm install # runs the "prepare": "husky" script as part of install163# or, if dependencies are already installed, register the hooks on their own:164pnpm exec husky165```166167You can confirm the hooks are active with `git config core.hooksPath` (it should point at husky's directory) and by checking that `.husky/_/` exists. Do not commit with hooks uninstalled — that silently skips every check, including the bare `#NNN` rejection below.168169### Never use bare `#NNN` issue/PR references170171**Do not write a bare `#NNN` (a `#` followed by digits) anywhere in a commit message.** A `commit-msg` hook (`.husky/reject-bare-issue-refs.mjs`) rejects them.172173GitHub turns any `#NNN` into a link to issue/PR `NNN` of *this* repo, which is almost never what a bare reference means. This is a frequent AI mistake in two forms:174175- Using `#1`, `#2`, `#3`, … to enumerate items in a list. GitHub instead links them to unrelated issues `#1`, `#2`, `#3` of this repo. **Fix:** don't use `#` for enumeration — write `item 1`, `(1)`, `1.`, or rephrase.176- Referring to issue `#NNN` of a *different* repository. GitHub instead links it to issue `NNN` of this repo. **Fix:** use qualified syntax `owner/repo#NNN` or an absolute URL `https://github.com/owner/repo/issues/NNN`.177178For references to issues/PRs in **this** repo, also use the qualified form `pnpm/pnpm#NNN` or the absolute URL `https://github.com/pnpm/pnpm/issues/NNN`. Qualified syntax and absolute URLs are always unambiguous, so this rule is applied to every `#NNN` without exception.179180**Address the root cause when the hook fires.** Rewrite the reference into the correct unambiguous form. Never bypass the check with `git commit --no-verify`, by editing or deleting the hook, or with any suppression file.181182### Never use a bare `@mention`183184**Do not write a bare `@name` (an `@` followed by a username-like token) anywhere in a commit message.** A `commit-msg` hook (`.husky/reject-bare-mentions.mjs`) rejects them.185186GitHub turns any `@name` into a mention of that user/org/team, which is wrong either way it is meant:187188- If it is code (a scoped package like `@pnpm/core`, a handle, a path), GitHub should not treat it as a mention.189- If it really is a person, every push, force-push, and rebase that carries the commit re-notifies them — noise nobody asked for.190191**Fix:** wrap the reference in backticks so GitHub renders it as code and sends no notification — e.g. `` `@pnpm/core` `` or `` `@foo` `` — or remove it if it is not needed. Never bypass the check with `git commit --no-verify`, by editing or deleting the hook, or with any suppression file.192193## Changesets194195If your changes affect published packages, you MUST create a changeset file in the `.changeset` directory (`pnpm change` records one interactively; `pnpm change status` shows the pending release plan). The file describes the change and specifies the affected packages with their pending version bump types: patch, minor, or major. Write the description for pnpm users and keep it concise — it becomes a release note. Implementation rationale belongs in the commit message, not the changeset. The bare `pnpm version -r` consumes the pending changesets at release time; there is no separate `@changesets/cli` dependency.196197**IMPORTANT: Always explicitly include `"pnpm"` in the changeset** with the appropriate version bump (patch, minor, or major). The pnpm CLI will only receive automatic patch bumps from its dependencies, so if your change warrants a minor or major version bump for the CLI, you must specify it explicitly. The changeset description will appear on the release notes page.198199Example:200201```202---203"@pnpm/installing.deps-installer": minor204"pnpm": minor205---206207Added a new setting `blockExoticSubdeps` that prevents the resolution of exotic protocols in transitive dependencies [#10352](https://github.com/pnpm/pnpm/issues/10352).208```209210**Versioning Guidelines for pnpm CLI:**211- **patch**: Bug fixes, internal refactors, and changes that don't require documentation updates212- **minor**: New features, settings, or commands that should be documented (anything users should know about)213- **major**: Breaking changes214215### Changesets for the Rust products216217The Rust products are released through the same native flow. Their npm wrapper packages are workspace packages with committed versions, so a user-visible change to a Rust product needs a changeset too, targeting:218219- `pacquet` — the Rust pnpm CLI (published to npm as `pnpm` and `@pnpm/exe` under its `next-<major>` dist-tag; named `pacquet` in-repo so its name can't collide with the TypeScript CLI). `@pnpm/napi` is a `versioning.fixed` group with it and bumps with it automatically.220- `@pnpm/napi` — the Node.js addon bindings for the Rust engine.221- `@pnpm/pnpr` — the pnpr registry server (published as `@pnpm/pnpr` and its platform packages, plus the `ghcr.io/pnpm/pnpr` Docker image).222223The Rust products release on `alpha` lanes (`versioning.lanes` in `pnpm-workspace.yaml`): each run of `pnpm version -r` that consumes an intent for one of them cuts an `X.Y.Z-alpha.N` prerelease, while the TypeScript CLI keeps releasing stable versions on the main lane. `pnpm lane main --filter …` graduates a product to a stable version.224225Do not add `"pnpm"` to a Rust-only changeset: in changesets, `pnpm` always means the TypeScript CLI package. A changeset whose implementation is Rust-only and targets `pacquet` must omit `"pnpm"`. A parity change that lands in both stacks carries one changeset naming both the affected TypeScript packages (plus `"pnpm"`) and the Rust wrapper(s).226227Use `pacquet` as the changeset package name, but use `pnpm` in its release-note prose and command examples (`pnpm add`, not `pacquet add`). The published Rust CLI's executable is `pnpm`; `pacquet` is only its in-repo package identifier.228229## Comments230231These conventions apply to the TypeScript pnpm CLI, pacquet, and pnpr. Product-specific `AGENTS.md` files may add language-specific rules, but they do not weaken this baseline.232233Write code that explains itself. A reader should understand what a function does from its name, parameters, and types — not from prose above the call site.234235Defaults:236237- **Do not write a comment** that restates what the code already says. If renaming a variable, splitting a helper, or moving a check to a more obvious place would carry the information, do that instead.238- **Do not repeat documentation** at call sites that already lives on the callee. If the function has JSDoc, a Rust doc comment, or equivalent API documentation, the call site shouldn't re-explain what calling it does. Update the documentation once; let every call site benefit.239- **Put a shared *why* in one place.** When the same rationale underlies several related functions — peers that delegate to a common helper, or a type and its methods — document it once at that common home and reference it from the rest, instead of re-deriving it in each. This is the call-site rule applied sideways across peers, not just upward to a callee.240- **Documentation comments are for the item's contract** — preconditions, postconditions, edge cases, why the item exists. Not for re-narrating the body.241- **Do not record past implementation shape, refactor history, or "the previous code did X" framing.** That's what `git log` and `git blame` are for. Describe the current contract — what the code is and what it guarantees — not what it replaced. Phrasings like "used to", "previously", "the original X", or a parenthetical naming a removed type belong in the commit message, not in the source.242243Write a comment only when:244245- The reason for the code is non-obvious from reading it (a hidden invariant, a workaround for a known bug, a deliberate exception to the surrounding pattern).246- The right name doesn't fit — e.g., a temporary technical constraint that's worth flagging but doesn't justify a new symbol.247248Before adding a comment, ask: "Could I rename, restructure, or extract instead?" If yes, do that. The bar for prose-in-code is high; the bar for prose-that-restates-code is "don't."249250## Code Style (TypeScript only)251252This repository uses [Standard Style](https://github.com/standard/standard) with a few modifications:253- **Trailing commas** are used.254- **Functions are preferred** over classes.255- **Functions are declared after they are used** (hoisting is relied upon).256- **Functions should have no more than two or three arguments.** If a function needs more parameters, use a single options object instead.257- **Import Order**:258 1. Standard libraries (e.g., `fs`, `path`).259 2. External dependencies (sorted alphabetically).260 3. Relative imports.261262To ensure your code adheres to the style guide, run:263264```bash265pnpm run lint266```267268### Conventions269270Recurring engineering conventions in this codebase — the rules reviewers most often enforce:271272- **Errors.** Throw `PnpmError` (from `@pnpm/error`) for user-reachable errors — they are part of the UX and carry a stable code. Programmer-error, type-guard, and unreachable-branch errors stay plain `Error`. Never swallow errors; catch only the specific expected code (not "any error" when you meant `ENOENT`). Throw on impossible states rather than continuing. Error messages must carry context, e.g. the offending path.273- **Naming.** Functions are verbs; types and fields are specific, not generic. Reuse existing terminology rather than inventing synonyms. File names follow the existing convention; rename a concept everywhere it appears.274- **Reuse repo libraries.** Don't add a dependency, or hand-roll logic, for a job an existing repo utility or an already-present library does — search for it first. Deduplicate copy-pasted logic into a shared function or package.275- **String parsing.** Prefer plain string operations over a custom regular expression. When the input needs structured parsing with backtracking, use the existing parser-combinator pattern (`object/property-path`).276- **Dependency placement.** Shared infrastructure (the logger, etc.) is a peer dependency. (The narrowest-package rule is covered under "Code Reuse and Avoiding Duplication" above.)277- **Config and layering.** Configurable values flow through `@pnpm/config` and reach commands via options — don't hardcode them (CLI options are camelCased automatically). Command handlers return data and let the CLI print it, which keeps them unit-testable. Don't add a wrapper function that adds nothing.278- **Async and loops.** Prefer async fs and `async/await`; run independent work with `Promise.all`/`Promise.any` and `await` what must complete; hoist invariant work out of loops.279280## Common Gotchas281282### Error Type Checking in Jest (TypeScript only)283284When checking if a caught error is an `Error` object, **do not use `instanceof Error`**. Jest runs tests in a VM context where `instanceof` checks can fail across realms.285286Instead, use `util.types.isNativeError()`:287288```typescript289import util from 'util'290291try {292 // ... some operation293} catch (err: unknown) {294 // ❌ Wrong - may fail in Jest295 if (err instanceof Error && 'code' in err && err.code === 'ENOENT') {296 return null297 }298299 // ✅ Correct - works across realms300 if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {301 return null302 }303 throw err304}305```306307## Working with GitHub PRs, Issues, and Comments308309- **Open every PR with the repository template.** `gh pr create` does not apply `.github/pull_request_template.md` automatically, so read that file and pass its filled-in contents as the PR body (`--body`/`--body-file`). Keep every section (Summary, Squash Commit Body, Checklist), fill them in for this change, mark the checklist items, and remove only the lines the template says are inapplicable.310- **Keep PR titles and descriptions current.** When pushing new changes to a PR, review the title and description and update them if they no longer accurately reflect what the PR does.311- **Reply to and resolve review conversations.** Once a review comment has been addressed, reply to the thread with a description of the resolution including the commit hash that fixed it, then mark the conversation as resolved.312- **Sign all agent-authored content.** When posting a comment, creating an issue, or opening a PR, append a footer to the message indicating that it was written by an agent. The footer must include the name of the agent and the name of the model used. Example:313314```markdown315 ---316 Written by an agent (Claude Code, claude-opus-4-7).317```318319## Resolving Conflicts in GitHub PRs320321Use `shell/resolve-pr-conflicts.sh` to resolve PR conflicts:322323```bash324./shell/resolve-pr-conflicts.sh <PR_NUMBER>325```326327The script force-fetches the base branch (avoiding stale refs), rebases, auto-resolves `pnpm-lock.yaml` conflicts via `pnpm install`, force-pushes, and verifies GitHub sees the PR as mergeable. For non-lockfile conflicts it will pause and list the files that need manual resolution.328329## Key Configuration Files330331- `pnpm-workspace.yaml`: Defines the workspace structure.332- `package.json` (root): Root scripts and devDependencies.333- `CONTRIBUTING.md`: Detailed contribution guidelines.334
Also in pnpm/pnpm
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| n8n-io/n8npackages/@n8n/agents/AGENTS.md · 199k | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| aaif-goose/gooseAGENTS.md · 52k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| wpscanteam/wpscanAGENTS.md · 9.7k | AGENTS.md | setupbuildteststyle+6 | 100/100 | 2 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago |
