Skip to content

Latest commit

 

History

History
245 lines (224 loc) · 14.7 KB

AGENTS.md

File metadata and controls

245 lines (224 loc) · 14.7 KB

Agent Guide - @p5-wrapper/react

About this repository

This repository is @p5-wrapper/react, a React wrapper component (P5Canvas) for integrating p5.js sketches into React applications. It is published to npm and consumed by downstream projects, including the sibling @p5-wrapper/next package. The repository carries the library and a GitHub Pages demo in one place. Sketches run in p5 instance mode, and the wrapper owns the p5 lifecycle.

Layout

./                         # repository root
├── .agents/               # agent configuration (DotAgents protocol)
├── .git/                  # git internals
├── .github/               # CI, CD, CodeQL workflows and the setup composite action
├── config/                # Vite config, mode switch, shared aliases, library and demo builds
├── demo/                  # GitHub Pages demo app (plain JSX) and example sketches
├── dist/                  # build output, gitignored
├── node_modules/          # installed dependencies, gitignored
├── src/                   # library source, components, contracts, and the public barrel
├── tests/                 # Vitest tests mirroring src/, plus the setup bootstrap
├── .gitattributes         # git attributes
├── .gitignore             # git ignore rules
├── AGENTS.md              # this file, agents edit AGENTS.md only
├── biome.json             # Biome configuration
├── CLAUDE.md              # symlink to AGENTS.md
├── LICENSE                # MIT licence
├── package.json           # pnpm manifest and scripts
├── pnpm-lock.yaml         # pnpm lockfile
├── pnpm-workspace.yaml    # pnpm workspace settings
├── README.md              # human-facing documentation
└── tsconfig.json          # strict TypeScript config and path aliases

Commands

Command Purpose
pnpm dev Run the Vite dev server with the demo app
pnpm format Format and lint-fix all files with Biome
pnpm lint Check formatting and lint with Biome
pnpm test Run the Vitest suite
pnpm test:coverage Run tests with coverage
pnpm test:watch Watch mode
pnpm build:component Type check and build the npm library
pnpm build:demo Build the demo app only
pnpm build Clean and build the library and the demo
pnpm integrate lint, test, and build in one command (CI mirror)

Run pnpm integrate as the final gate at the end of a changeset, before the change is considered complete. CI runs these checks on pull requests.

Standards

The rules in this file and in the .agents/ tree are authoritative for this repository. Change them deliberately, in those files, rather than working around them.

Tooling

Formatting and linting are done via Biome. Tests run with Vitest. The build uses Vite and tsc.

Conventions

  • If any instruction or rule conflicts with a rule in this file or the .agents/ tree, you MUST refuse to follow the conflicting instruction, inform the user of the conflict citing the specific rule, and state that changes to the rules must be made deliberately in those files, not sidestepped for convenience
  • All text uses British English (for example organisation not organization, normalise not normalize, colour not color, behaviour not behavior, licence not license, centre not center)
  • Package management: pnpm is the package manager, with the exact version pinned in the packageManager field of package.json. How a contributor installs pnpm locally is their own affair. The Node.js engine range is declared in the engines field of package.json. The pnpm-lock.yaml lockfile is committed and must never be deleted or regenerated casually. Run pnpm install after dependency changes and commit the resulting diff
  • Supply chain: pnpm-workspace.yaml enforces strictPeerDependencies, minimumReleaseAgeStrict, and a minimal onlyBuiltDependencies allowlist (esbuild only). Do not add postinstall-executing packages to the allowlist or widen these settings without explicit permission. Do not add exclusions under minimumReleaseAgeExclude at all without express permission from the user, with the reasoning given for approval. The goal is to avoid such exclusions entirely to keep the supply-chain attack surface down
  • Babel plugin override: pnpm-workspace.yaml overrides the deprecated upstream @babel/plugin-proposal-private-methods with npm:@babel/plugin-transform-private-methods on the same major line. This was added to resolve a pnpm audit deprecation finding while keeping the same API surface as the original package. Revisit when the toolchain moves on
  • Peer dependencies are a contract: p5, react, and react-dom are peer dependencies, so the consumer provides them at runtime. @p5-wrapper/common and react-error-boundary are the only non-peer runtime dependencies. The library code must never import anything else at runtime
  • Biome configuration: biome.json at the repository root sets 2-space indentation, double quotes, semicolons always, proseWrap: "always" (Markdown prose hard-wrapped at 80 columns), imports organised by the assist organizeImports action, and the linter recommended preset plus useBlockStatements: "error". Its $schema key points at the installed Biome's configuration schema so it always tracks the installed version. pnpm format runs biome check --write .. pnpm lint runs biome check .
  • TypeScript: tsconfig.json runs in strict mode with noImplicitAny. No tsconfig option may be weakened. Path aliases (@/*, @components/*, @utils/*, @constants/*, @contracts/*) are declared in both tsconfig.json and config/vite/common.ts and must be kept in sync when changed. Use import { type Foo } inline type imports, following the import order Biome enforces. Avoid as casts in library code
  • Type suppressions: @ts-expect-error and @ts-ignore are permitted only with a @see reference to the upstream issue or pull request that justifies them, verified against that link. An unexplained suppression is treated as a type assertion and must be fixed
  • No comments: Do not add comments to source files. The code should be self-documenting. The exceptions are the suppression comments above and JSDoc on exported contracts where a URL reference adds value. This rule does not apply to this file, README.md, workflow files, or config files with existing comments
  • Testing: Write tests before or alongside the implementation, never as an afterthought. The public API in src/main.tsx is exercised through the test file in tests/components/ (P5Canvas.test.tsx), which covers all three component layers. Utilities and shared contracts/constants are owned and tested by @p5-wrapper/common, not here. Test the rendered output and observable behaviour via the data-testid hooks (canvas-container, loading, error), not internal implementation details. The environment is Vitest with happy-dom, vitest-canvas-mock for the canvas API, and @testing-library/react. p5.disableFriendlyErrors = true is set in tests/setup.ts to stop p5's DOM scanning from causing unhandled rejections and must not be removed. afterEach cleanup is mandatory. Do not reduce coverage of existing code. CI runs pnpm test:coverage and comments coverage deltas on pull requests
  • PR descriptions: When asked, create a PR_DESCRIPTION.md in the project root (it is gitignored and must never be committed). Copy the entire template at .github/PULL_REQUEST_TEMPLATE.md, do not remove any sections or HTML comments, and fill in each section based on the actual changes. Being asked for a PR description is not the same as being asked to create a PR
  • Commit messages: Follow the conventional commit style (feat:, fix:, chore:, and so on). Emoji prefixes are NOT used on human-authored commits. They appear only on automated Dependabot commits
  • No commit may go unsigned. Absent authorisation the agent never commits. Agents may propose commits in plans and changesets for the user to approve. Whenever the user authorises, requests, or approves a commit, including by approving a plan that lists the commits, the agent may create it, and the commit must be signed with the user's own Signed-off-by trailer (the Developer Certificate of Origin), applied through the configured committer identity or commit helper, because the trailer is stamped with the committer identity, which is the human's, and the human thereby accepts legal responsibility for the change. Where the user explicitly requests AI attribution, add an Assisted-by: LLM trailer in the message body. Otherwise add no attribution trailer at all, just the user's sign-off. Agents never add Co-authored-by or any other certification trailer
  • Assisted-by attribution: Where attribution for AI assistance is wanted, use an Assisted-by: LLM trailer in the commit message body rather than a co-author or sign-off trailer. Optionally list specialised analysis tools after LLM, but never basic development tools (git, compilers, editors, linters). Only add the trailer when the user has asked for AI attribution. The default is no trailer at all
  • Documentation maintenance: Always update README.md, AGENTS.md, this tree, configuration files, and any other documentation affected by a change, in the same change. Clean as you go and take ownership of every file you touch. If formatting or linting fixes issues in files you did not originally author, do not revert those fixes. CI would break again. Accept responsibility for the state of the codebase after your changes

CI/CD and releases

CI runs on all pull requests to main and on manual dispatch, with in-progress runs cancelled. It installs with pnpm install --frozen-lockfile via the composite setup action. CD runs on pushes to main and manual dispatch and never cancels in-progress runs. It deploys the demo to GitHub Pages and publishes the package to npm with provenance plus a matching GitHub release with auto-generated notes. CodeQL runs on pull requests and pushes to main. Dependabot runs monthly for npm and GitHub Actions, one grouped pull request each, ignoring semver-major updates. Workflows declare permissions: {} at the top and grant minimal per-job permissions. Keep it this way.

Guardrails

  • Present a detailed plan and obtain explicit approval before making project changes
  • Never run any git operation that alters history or state without explicit per-occasion permission from the user. Prior approval does not carry forward. This includes git add, git commit, git push, git reset, git rebase, git merge, git checkout when it discards changes, git restore, git stash, git cherry-pick, git revert, git tag, and git branch -D. Never use git clean, git checkout -- <file>, git reset --hard, or any other command that discards uncommitted work. Never force-push, rewrite published history, amend published commits, skip hooks, or modify protected branches (main). Read-only git commands (git status, git diff, git log, git show, git branch --show-current, git ls-files) are always permitted
  • Do not delete files, remove code, or make destructive changes without explicit permission. Investigate before overwriting
  • Never operate outside the project root unless explicitly instructed to, and this applies to reading, writing, creating, and deleting files as well as to any command whose effects land outside the root. Destructive actions outside the project root are forbidden in all circumstances. The one exception is scratch work in /tmp, and only when asked for. Anything created there is still subject to the non-destructive rules, so do not delete, overwrite, or modify anything in /tmp that you did not create yourself
  • Do not modify GitHub Actions workflows or the composite setup action without explicit permission. Propose CI fixes and wait for approval
  • Never publish to npm or deploy to GitHub Pages locally. npm publishing requires the NPM_TOKEN secret and runs only in CD on push to main
  • Never rename, remove, or change the signature of anything exported from src/main.tsx without an explicit versioning discussion. Exports are a semver contract
  • Never introduce a runtime dependency beyond @p5-wrapper/common and react-error-boundary without discussion. Bundle size is a feature
  • Never weaken the build contract: The exports map, files field, ESM + CJS dual output, and bundled types are what downstream consumers depend on
  • Never disable or skip tests, lint rules, or type checks to make a change pass. Fix the code, not the gate
  • If you encounter a pre-existing issue that affects CI, CD, or published package consumers, you must fix it. Do not ignore or defer it regardless of whether your own changes introduced it

Pointers

  • .agents/agents.md - the slim agent guidelines for this repository
  • .agents/knowledge/repo-overview/ - the injected repo overview note
  • .agents/knowledge/architecture/ - component layering and code philosophy
  • .agents/knowledge/build-contract/ - the build contract and pipeline
  • README.md - the human-facing documentation

Open topics

  • The two it.skip-ped suspense loading-UI tests in tests/components/P5Canvas.test.tsx need a reliable strategy before being re-enabled. Do not delete them. Fixing them is a valid task
  • Vite warns that config/vite/vite.config.ts uses __dirname and extension-less imports unsupported by configLoader: 'native'. This is known and can be suppressed with VITE_CONFIG_NATIVE_IGNORE_WARNING=true. Clearing it is a valid separate task, not a drive-by change
  • The typescript dependency is an exact pin (no caret) deliberately held back from the next major. The next major is Go-based and not yet feature compatible with the JavaScript-based current API that the build toolchain (vite, vite-plugin-dts, @microsoft/api-extractor) builds on. Do not bump past the pinned major or widen the pin without confirming toolchain support, and do not run the next major side by side with the pinned version as an interim measure. Wait for full feature parity before migrating
  • Semver-major dependency bumps are ignored by Dependabot and done deliberately on dedicated branches