Skip to content

Commit a6ac318

Browse files
committed
added cursor rules and skills
1 parent e7a4006 commit a6ac318

224 files changed

Lines changed: 21167 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.cursor/rules/cimo-anti-slop.mdc‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
description: Maintainability and anti-slop standards when changing Cimo code
3+
alwaysApply: true
4+
---
5+
6+
# Maintainability & anti-slop
7+
8+
Prefer deepening existing seams over inventing parallel structure. Goal: one place to change a behaviour; freemium gates and shared heuristics stay single-sourced.
9+
10+
## Before you paste
11+
12+
When adding or extending behaviour, check the nearest sibling first. If the change would clone a block (converter wiring, media-manager upload hooks, settings field + REST save pairs, upsell/pricing URL builders, `CIMO_BUILD` gates), extract or reuse a shared helper **before** adding the nth copy.
13+
14+
## Deepen, don’t layer
15+
16+
Keep the runtime spine:
17+
18+
- **Upload path:** media-manager hooks → shared converters → metadata saver
19+
- **Settings path:** React settings UI → REST/options → localized `window.cimoAdmin` / script loader
20+
- **Freemium:** free tree + `CIMO_BUILD` gates; premium only under `pro__premium_only/`
21+
22+
New behaviour goes into an existing module cluster (converter, media-manager surface, settings section, shared util, premium module) when one fits. Do not add a second converter registry, parallel upload interceptor, or ad-hoc AJAX twin beside an existing REST route without an explicit extract.
23+
24+
God-file rule of thumb: prefer extracting a coherent cluster over growing `admin-settings.js`, a media-manager entry, or a fat PHP admin class with another pasted case.
25+
26+
## Single source for shared heuristics
27+
28+
Heuristics that exist on both PHP and JS (settings defaults, “is premium” flags, pricing/upsell URLs, optimization labels) share one definition of truth — localized data, shared module, or a documented sync. Do not hand-sync a second map “for convenience.”
29+
30+
Ship or silence: do not advertise a premium feature, format, or setting in free UI/copy unless the free build truly exposes it (or clearly marks it as premium upsell).
31+
32+
## Completion check
33+
34+
Before finishing a change that adds a converter, setting, upload hook, or freemium gate: every list/map/UI/REST surface that must know about it is updated, no phantom options remain, and no new duplicate helper was introduced beside an existing one. Keep premium logic out of the free tree.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: Cimo uses plain JavaScript; React for settings, vanilla JS for media upload
3+
alwaysApply: true
4+
---
5+
6+
# JavaScript & React
7+
8+
Cimo uses **regular JavaScript** (`.js`), not TypeScript, for plugin UI and runtime code. Do not add `.ts` / `.tsx` source files outside e2e tests (`e2e/**/*.ts` is fine).
9+
10+
## Two JS surfaces
11+
12+
1. **Media upload interception** (primary product runtime) — mostly **vanilla JS** under `src/admin/js/media-manager/` and shared converters under `src/shared/converters/`. This hooks Media Manager / editor / page-builder uploads and runs client-side optimize/convert before save.
13+
2. **Settings UI** — **React** via `@wordpress/element` under `src/admin/js/page/` (and related bulk-optimizer UI). Mount with `createRoot` into `#cimo-admin-settings`.
14+
15+
Prefer putting interactive upload/optimize logic in shared JS modules. PHP should expose settings, enqueue assets, REST/AJAX, and capability gates — not reimplement conversion in PHP when the product path is client-side.
16+
17+
## React (settings / admin UI)
18+
19+
- Build admin UI with **React** via `@wordpress/element` (WordPress’s React wrapper).
20+
- Use JSX inside `.js` files (wp-scripts handles transpilation).
21+
- Prefer WordPress packages (`@wordpress/element`, `@wordpress/components`, `@wordpress/i18n`, `@wordpress/api-fetch`, `@wordpress/hooks`, etc.) over adding a separate `react` / `react-dom` dependency.
22+
- Text domain: `cimo-image-optimizer`.
23+
- Freemium UI extensions use `applyFilters( 'cimo.…' )` so premium can swap/inject components without putting premium logic in the free tree.
24+
25+
## Import alias
26+
27+
- Use the `~cimo` alias (maps to `src/`) for cross-folder imports, e.g. `~cimo/shared/pricing-url`.
28+
29+
## Media & converters
30+
31+
- New optimize/convert formats deepen `src/shared/converters/` (extend `converter-abstract` / registry in `index.js`) rather than forking one-off paths in each media-manager file.
32+
- Keep upload UX (drop zone, select files, progress, sidebar info) in `src/admin/js/media-manager/`; keep pure conversion/util code in `src/shared/`.

‎.cursor/rules/cimo-project-repos.mdc‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@ This project has two GitHub repositories, used depending on whether we're buildi
1717
### Free version
1818

1919
- Main plugin repo: https://github.com/gambitph/Cimo
20+
- Contains **only** free plugin code and must remain free of premium logic (WordPress.org guidelines).
21+
- Must pass [WordPress Plugin Check](https://github.com/wordpress/plugin-check) for Plugin Directory inclusion (see `cimo-wordpress-plugin-check` rule).
2022

2123
### Premium version
2224

2325
- Uses the free version as the main plugin repo, and additionally uses:
2426
- Premium-only repo: https://github.com/bfintal/cimo-premium
2527
- The premium repo contains **only** the premium plugin code.
2628
- It is placed in the `pro__premium_only` directory inside the free plugin's root folder.
29+
30+
## Free / Premium boundaries
31+
32+
- Do not put premium feature logic in the free repo.
33+
- Premium code lives exclusively under `pro__premium_only/`.
34+
- The free plugin may gate-load premium via `CIMO_BUILD === 'premium'` and `pro__premium_only/index.php`.
35+
- When packaging the free build, `pro__premium_only` must not be included.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
description: Free plugin must pass WordPress Plugin Check for directory submission
3+
alwaysApply: true
4+
---
5+
6+
# WordPress Plugin Directory & Plugin Check
7+
8+
The **free** Cimo plugin is intended for the [WordPress Plugin Directory](https://wordpress.org/plugins/). Directory inclusion requires meeting WordPress.org plugin guidelines.
9+
10+
## Official checker
11+
12+
Use **[WordPress/plugin-check](https://github.com/wordpress/plugin-check)** (Plugin Check / PCP) as the compliance bar:
13+
14+
- Static + runtime checks for directory requirements and best practices
15+
- WP Admin: **Tools → Plugin Check**
16+
- WP-CLI: `wp plugin check <plugin>` (add `--require=…/plugin-check/cli.php` for runtime checks)
17+
- Also: [wordpress.org/plugins/plugin-check](https://wordpress.org/plugins/plugin-check/)
18+
19+
## What this means for Cimo
20+
21+
- Free-repo code and the free build zip should be written to **pass Plugin Check**.
22+
- Prefer WordPress coding / security / i18n / enqueue practices that PCP enforces (escaping, nonces, capability checks, no forbidden APIs, proper headers, etc.).
23+
- Do not ship premium-only code, `pro__premium_only/`, or directory-disallowed patterns in the free package.
24+
- When changing free-plugin PHP, assets, or packaging, keep Plugin Check green in mind — fix regressions rather than silencing them without cause.
25+
26+
Premium code under `pro__premium_only/` is out of scope for Directory submission, but anything that lands in the **free** tree or free zip is in scope.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
name: code-review
3+
description: Review the changes since a fixed point (commit, branch, tag, or merge-base) along two axes — Standards (does the code follow this repo's documented coding standards?) and Spec (does the code match what the originating issue/spec asked for?). Runs both reviews in parallel sub-agents and reports them side by side. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to "review since X".
4+
---
5+
6+
Two-axis review of the diff between `HEAD` and a fixed point the user supplies:
7+
8+
- **Standards** — does the code conform to this repo's documented coding standards?
9+
- **Spec** — does the code faithfully implement the originating issue / spec?
10+
11+
Both axes run as **parallel sub-agents** so they don't pollute each other's context, then this skill aggregates their findings.
12+
13+
The issue tracker should have been provided to you — run `/setup-matt-pocock-skills` if `docs/agents/issue-tracker.md` is missing.
14+
15+
## Process
16+
17+
### 1. Pin the fixed point
18+
19+
Whatever the user said is the fixed point — a commit SHA, branch name, tag, `main`, `HEAD~5`, etc. If they didn't specify one, ask for it.
20+
21+
Capture the diff command once: `git diff <fixed-point>...HEAD` (three-dot, so the comparison is against the merge-base). Also note the list of commits via `git log <fixed-point>..HEAD --oneline`.
22+
23+
Before going further, confirm the fixed point resolves (`git rev-parse <fixed-point>`) and the diff is non-empty. A bad ref or empty diff should fail here — not inside two parallel sub-agents.
24+
25+
### 2. Identify the spec source
26+
27+
Look for the originating spec, in this order:
28+
29+
1. Issue references in the commit messages (`#123`, `Closes #45`, GitLab `!67`, etc.) — fetch via the workflow in `docs/agents/issue-tracker.md`.
30+
2. A path the user passed as an argument.
31+
3. A spec file under `docs/`, `specs/`, or `.scratch/` matching the branch name or feature.
32+
4. If nothing is found, ask the user where the spec is. If they say there isn't one, the **Spec** sub-agent will skip and report "no spec available".
33+
34+
### 3. Identify the standards sources
35+
36+
Anything in the repo that documents how code should be written, such as `CODING_STANDARDS.md` or `CONTRIBUTING.md`.
37+
38+
On top of whatever the repo documents, the Standards axis always carries the **smell baseline** below — a fixed set of Fowler code smells (_Refactoring_, ch.3) that applies even when a repo documents nothing. Two rules bind it:
39+
40+
- **The repo overrides.** A documented repo standard always wins; where it endorses something the baseline would flag, suppress the smell.
41+
- **Always a judgement call.** Each smell is a labelled heuristic ("possible Feature Envy"), never a hard violation — and, like any standard here, skip anything tooling already enforces.
42+
43+
Each smell reads *what it is* → *how to fix*; match it against the diff:
44+
45+
- **Mysterious Name** — a function, variable, or type whose name doesn't reveal what it does or holds. → rename it; if no honest name comes, the design's murky.
46+
- **Duplicated Code** — the same logic shape appears in more than one hunk or file in the change. → extract the shared shape, call it from both.
47+
- **Feature Envy** — a method that reaches into another object's data more than its own. → move the method onto the data it envies.
48+
- **Data Clumps** — the same few fields or params keep travelling together (a type wanting to be born). → bundle them into one type, pass that.
49+
- **Primitive Obsession** — a primitive or string standing in for a domain concept that deserves its own type. → give the concept its own small type.
50+
- **Repeated Switches** — the same `switch`/`if`-cascade on the same type recurs across the change. → replace with polymorphism, or one map both sites share.
51+
- **Shotgun Surgery** — one logical change forces scattered edits across many files in the diff. → gather what changes together into one module.
52+
- **Divergent Change** — one file or module is edited for several unrelated reasons. → split so each module changes for one reason.
53+
- **Speculative Generality** — abstraction, parameters, or hooks added for needs the spec doesn't have. → delete it; inline back until a real need shows.
54+
- **Message Chains** — long `a.b().c().d()` navigation the caller shouldn't depend on. → hide the walk behind one method on the first object.
55+
- **Middle Man** — a class or function that mostly just delegates onward. → cut it, call the real target direct.
56+
- **Refused Bequest** — a subclass or implementer that ignores or overrides most of what it inherits. → drop the inheritance, use composition.
57+
58+
### 4. Spawn both sub-agents in parallel
59+
60+
**Standards sub-agent prompt** — include:
61+
62+
- The full diff command and commit list.
63+
- The list of standards-source files you found in step 3, **plus the smell baseline from step 3** pasted in full — the sub-agent has no other access to it.
64+
- The brief: "Report — per file/hunk where relevant — (a) every place the diff violates a documented standard: cite the standard (file + the rule); and (b) any baseline smell you spot: name it and quote the hunk. Distinguish hard violations from judgement calls — documented-standard breaches can be hard, but baseline smells are always judgement calls, and a documented repo standard overrides the baseline. Skip anything tooling enforces. Under 400 words."
65+
66+
**Spec sub-agent prompt** — include:
67+
68+
- The diff command and commit list.
69+
- The path or fetched contents of the spec.
70+
- The brief: "Report: (a) requirements the spec asked for that are missing or partial; (b) behaviour in the diff that wasn't asked for (scope creep); (c) requirements that look implemented but where the implementation looks wrong. Quote the spec line for each finding. Under 400 words."
71+
72+
If the spec is missing, skip the Spec sub-agent and note this in the final report.
73+
74+
### 5. Aggregate
75+
76+
Present the two reports under `## Standards` and `## Spec` headings, verbatim or lightly cleaned. Do **not** merge or rerank findings — the two axes are deliberately separate (see _Why two axes_).
77+
78+
End with a one-line summary: total findings per axis, and the worst issue _within each axis_ (if any). Don't pick a single winner across axes — that's the reranking the separation exists to prevent.
79+
80+
## Why two axes
81+
82+
A change can pass one axis and fail the other:
83+
84+
- Code that follows every standard but implements the wrong thing → **Standards pass, Spec fail.**
85+
- Code that does exactly what the issue asked but breaks the project's conventions → **Spec pass, Standards fail.**
86+
87+
Reporting them separately stops one axis from masking the other.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface:
2+
display_name: "Code Review"
3+
short_description: "Review a diff on standards and spec"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Deepening
2+
3+
How to deepen a cluster of shallow modules safely, given its dependencies. Assumes the vocabulary in [SKILL.md](SKILL.md) — **module**, **interface**, **seam**, **adapter**.
4+
5+
## Dependency categories
6+
7+
When assessing a candidate for deepening, classify its dependencies. The category determines how the deepened module is tested across its seam.
8+
9+
### 1. In-process
10+
11+
Pure computation, in-memory state, no I/O. Always deepenable — merge the modules and test through the new interface directly. No adapter needed.
12+
13+
### 2. Local-substitutable
14+
15+
Dependencies that have local test stand-ins (PGLite for Postgres, in-memory filesystem). Deepenable if the stand-in exists. The deepened module is tested with the stand-in running in the test suite. The seam is internal; no port at the module's external interface.
16+
17+
### 3. Remote but owned (Ports & Adapters)
18+
19+
Your own services across a network boundary (microservices, internal APIs). Define a **port** (interface) at the seam. The deep module owns the logic; the transport is injected as an **adapter**. Tests use an in-memory adapter. Production uses an HTTP/gRPC/queue adapter.
20+
21+
Recommendation shape: *"Define a port at the seam, implement an HTTP adapter for production and an in-memory adapter for testing, so the logic sits in one deep module even though it's deployed across a network."*
22+
23+
### 4. True external (Mock)
24+
25+
Third-party services (Stripe, Twilio, etc.) you don't control. The deepened module takes the external dependency as an injected port; tests provide a mock adapter.
26+
27+
## Seam discipline
28+
29+
- **One adapter means a hypothetical seam. Two adapters means a real one.** Don't introduce a port unless at least two adapters are justified (typically production + test). A single-adapter seam is just indirection.
30+
- **Internal seams vs external seams.** A deep module can have internal seams (private to its implementation, used by its own tests) as well as the external seam at its interface. Don't expose internal seams through the interface just because tests use them.
31+
32+
## Testing strategy: replace, don't layer
33+
34+
- Old unit tests on shallow modules become waste once tests at the deepened module's interface exist — delete them.
35+
- Write new tests at the deepened module's interface. The **interface is the test surface**.
36+
- Tests assert on observable outcomes through the interface, not internal state.
37+
- Tests should survive internal refactors — they describe behaviour, not implementation. If a test has to change when the implementation changes, it's testing past the interface.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Design It Twice
2+
3+
When the user wants to explore alternative interfaces for a chosen deepening candidate, use this parallel sub-agent pattern. Based on "Design It Twice" (Ousterhout) — your first idea is unlikely to be the best.
4+
5+
Uses the vocabulary in [SKILL.md](SKILL.md) — **module**, **interface**, **seam**, **adapter**, **leverage**.
6+
7+
## Process
8+
9+
### 1. Frame the problem space
10+
11+
Before spawning sub-agents, write a user-facing explanation of the problem space for the chosen candidate:
12+
13+
- The constraints any new interface would need to satisfy
14+
- The dependencies it would rely on, and which category they fall into (see [DEEPENING.md](DEEPENING.md))
15+
- A rough illustrative code sketch to ground the constraints — not a proposal, just a way to make the constraints concrete
16+
17+
Show this to the user, then immediately proceed to Step 2. The user reads and thinks while the sub-agents work in parallel.
18+
19+
### 2. Spawn sub-agents
20+
21+
Spawn 3+ sub-agents in parallel. Each must produce a **radically different** interface for the deepened module.
22+
23+
Prompt each sub-agent with a separate technical brief (file paths, coupling details, dependency category from [DEEPENING.md](DEEPENING.md), what sits behind the seam). The brief is independent of the user-facing problem-space explanation in Step 1. Give each agent a different design constraint:
24+
25+
- Agent 1: "Minimize the interface — aim for 1–3 entry points max. Maximise leverage per entry point."
26+
- Agent 2: "Maximise flexibility — support many use cases and extension."
27+
- Agent 3: "Optimise for the most common caller — make the default case trivial."
28+
- Agent 4 (if applicable): "Design around ports & adapters for cross-seam dependencies."
29+
30+
Include both [SKILL.md](SKILL.md) vocabulary and CONTEXT.md vocabulary in the brief so each sub-agent names things consistently with the architecture language and the project's domain language.
31+
32+
Each sub-agent outputs:
33+
34+
1. Interface (types, methods, params — plus invariants, ordering, error modes)
35+
2. Usage example showing how callers use it
36+
3. What the implementation hides behind the seam
37+
4. Dependency strategy and adapters (see [DEEPENING.md](DEEPENING.md))
38+
5. Trade-offs — where leverage is high, where it's thin
39+
40+
### 3. Present and compare
41+
42+
Present designs sequentially so the user can absorb each one, then compare them in prose. Contrast by **depth** (leverage at the interface), **locality** (where change concentrates), and **seam placement**.
43+
44+
After comparing, give your own recommendation: which design you think is strongest and why. If elements from different designs would combine well, propose a hybrid. Be opinionated — the user wants a strong read, not a menu.

0 commit comments

Comments
 (0)