AGENTS.md
AGENTS.mdAGENTS.mdroot
Quality
85/100
Scores the file, not the repository.Length
1,296 words
26 headings · 3 code blocksRepository
409
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1# AGENTS.md23This file provides guidance for AI coding agents (Claude Code, Codex, Gemini CLI, etc.) working in this repository.45## Navigation67- Locating files or understanding structure → [Repository Structure](#repository-structure)8- Writing or reviewing PHP → [Key Conventions → PHP](#php) + [Known Constraints → PHP Constraints](#php-constraints)9- Working on REST API controllers → [Key Conventions → REST API](#rest-api)10- Editing styles or scripts → [Key Conventions → CSS/JS](#cssjs) + [Known Constraints → JavaScript](#javascript)11- Checks required before committing → [Development Workflow](#development-workflow)12- Branch naming or commit format → [Creating Branches](#creating-branches) + [Commits](#commits)13- Verifying whether a file is safe to modify → [What Not to Touch](#what-not-to-touch)1415## Project Overview1617**CoCart Community** is an open-source, developer-first REST API plugin for WooCommerce. It exposes product browsing, cart management, and session handling as a WordPress REST API — purpose-built for headless and decoupled storefronts.1819- **Plugin file:** `cart-rest-api-for-woocommerce.php`20- **Main class:** `includes/class-cocart.php` → singleton via `CoCart()`21- **Autoloader:** `includes/class-cocart-autoloader.php` (PSR-4 from `includes/`)22- **Text domain:** `cart-rest-api-for-woocommerce`23- **PHP minimum:** 8.224- **WordPress minimum:** 6.725- **WooCommerce minimum:** 9.026- **Default branch:** `trunk`27- **License:** GPLv3+2829## Repository Structure3031```text32cart-rest-api-for-woocommerce.php # Main plugin file — defines constants, boots plugin33load-package.php # Package loader34uninstall.php # Uninstall cleanup35includes/36├── class-cocart.php # Main class — hooks, init, load sequence37├── class-cocart-autoloader.php # PSR-4 autoloader38├── cocart-*.php # Standalone function files (formatting, deprecated, etc.)39├── abstracts/ # Abstract base classes40├── classes/41│ ├── rest-api/ # REST API controllers, authentication, caching, responses42│ ├── admin/ # WordPress admin UI, notices, setup wizard, update checks43│ ├── cli/ # WP-CLI commands44│ └── integrations/ # Third-party plugin compatibility handlers45└── utilities/ # Shared utility helpers46assets/47├── scss/ # SCSS source — only this is tracked in git48├── css/ # Compiled CSS — generated by CI, not tracked49├── js/ # JS source; *.min.js compiled by CI, not tracked50└── images/ # Static images51languages/ # Only README.md tracked; .pot/.po/.mo generated by CI52bin/ # Release and build shell scripts53```5455## Key Conventions5657### PHP5859- Follow [WordPress Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/)60- Use `cart-rest-api-for-woocommerce` as the text domain in all translatable strings61- Use numbered arguments in `printf`/`sprintf` when replacing more than one value: `%1$s`, `%2$s`62- Use sentence case for translatable strings: `Some thing` not `Some Thing`63- Avoid HTML in strings — insert via `sprintf` instead64- Do not call deprecated functions from plugin source; use replacement functions directly65- Use `COCART_FILE` and `COCART_SLUG` constants — do not hardcode the plugin path or slug6667### REST API6869- REST API controllers live in `includes/classes/rest-api/`70- CoCart uses WooCommerce Data Stores API for session management — not WooCommerce default sessions71- ETag support, cache headers, and CORS handling are built-in — do not bypass them72- Authentication is via JWT or Basic Auth only — no cookie/nonce auth for API requests7374### CSS/JS7576- Edit SCSS source in `assets/scss/` — never edit compiled CSS in `assets/css/`77- Compiled CSS and minified JS are generated by CI (`npx grunt css js`) — do not commit them78- RTL CSS is auto-generated from compiled CSS — do not create RTL files manually7980## Build Commands8182```bash83# Install dependencies84npm ci85composer install8687# Compile CSS and JS88npx grunt css js8990# Watch for changes during development91npx grunt watch9293# Code standards94composer phpcs # Check PHP coding standards95composer phpcbf # Auto-fix coding standards issues96composer phpstan # Static analysis9798# Fix text domain references99npm run fix:textdomain100```101102## Development Workflow1031041. Make code changes1052. Run `composer phpcs` on changed PHP files — fix all violations before continuing1063. Run `composer phpstan` on changed PHP files — fix errors in code, never add to baseline1074. Compile assets if SCSS/JS changed: `npx grunt css js`1085. Commit only after checks are clean1096. Open a pull request against `trunk`110111### Pre-commit Checks112113**Before committing PHP changes**, run these to avoid CI failures:114115```bash116# Check coding standards on changed files117composer phpcs118119# Static analysis120composer phpstan121```122123**PHPStan baseline policy:** The baseline file (`phpstan-baseline.neon`) must never grow. If PHPStan reports a new error, fix it in the code. If your fix resolves a previously baselined error, remove the corresponding entry from the baseline. The baseline should only shrink over time.124125## Known Constraints126127### Project Structure128129- Never add standalone global functions outside the designated `includes/cocart-*.php` function files130- Never modify `CHANGELOG.md` — updated by the CoCart team only131- Never commit compiled CSS (`assets/css/`) or minified JS (`assets/js/**/*.min.js`) — generated by CI132- Never commit `.pot` files — generated by CI133- Never edit RTL CSS files manually — auto-generated from compiled CSS134- All new classes go in `includes/classes/` under the appropriate subdirectory135- `includes/` legacy function files should only be modified when no class-based alternative exists136137### JavaScript138139- Never write inline JavaScript — all JS must live in enqueued script files so it can be compiled, linted, and minified140- Never use dynamic code execution functions (`call`, `apply`, `Function` constructor, or similar patterns that execute strings as code)141- Never enqueue scripts or styles outside the designated admin class142143### PHP Constraints144145- Never use `var_dump()`, `print_r()`, or `error_log()` in committed code — remove all debug output before committing146- Never access `$_GET`, `$_POST`, or `$_SERVER` directly in REST API controllers — use `WP_REST_Request` parameter methods147- Never write raw database queries — use WooCommerce Data Stores or existing CoCart abstractions148- Never use `wp_die()` inside REST API controllers — return a `WP_Error` instance instead149- Never output unescaped content — use `esc_html()`, `esc_attr()`, `wp_json_encode()`, or the appropriate escaping function150- Never hardcode credentials, tokens, or API keys — use WordPress options or constants defined outside the codebase151- Never read options directly where a CoCart settings abstraction already exists — use the abstraction152153## What Not to Touch154155- **`CHANGELOG.md`** — updated by the CoCart team, not contributors156- **`languages/*.pot`** — generated by CI (`wp i18n make-pot`), not tracked in git157- **`assets/css/`** — compiled by CI, not tracked in git158- **`assets/js/**/*.min.js`** — compiled by CI, not tracked in git159- **`vendor/`** — managed by Composer, not tracked in git160- **`node_modules/`** — managed by npm, not tracked in git161- **`.phpcs.xml.dist`** — do not change coding standard rules without discussion162163## Creating Branches164165Branch names follow this structure (`{short-slug}` = brief descriptor of the change):166167- `release/{version}` — release branches168- `refactor/{short-slug}` — refactors169- `test/{short-slug}` — test-only changes170- `fix/{issue-number}-{short-slug}` — bug fixes (always include the issue number)171- `add/{short-slug}` — new features172173## Commits174175- Each commit should address one atomic unit of work176- Subject line: imperative mood, no trailing period, max 50 characters (e.g. `Fix session expiry on guest checkout`)177- Blank line between subject and body178- Body lines: max 72 characters179- Explain *what* and *why*, not just *how* — only explain *how* if it isn't obvious180- Reference the related issue number in the commit body (e.g. `Fixes #123`)181- Do not amend published commits182183## Agent Rules184185- Run pre-commit checks before every commit — do not skip them for any reason186- Do not modify generated files (`assets/css/`, `*.min.js`, `*.pot`) — CI overwrites them187- Do not add entries to the PHPStan baseline — fix the error in code instead188- Do not create new files when an existing class can be extended or modified189- Do not reach past a CoCart abstraction to call WordPress or WooCommerce directly — use the abstraction190- Do not amend commits that have already been pushed191- Check [What Not to Touch](#what-not-to-touch) before modifying any file you are uncertain about192- Check [Known Constraints](#known-constraints) before writing any new PHP, JS, or SQL193
Also in co-cart/co-cart
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?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| co-cart/co-cart.cursor/rules/git.mdc · 409 | Cursor rules | gitagent-behaviour | 39/100 | 3 days ago |
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 | |
| code-yeongyu/oh-my-openagentpackages/web/AGENTS.md · 67k | AGENTS.md | setupbuildtestlint-format+6 | 100/100 | 2 days ago | |
| mui/material-uiAGENTS.md · 99k | AGENTS.md | setupbuildtestlint-format+9 | 100/100 | 3 days ago | |
| duckduckgo/content-scope-scriptsspecial-pages/AGENTS.md · 70 | AGENTS.md | buildteststylearch+3 | 100/100 | 3 days ago | |
| TryGhost/Ghoste2e/AGENTS.md · 55k | AGENTS.md | setupteststylearch+2 | 100/100 | 3 days ago | |
| SkeneTechnologies/skene-cookbookAGENTS.md · 51 | AGENTS.md | setupbuildtestlint-format+7 | 100/100 | 2 days ago | |
| trick77/agents-md-syncAGENTS.md · 2 | AGENTS.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| elastic/elasticsearchx-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/AGENTS.md · 78k | AGENTS.md | buildtestlint-formatstyle+2 | 100/100 | 3 days ago |
