|
1 | 1 | # AGENTS.md - WP Kernel |
2 | 2 |
|
3 | | -> 💡 For human contributors: see [DEVELOPMENT.md](./DEVELOPMENT.md) for setup, workflow, and environment details. |
4 | | -> This file focuses on agent/contribution rules. |
5 | | -
|
6 | | -**Purpose**: Operational guide for coding agents (Codex, etc.) working on WP Kernel. Follow the commands and constraints below. Finish only when checks are green and diffs are minimal. |
7 | | - |
8 | | -## Project Overview (for agents) |
9 | | - |
10 | | -- **Architecture**: Rails-like WordPress framework. **JS is source of truth**; PHP is a thin bridge (REST + capabilities + optional server bindings). |
11 | | -- **Core primitives**: Actions (orchestrate writes), Resources (transport + stores + cache keys + events), Views (blocks + bindings + Interactivity API), Jobs (background). |
12 | | -- **Non-negotiables** |
13 | | - - UI never calls transport directly. **All writes flow through Actions.** |
14 | | - - Events must use **canonical registry names**. No ad-hoc events. |
15 | | - - Errors are typed `KernelError` subclasses. Never throw a plain `Error`. |
16 | | - |
17 | | -## Monorepo Layout |
18 | | - |
19 | | -``` |
20 | | -packages/ |
21 | | - wp-kernel/ # core framework (resources, actions, events, jobs) |
22 | | - wp-kernel-ui/ # UI components & design system |
23 | | - wp-kernel-cli/ # scaffolding & DX tools |
24 | | - wp-kernel-e2e-utils/ # e2e utilities (validated via showcase) |
25 | | -app/ |
26 | | - showcase/ # demo plugin exercising full kernel |
27 | | -docs/ # public API docs & guides |
28 | | -information/ # product spec, example plugin specs, roadmap, event taxonomy |
29 | | -``` |
| 3 | +## Scope & Precedence |
30 | 4 |
|
31 | | -## Environment & Tooling |
32 | | - |
33 | | -- **Node**: v20.x LTS or higher (minimum for Vite 7). **pnpm** workspace. |
34 | | -- **WordPress**: 6.8+ required (Script Modules API is core to framework). |
35 | | -- **Development environments**: wp-env (Docker + PHP 8.1+) OR WordPress Playground (WASM, no Docker). |
36 | | -- **E2E testing**: Optional. Only needed if writing/running E2E tests (uses Playwright + `@geekist/wp-kernel-e2e-utils`). |
37 | | - |
38 | | -- **Commands** (always use exactly these): |
39 | | - - Install: `pnpm install` |
40 | | - - Format/lint: `pnpm lint --fix` (or `pnpm format`) |
41 | | - - Typecheck (code): `pnpm typecheck` |
42 | | - - Typecheck (tests): `pnpm typecheck:tests` |
43 | | - - Test (all): `pnpm test` |
44 | | - > Do **not** use `--filter` for tests; it breaks our harness. |
45 | | - - Build (if needed): `pnpm build` |
46 | | - |
47 | | - - **When running agents (Codex, Co‑Pilot, etc.) inside private containers or CI**, set the environment variable `CI=1` before running any `git` or `pnpm` commands. This ensures non-interactive behaviour and avoids prompts that could block automation. |
48 | | - |
49 | | - - **Note:** The pre-commit hook may take some time to complete. It performs typechecks and tests before allowing a commit. Contributors should wait patiently until it finishes. |
50 | | - |
51 | | -**When in doubt**: run install → typecheck → tests → lint fix → tests again. |
52 | | - |
53 | | ---- |
54 | | - |
55 | | -## Definition of Done (DoD) |
56 | | - |
57 | | -1. `pnpm typecheck` and `pnpm typecheck:tests` pass. |
58 | | -2. `pnpm test` is green and **coverage does not regress**: |
59 | | - - ≥95% statements/lines, ≥98% functions globally. |
60 | | - - Branch coverage median ≥90% (file-level dips acceptable if global median holds). |
61 | | -3. New public APIs covered, error paths tested. |
62 | | -4. No `any` types introduced; project/test globals updated if needed (`global.d.ts`, `tests/test-globals.d.ts`). |
63 | | -5. Follow folder conventions: |
64 | | - |
65 | | -``` |
66 | | -
|
67 | | -app/ |
68 | | -resources/ # defineResource() |
69 | | -actions/ # defineAction() |
70 | | -views/ # bindings + Interactivity |
71 | | -jobs/ # defineJob() |
72 | | -
|
73 | | -``` |
74 | | - |
75 | | ---- |
76 | | - |
77 | | -## File & Refactor Guards |
78 | | - |
79 | | -- Keep modules/tests under **500 lines**. If approaching the limit: |
80 | | -- Extract utilities/interfaces or split modules. |
81 | | -- Before large refactors, open a planning comment and summarise the split. |
82 | | - |
83 | | ---- |
84 | | - |
85 | | -## Action & Resource Patterns (enforced) |
86 | | - |
87 | | -- **Actions-first**. Example: |
88 | | - |
89 | | -```ts |
90 | | -import { CreateThing } from '@/app/actions/Thing/Create'; |
91 | | -await CreateThing({ data: formData }); |
92 | | -``` |
93 | | - |
94 | | -- **Resources**: one `defineResource()` defines client, store, cache keys, events. |
95 | | -- **Events**: import from the canonical registry only. |
| 5 | +This document provides operational guidance for coding agents (Codex, etc.) working on WP Kernel. Follow the commands and constraints below. Complete tasks only when checks are green and diffs are minimal. |
96 | 6 |
|
97 | | ---- |
| 7 | +## Project Architecture & Invariants |
98 | 8 |
|
99 | | -## PHP Bridge |
| 9 | +- Rails-like WordPress framework: **JS is source of truth**; PHP acts as a thin transport and capability bridge. |
| 10 | +- Core primitives: Actions (handle writes), Resources (transport, stores, cache keys, events), Views (blocks, bindings, Interactivity API), Jobs (background). |
| 11 | +- Non-negotiables: |
| 12 | + - UI never calls transport directly; **all writes flow through Actions**. |
| 13 | + - Use only **canonical registry event names**; no ad-hoc events. |
| 14 | + - Errors must be typed `KernelError` subclasses; never throw plain `Error`. |
100 | 15 |
|
101 | | -- Treat PHP as a strict transport/capability contract. No business logic drift. |
102 | | -- If changing types across PHP/JS, stop and raise a comment with a migration note. |
| 16 | +## Project Structure & Module Organisation |
103 | 17 |
|
104 | | ---- |
| 18 | +- The repo is a monorepo with multiple packages under `packages/`. |
| 19 | +- Each package uses `src/` for source code, `tests/` for tests, and `types/` for TypeScript definitions. |
| 20 | +- Modules have clear separation of concerns and minimal cross-package dependencies. |
| 21 | +- Avoid deep imports across packages (e.g., no direct imports from `packages/*/src/**`). |
| 22 | +- Use explicit exports and imports to maintain encapsulation and module boundaries. |
105 | 23 |
|
106 | | -## Test Strategy |
107 | | - |
108 | | -- **E2E tests are optional** for framework users - only needed if contributing or writing E2E tests for your own project. |
109 | | -- Target e2e realism. `@geekist/wp-kernel-e2e-utils` is validated **via** `app/showcase` e2e; do not unit-test `e2e-utils` in isolation. |
110 | | -- Flaky tests: prefer serial mode or better selectors/cleanup over sleeps. |
111 | | - |
112 | | ---- |
113 | | - |
114 | | -## Coverage Hotspots |
115 | | - |
116 | | -- Keep `error`, `http`, and `resource` core near **100%**. |
117 | | -- Defensive branches that are genuinely hard to reach are acceptable if documented. |
118 | | - |
119 | | ---- |
120 | | - |
121 | | -## Commit, PR, and Review Protocol |
| 24 | +## Environment & Tooling |
122 | 25 |
|
123 | | -- Small, cohesive commits. One concern per commit. |
124 | | -- **ALWAYS use the PR template** (`.github/PULL_REQUEST_TEMPLATE.md`) - never create ad-hoc PRs |
125 | | -- PR title format: Sprint headline (e.g., "Sprint 5: Bindings & Interactivity") |
126 | | -- Link to Roadmap section and Sprint doc/spec in PR description |
127 | | -- Include changeset unless labelled `no-release` (see [RELEASING.md](./RELEASING.md)) |
128 | | -- Before requesting review: run `pnpm lint --fix && pnpm typecheck && pnpm typecheck:tests && pnpm test`. |
| 26 | +- Node v20.x LTS or higher (required for Vite 7). |
| 27 | +- WordPress 6.8+ (Script Modules API required). |
| 28 | +- Development environments: `wp-env` (Docker + PHP 8.1+) or WordPress Playground (WASM, no Docker). |
| 29 | +- E2E testing is optional; uses Playwright and `@geekist/wp-kernel-e2e-utils`. |
| 30 | +- Commands: |
| 31 | + - Install: `pnpm install` |
| 32 | + - Format/lint: `pnpm lint --fix` and `pnpm format` |
| 33 | + - Typecheck code: `pnpm typecheck` |
| 34 | + - Typecheck tests: `pnpm typecheck:tests` |
| 35 | + - Test all: `pnpm test` (do not use `--filter`) |
| 36 | + - Build: `pnpm build` (if needed) |
| 37 | +- We have `types/globals.d.ts`, `tests/test-globals.d.ts`, and stubs in `tests/test-utils/wp.ts` for typing and testing support. Use these and update incrementally as needed. |
| 38 | +- When running agents (Codex, Co-Pilot, etc.) inside private containers or CI, set `CI=1` before running any `git` commands to ensure non-interactive behavior. |
| 39 | + |
| 40 | +## Quality & Coverage |
| 41 | + |
| 42 | +- Maintain ≥95% statements/lines and ≥98% functions coverage globally. |
| 43 | +- Branch coverage median ≥90% (some file-level dips allowed if global median holds). |
| 44 | +- Keep core modules (error, http, resource) near 100% coverage. |
| 45 | +- Defensive branches that are hard to reach are acceptable if documented. |
| 46 | +- Avoid flaky tests; use serial mode or improved selectors/cleanup instead of sleeps. |
| 47 | + |
| 48 | +## Workflow & Policies |
| 49 | + |
| 50 | +- Definition of Done (DoD): |
| 51 | + - Pass `pnpm typecheck` and `pnpm typecheck:tests`. |
| 52 | + - Pass `pnpm test` with no coverage regression. |
| 53 | + - Test new public APIs and error paths. |
| 54 | + - No `any` types introduced; update globals if needed. |
| 55 | + - Follow folder conventions. |
| 56 | +- Always run before requesting review: |
| 57 | + `pnpm lint --fix && pnpm typecheck && pnpm typecheck:tests && pnpm test` |
| 58 | + |
| 59 | +## Commit & PR Guidelines |
| 60 | + |
| 61 | +- Make small, focused commits (one concern per commit). |
| 62 | +- Always use the PR template (`.github/PULL_REQUEST_TEMPLATE.md`). |
| 63 | +- PR title format: Sprint headline (e.g., "Sprint 5: Bindings & Interactivity"). |
| 64 | +- Link to Roadmap section and Sprint doc/spec in PR description. |
129 | 65 | - Respond to all review feedback; avoid duplication; extract interfaces when suggested. |
130 | 66 |
|
131 | | ---- |
132 | | - |
133 | 67 | ## Agent Execution Policy (Codex) |
134 | 68 |
|
135 | | -- **Approval mode**: default to read/write in workspace. Ask before: |
| 69 | +- Default to read/write in workspace. |
| 70 | +- Ask before: |
136 | 71 | - Writing outside workspace, changing dotfiles, or enabling network access. |
137 | 72 | - Installing new dev dependencies. |
138 | | - - Creating or modifying PRs (always use PR template) |
139 | | - |
140 | | -- **Never**: run destructive commands, alter Git history, or publish artefacts. |
141 | | -- **PR creation**: Always use `.github/PULL_REQUEST_TEMPLATE.md` - no ad-hoc PRs |
| 73 | + - Creating or modifying PRs (always use PR template). |
| 74 | +- Never run destructive commands, alter Git history, or publish artifacts. |
142 | 75 | - Always show plan, then diffs, then run checks. Close task only after DoD passes. |
143 | 76 |
|
144 | | ---- |
145 | | - |
146 | | -## Package-specific Notes |
147 | | - |
148 | | -- `wp-kernel-e2e-utils`: treated as a support lib; validated by showcase e2e only. |
149 | | -- `wp-kernel-ui`: respect design tokens and component boundaries; add stories if created. |
150 | | -- `wp-kernel-cli`: keep scaffolds idempotent; snapshot tests preferred. |
151 | | - |
152 | | ---- |
153 | | - |
154 | | -## Typical Flows |
155 | | - |
156 | | -### Bug fix |
157 | | - |
158 | | -1. Reproduce with a focused test. |
159 | | -2. Minimal fix in the smallest package. |
160 | | -3. Run full checks; ensure coverage does not drop. |
161 | | -4. Add a short regression test name: `fix: <symptom>`. |
162 | | - |
163 | | -### Feature |
164 | | - |
165 | | -1. Add/extend Actions and Resources first; wire Views via bindings. |
166 | | -2. Emit canonical events; update cache invalidation. |
167 | | -3. Add tests; update docs if API changed. |
168 | | - |
169 | | ---- |
170 | | - |
171 | 77 | ## What NOT to do |
172 | 78 |
|
173 | | -- ✗ Call transport from UI components |
174 | | -- ✗ Create ad-hoc event names |
175 | | -- ✗ Deep-import across packages (`packages/*/src/**`) |
176 | | -- ✗ Use `any` or throw plain `Error` |
177 | | -- ✗ Skip cache invalidation after writes |
178 | | -- ✗ Ignore TS errors or coverage regressions |
| 79 | +- Call transport from UI components. |
| 80 | +- Create ad-hoc event names. |
| 81 | +- Deep-import across packages (`packages/*/src/**`). |
| 82 | +- Use `any` or throw plain `Error`. |
| 83 | +- Skip cache invalidation after writes. |
| 84 | +- Ignore TypeScript errors or coverage regressions. |
0 commit comments