|
| 1 | +# Cytoscape.js AGENTS.md |
| 2 | + |
| 3 | +Guidelines for agents contributing to the Cytoscape.js graph theory and visualisation library. |
| 4 | + |
| 5 | +## Environment & tooling |
| 6 | +- Use Node via `.nvmrc` when possible: `nvm use` or `mise en`. |
| 7 | +- Use `npm`; the repo is configured around `package-lock.json` and the existing npm scripts. |
| 8 | +- Library source of truth is in `src/`. Documentation source lives in `documentation/md/`, `documentation/demos/`, and `documentation/docmaker.json`. Built artifacts in `build/`, `dist/`, and generated files under `documentation/` should only be updated via the project scripts. |
| 9 | +- Bundles are produced with Rollup from `src/index.mjs` into UMD, minified UMD, CJS, ESM, and minified ESM outputs. |
| 10 | +- The repo uses ESM source files (`.mjs`), ESLint, Mocha, and Playwright. |
| 11 | +- Before starting significant work, read any repo docs directly related to the area you are changing. For architecture context, start with `documentation/md/architecture.md`. |
| 12 | +- If you want to read the documentation, you can grep `documentation/docmaker.json`, which contains all the documentation data (and API in JSON format). You can search for things like "cy.on" for the `cy.on()` method. `docmaker.json` references markdown files in `documentation/md/` for prose that elaborates on particular API methods and also for general prose sections, like the intro or getting started sections. You can also grep `documentation/md/**/*.md` generally for doc searches. The paths broadly match the `src/**/*.mjs` paths. |
| 13 | + |
| 14 | +## Development flow |
| 15 | +- Make sure dependencies are installed when you first start: `npm install`. |
| 16 | +- Install Playwright browsers before running browser coverage or the full test suite on a fresh environment: `npx playwright install --with-deps`. |
| 17 | +- Make your changes. |
| 18 | +- Lint source files: `npm run lint`. |
| 19 | +- Run the narrowest useful test loop while iterating, but run the relevant verification before handing work back: |
| 20 | + - Source or algorithm changes: `npm run test:js` and `npm run test:modules`. |
| 21 | + - Renderer or interaction changes: `npm run test:js`, `npm run test:modules`, and sanity check in `debug/` via `npm run watch`; run Playwright when browser behaviour is affected. |
| 22 | + - Bundle, packaging, or docs pipeline changes: `npm run build`, `npm run docs`, and any targeted release script checks that apply. |
| 23 | + - If the change is broad or you are unsure, run `npm test`. |
| 24 | +- Build all bundles but only if you're modifying the build system: `npm run build`. |
| 25 | + |
| 26 | +## Repository structure |
| 27 | +- `src/`: Main library source. |
| 28 | + - `src/core/`: Core instance lifecycle, viewport, rendering, style, layout, animation, and notifications. |
| 29 | + - `src/collection/`: Collection APIs, traversals, dimensions, styling, and graph algorithms. |
| 30 | + - `src/style/`: Style parsing, application, bypasses, and stylesheet helpers. |
| 31 | + - `src/selector/`: Selector parsing and matching. |
| 32 | + - `src/extensions/`: Built-in layouts and renderers. |
| 33 | + - `src/extensions/renderer/base/`: Shared renderer state and geometry logic. |
| 34 | + - `src/extensions/renderer/canvas/`: Canvas renderer, drawing pipeline, caches, and WebGL helpers. |
| 35 | + - `src/extensions/layout/`: Built-in layouts like grid, cose, concentric, and breadthfirst. |
| 36 | + - `src/util/`: Shared low-level helpers. |
| 37 | +- `test/`: Mocha tests. Add regression coverage here for API and logic changes. |
| 38 | +- `debug/`: Manual visual and interaction test pages. Use this for renderer, interaction, and gesture changes that are hard to verify in unit tests alone. |
| 39 | +- `playwright-tests/` and `playwright.config.js`: Browser-level regression coverage. |
| 40 | +- `documentation/`: Generated site plus source markdown, demos, and the doc generator. |
| 41 | + - `documentation/md/`: Documentation source. |
| 42 | + - `documentation/demos/`: Demo apps and assets used by the docs site. |
| 43 | + - `documentation/docmaker.mjs`: Docs build entrypoint. |
| 44 | +- `.github/workflows/`: CI and release workflows. |
| 45 | +- `benchmark/`: Performance comparisons and targeted benchmark runners. |
| 46 | +- `typescript/`: TypeScript-related tests and fixtures. |
| 47 | + |
| 48 | +## Code standards |
| 49 | +1. Preserve the existing style: two-space indentation, single quotes, ESM imports/exports, and concise readable functions. |
| 50 | +2. Do not hand-edit generated outputs when a source file exists instead. In particular, prefer editing `src/` and `documentation/md/` over generated files in `build/`, `dist/`, and compiled docs assets. |
| 51 | +3. Keep module boundaries aligned with the existing architecture. New source files should live near the corresponding subsystem in `src/`. |
| 52 | +4. When fixing a bug, add or update a regression test whenever practical. Put public-behaviour tests in `test/`; keep internal-only coverage in `test/modules/` when applicable. |
| 53 | +5. For renderer, gesture, or grab-state changes, verify behaviour in `debug/` because visual regressions are not always caught by Mocha alone. You need to control a browser instance to use this and you need to run `npm run watch` to run a dev server with auto-rebuild. |
| 54 | +6. Keep docs in sync with API or behaviour changes. Update `documentation/md/`, demos, and `docmaker.json` inputs rather than patching generated HTML by hand. |
| 55 | +7. Avoid introducing new build tools, frameworks, or repo-wide conventions unless the task explicitly requires it. |
| 56 | +8. When adding new top-level workflows, major directories, or important source areas not already documented here, update `AGENTS.md`. |
| 57 | + |
| 58 | +## Testing notes |
| 59 | +- `npm test` matches CI closely: GitHub Actions installs dependencies, installs Playwright browsers, and runs `npm test`. |
| 60 | +- `npm run test:build` exercises the built bundle rather than source files; use it when a bug could be introduced by bundling or build-time transforms. |
| 61 | +- Playwright setup depends on a built UMD bundle and a local HTTP server. Use the existing scripts rather than inventing a parallel harness. |
| 62 | + |
| 63 | +## Documentation notes |
| 64 | +- Documentation HTML is generated. Do not edit generated docs directly when the corresponding markdown or template source (i.e. `docmaker.json` and `template.html`) should be changed instead. |
| 65 | + |
| 66 | +## Contribution notes |
| 67 | +- Keep changes narrowly scoped. Cytoscape.js has a large public API and small internal regressions can surface broadly. |
| 68 | +- Prefer extending existing tests, demos, and docs over adding parallel mechanisms. |
| 69 | +- If a change affects public API semantics, selectors, style behaviour, layouts, rendering, or documentation structure, call that out explicitly in your summary to the user. |
0 commit comments