Skip to content

Latest commit

 

History

History
181 lines (147 loc) · 12.2 KB

AGENTS.md

File metadata and controls

181 lines (147 loc) · 12.2 KB

Working in c2pa-js

Run the smallest relevant lint/test/build/typecheck targets. For shared types, utilities, or bindings, identify affected consumers from imports and call sites; test changed paths in each. Run pnpm ci:check for API or behavior changes spanning packages, or when consumer impact is unclear. Report exact checks and missing prerequisites; never claim skipped checks passed.

Read README.md, the development guide, CONTRIBUTING.md, and the relevant package README. This guide applies repository-wide. Follow package conventions; Node and browser bindings are not interchangeable.

Package workflow guides

Use the guide for the package involved: web or Node. When a change affects both, including shared utilities or generated types, read the relevant sections of both.

Task Web guide Node guide
Write applications, examples, or tests that use the SDK Part 1: Using the Package Part 1: Using the Package
Change public APIs or package behavior Part 1 and Part 2: Changing the Package Part 1 and Part 2: Changing the Package
Change Rust bindings WebAssembly Neon
Change tests, build tooling, or documentation Testing and Validation Testing and Validation
Prepare a change for review Done Checklist Done Checklist

These guides supplement this repository-wide entry point. Verify APIs against the package being changed instead of translating examples from another runtime or language's SDK.

Repository map

pnpm/Nx monorepo with a Rust workspace. Production packages use @contentauth/; workspace dependencies use workspace:*.

  • c2pa-web: browser TypeScript API over WASM and shared utilities. Public entry points: main, inline; The worker bridges browser API calls to WASM.
  • c2pa-node: Node API with a native Neon addon. TypeScript and tests: js-src/; Rust: src/; fixtures: tests/. Start at public exports and native registrations.
  • c2pa-wasm: Rust/wasm-bindgen adapters over c2pa-rs. Start at src/lib.rs; pkg/ is generated.
  • c2pa-types: generated TypeScript types; Rust schema sources in src/. build.ts recreates schemas/ and types/; index.ts is a hand-maintained export facade.
  • c2pa-utilities: shared Settings/Context and HTTP helpers; exports. Nx project: @contentauth/c2pa-utilities.
  • nx-wasm-bindgen: custom WASM build/test executors.
  • testbed: local browser app for inspecting manifests.
  • scripts/: API documentation tooling. api-docs/: generated documentation plus tracked version lists and selector assets.
  • docs/: contributor documentation; .github/: CI, releases, PR template.

Trace API changes through TypeScript and native/WASM implementations. Check package exports; use workspace imports, never another package's private source or build output. Nx targets come from scripts, project.json, and inferred TypeScript/Vite/Vitest/ESLint configuration. Confirm names and targets; directories do not always match project names:

pnpm exec nx show projects
pnpm exec nx show project c2pa-web
pnpm exec nx show project @contentauth/c2pa-utilities

Other library project names: c2pa-web, c2pa-node, c2pa-wasm, c2pa-types.

Setup and commands

Run from the repository root unless noted. Use pnpm exec nx; no global Nx required.

pnpm install --frozen-lockfile
  • Web tests: next, run pnpm exec playwright install from packages/c2pa-web, then return to the root. Vitest uses headless Chromium, Firefox, and WebKit.
  • WASM tests: wasm-pack with headless Chrome.
  • Node tests: build the local native addon; downloaded binaries do not test changed Rust.
  • Trustmark tests: download missing ONNX models; require network access or a populated writable cache. CI uses packages/c2pa-node/tmp/trustmark_models/.

Common commands; run only those relevant to your change:

pnpm exec nx build c2pa-web
pnpm exec nx lint c2pa-web
pnpm exec nx test c2pa-web
pnpm exec nx typecheck c2pa-web
pnpm exec nx test @contentauth/c2pa-utilities
pnpm exec nx test c2pa-node
pnpm exec nx test c2pa-wasm
pnpm ci:check
cargo +nightly fmt --all -- --check

Prefer Nx targets for dependency-build ordering. pnpm ci:check runs library lint/test/build; nightly Rust formatting is separate. See CI for environment details.

  • Manual browser testing: build c2pa-web, then pnpm exec nx serve testbed. See testbed README for HTTPS setup.

Coding and compatibility

General

  • Match surrounding naming, imports, layout, and error handling. When writing or changing code, format only as needed to fix actual formatting-rule or lint-rule violations. Preserve existing formatting in untouched code; avoid indentation/newline-only churn that adds review noise without fixing violations. Run checks first, then limit fixes to actual violations and the narrowest necessary scope. Do not indiscriminately run automatic formatter --write or lint --fix on entire files or the repository. If a tool necessarily rewrites a broader scope, retain only required or task-related formatting changes; avoid unrelated cleanup. Do not weaken formatting/lint requirements or suppress rules to avoid fixes.
  • Keep strict TypeScript, ESM exports, and .js relative imports. Prefer domain types and guards over any, unchecked casts, or non-null assertions.
  • Keep static imports organized together at the top of every JavaScript/TypeScript file, after the license header and before declarations or executable code. Follow existing import grouping/order and preserve side-effect import order.
  • Use applicable ESLint and Prettier: single quotes, no trailing commas. Preserve license headers; new JS/TS covered by root ESLint needs the adjacent Adobe header.
  • Use nightly rustfmt and rustfmt.toml import grouping. Respect crate editions and blank-line rules for multiline blocks.
  • Update both TypeScript/Rust sides and exported types when an API spans bindings.
  • Preserve validation, cleanup, and error contracts. Reuse conversion helpers; never hide failures with success defaults.
  • Update public API documentation with behavior changes. Preserve documentation style and @internal boundaries.

Shared utilities

  • Check utilities before adding Settings/Context, Reader/Builder validation, signer, or HTTP logic. Keep shared behavior aligned; document intentional differences and unavoidable duplicates.
  • Keep Node filesystem/native code out of browser/shared code.

Node

Web and WASM

  • Trace changed web APIs through main/inline entry points, worker messaging, and WASM. Update and test affected layers only.
  • Preserve WASM reader errors: JsString supports Firefox workers.

Generated files and dependencies

  • Edit sources/generators, not dist/, out-tsc/, target/, WASM pkg/, index.node, or generated API docs.
  • Regenerate types with pnpm exec nx build c2pa-types; rebuild affected consumers.
  • The WASM executor generates WASM_SRI. Rebuild through the pipeline; never change the binary or integrity value alone.
  • Never delete api-docs/ to clean output: preserve tracked version lists and selector assets.
  • Change appropriate manifests; update locks through pnpm/Cargo. Avoid unrelated upgrades. Shared c2pa dependency lives in root Cargo.toml.

Validation and pull requests

  • Add nearby regression tests using existing fixtures/mocks. Cover errors and cleanup; test bindings at runtime, not only through mocks. Node/utilities use colocated *.spec.ts in Node Vitest. Reuse web fixtures for initialization/disposal and MSW lifecycle.
  • Documentation tooling: pnpm test:docs. Versioned commands such as pnpm ci:docs:releases need network access and published npm declarations; they do not validate unreleased APIs. See documentation builds. Prose-only changes need no native/WASM builds.
  • Follow the contributor CLA and code of conduct. Discuss major API additions in an issue first.
  • Follow PR template: Overview, Changes, Testing, and applicable cross-package drift check. Explain compatibility effects and validation.
  • Create a changeset only when explicitly requested by the user. When requested, run pnpm changeset and include the generated file; do not create one automatically even if the change requires a package release. When writing a changeset for a pre-1.0 package, use a patch bump for additive, backward-compatible changes. Reserve minor bumps for breaking changes in the public API; do not create major bumps while the package is pre-1.0. Do not run release/versioning workflows in feature PRs.
  • Follow Conventional Commits for commit subjects and PR titles: <type>[optional scope]: <description>, e.g. feat(c2pa-node): add support, fix: correct validation, docs: update guidance.
  • Exclude generated output, caches, credentials, and unrelated worktree changes. Report suspected vulnerabilities through SECURITY.md, never public issues.