|
1 | 1 | --- |
2 | 2 | name: audit-widget |
3 | | -description: Audit one Mendix pluggable widget across seven categories (unit tests, e2e, performance, dependencies, code smells, missing behaviours, mx-docs drift) into a resumable AUDIT.md, then fix one category at a time, stopping after each for review and commit. |
| 3 | +description: Audit one Mendix pluggable widget and write a point-in-time report (AUDIT.md) on unit tests, e2e, performance, dependencies, security, code smells, missing behaviours and mx-docs drift. Report only — it never changes code. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Audit Widget |
7 | 7 |
|
8 | | -Two-phase, resumable health check for one widget package. Phase 1 produces a report; Phase 2 fixes it **one category at a time and stops**. |
9 | | - |
10 | | -The report file is the state machine. Everything needed to resume lives in it, so a fresh session can continue an audit it did not start. |
| 8 | +Writes a health report for **one** widget package. The skill reads code and runs read-only commands. The report is its only output. |
11 | 9 |
|
12 | 10 | ## Invocation |
13 | 11 |
|
14 | 12 | ``` |
15 | | -/audit-widget <widget> # Phase 1 — generate/refresh the report |
16 | | -/audit-widget <widget> fix # Phase 2 — fix the next pending category, then STOP |
17 | | -/audit-widget <widget> fix <category> # Phase 2 — fix a specific category, then STOP |
18 | | -/audit-widget <widget> skip <category> # mark a category skipped, change nothing else |
19 | | -/audit-widget <widget> status # print the category table, change nothing |
| 13 | +/audit-widget [<widget>] |
20 | 14 | ``` |
21 | 15 |
|
22 | | -`<widget>` is a folder name under `packages/pluggableWidgets/` (e.g. `combobox-web`) or `packages/modules/` (e.g. `data-widgets`). If it is missing or ambiguous, ask — do not guess. |
23 | | - |
24 | | -`<category>` is one of: `unit-tests`, `e2e-tests`, `performance`, `dependencies`, `smells`, `behaviours`, `docs`. |
25 | | - |
26 | | -**Mode resolution:** no mode word → Phase 1. If `AUDIT.md` already exists and Phase 1 is requested again, ask whether to refresh it (re-audit, preserving `fixed`/`skipped` statuses) or to switch to `fix`. |
| 16 | +`<widget>` is a folder name under `packages/pluggableWidgets/` (e.g. `combobox-web`). If it is missing or matches no folder, ask which widget. Do not guess. |
27 | 17 |
|
28 | | -## Scope discipline |
| 18 | +Every run is a fresh snapshot. If `AUDIT.md` already exists, replace it without reading it first: audit from scratch so old findings do not anchor the new ones. |
29 | 19 |
|
30 | | -- Audit **one package**. Read files under `packages/<type>/<widget>/` only. |
31 | | -- Follow findings into `@mendix/widget-plugin-*` / shared packages **only** when the widget's own code cannot explain a finding — and say so explicitly in the finding. Never fix shared-package code as part of a widget audit; raise it as a separate note. |
32 | | -- Dependency analysis uses **only that widget's `package.json`**. Never the root, never another package. |
33 | | -- Never touch `dist/`, generated files (`typings/*.d.ts`), or lockfiles. |
34 | | -- **The one exception is `docs`**: it reads — and in Phase 2 edits — the widget's page in the mx-docs repo. Resolve its location as `$MX_DOCS_PATH`, else `~/Projects/mx-docs`. If neither exists, mark `docs` as `skipped` with the reason in Notes; do not guess another path. Never edit any other mx-docs page than the widget's own (and its `_index.md` only if the page is a section). |
| 20 | +## Hard rules |
35 | 21 |
|
36 | | -## Phase 1 — Report |
| 22 | +- **The report is the only file you write.** Never edit source, tests, config, `package.json`, docs, or the mx-docs repo. Output that commands write on their own (Jest coverage) is fine. |
| 23 | +- **Install nothing.** Never run `pnpm install`, `pnpm add`, `pnpm up` or `pnpm audit --fix`, and never run a script that downloads a tool. They change `package.json` or `pnpm-lock.yaml`, and the repo does not allow lockfile changes. |
| 24 | +- **No git writes.** Never `git add`, commit, branch or push. The user decides what to do with the report. |
| 25 | +- **Stay in the package.** Read files under `packages/pluggableWidgets/<widget>/` only. Follow a finding into a shared `@mendix/widget-plugin-*` package only when the widget's own code cannot explain it, and record it in Notes, not as a widget finding. |
| 26 | +- **mx-docs is read-only.** Read it from `$MX_DOCS_PATH`, else `~/Projects/mx-docs`. If neither exists, skip `DOCS` and say why in Notes. |
37 | 27 |
|
38 | | -### 1. Orient (cheap, always do this first) |
| 28 | +## 1. Orient |
39 | 29 |
|
40 | 30 | ```bash |
41 | 31 | cd packages/pluggableWidgets/<widget> |
| 32 | +git rev-parse --short HEAD # record in the report header |
42 | 33 | ``` |
43 | 34 |
|
44 | 35 | Read, in this order: |
45 | 36 |
|
46 | | -1. `package.json` — deps, scripts, `widgetName`, `marketplace.minimumMXVersion` |
| 37 | +1. `package.json` — deps, scripts, `widgetName`, `marketplace` |
47 | 38 | 2. `AGENTS.md` if present — the widget's own architecture map, the highest-value context you will get |
48 | 39 | 3. `src/<WidgetName>.xml` — the property contract; this is the source of truth for expected behaviour |
49 | | -4. `CHANGELOG.md` — recent behaviour changes, unreleased entries |
| 40 | +4. `CHANGELOG.md` — recent behaviour changes |
50 | 41 | 5. `openspec/specs/**` and `openspec/changes/**` — declared requirements and in-flight work |
51 | 42 | 6. Inventory (do not read contents yet): |
52 | 43 | ```bash |
53 | 44 | find src -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.scss" \) | sort |
54 | 45 | find src -path "*__tests__*" -name "*.spec.*" | sort |
55 | 46 | ls e2e/*.spec.js |
56 | 47 | ``` |
57 | | -7. The mx-docs page for the widget — locate it now (lookup recipe in the `DOCS` section of [checklists.md](checklists.md)) and record its path in the report header. Do not read it in full yet. |
| 48 | +7. The mx-docs page for the widget — locate it with the recipe in the `DOCS` section of [checklists.md](checklists.md) and record its path. Do not read it in full yet. |
58 | 49 |
|
59 | | -### 2. Run the seven checks |
| 50 | +## 2. Run the eight checks |
60 | 51 |
|
61 | | -Detection heuristics for each live in [checklists.md](checklists.md). Read it now — it is the substance of this skill. |
| 52 | +Detection heuristics for each category are in [checklists.md](checklists.md). Read it now — it is the substance of this skill. |
62 | 53 |
|
63 | | -| Category | ID prefix | What it answers | |
64 | | -| ------------------ | --------- | ------------------------------------------------------------------- | |
65 | | -| Unit tests | `UT` | Which modules/branches/states have no Jest+RTL coverage? | |
66 | | -| E2E tests | `E2E` | Which user-visible flows have no Playwright spec, or a fragile one? | |
67 | | -| Performance | `PERF` | What causes avoidable renders, work-in-render, or leaks? | |
68 | | -| Dependencies | `DEP` | Patch/minor/major updates available for this widget's own deps | |
69 | | -| Code smells | `SMELL` | Violations of repo conventions, dead code, type escapes | |
70 | | -| Missing behaviours | `BEH` | XML/API/a11y contract the implementation does not honour | |
71 | | -| Public docs | `DOCS` | Where the mx-docs page disagrees with the XML, changelog, or code | |
| 54 | +| Category | ID prefix | What it answers | |
| 55 | +| ------------------ | --------- | ---------------------------------------------------------------------------- | |
| 56 | +| Unit tests | `UT` | Which modules/branches/states have no Jest+RTL coverage? | |
| 57 | +| E2E tests | `E2E` | Which user-visible flows have no Playwright spec, or a fragile one? | |
| 58 | +| Performance | `PERF` | What causes avoidable renders, work-in-render, or leaks? | |
| 59 | +| Dependencies | `DEP` | Which of this widget's own deps are outdated or have known advisories? | |
| 60 | +| Security | `SEC` | Where can untrusted data reach HTML, URLs, scripts or other dangerous sinks? | |
| 61 | +| Code smells | `SMELL` | Violations of repo conventions, dead code, type escapes | |
| 62 | +| Missing behaviours | `BEH` | XML/API/a11y contract the implementation does not honour | |
| 63 | +| Public docs | `DOCS` | Where the mx-docs page disagrees with the XML, changelog, or code | |
72 | 64 |
|
73 | | -Parallelising is allowed and encouraged here: dispatch one read-only `Explore` agent per category with the package path plus that category's section of `checklists.md`, then merge results. Keep `dependencies` for yourself — it needs a command run, not a search. |
| 65 | +If your agent supports read-only subagents (for example Claude Code's `Explore`), run one per category with the package path and that category's section of `checklists.md`, then merge the results. Run `DEP` yourself — it needs commands, not a search. |
74 | 66 |
|
75 | | -### 3. Verify before writing |
| 67 | +## 3. Verify before writing |
76 | 68 |
|
77 | 69 | Every finding must survive this filter, or it does not go in the report: |
78 | 70 |
|
79 | 71 | - **Evidence**: a `file:line` you actually read, or command output you actually ran. |
80 | | -- **Failure scenario**: concrete inputs/config → wrong or slow result. "Could be cleaner" is not a finding. |
| 72 | +- **Failure scenario**: concrete inputs/config → wrong, slow or unsafe result. "Could be cleaner" is not a finding. |
81 | 73 | - **Not already handled**: check the code path once more for the guard you are claiming is absent. |
82 | 74 | - **Not a shared-package concern** misattributed to the widget. |
83 | | -- **Not handled by a library**: when the finding depends on how a framework or library behaves (for example, a callback captured by `useEditor(..., [])`), read that library's code in `node_modules` before reporting it. `@tiptap/react` forwards callbacks to the latest options, which made a stale-callback finding in a Rich Text audit a false positive. |
84 | | -- **Critical needs proof**: report a finding as Critical only after a failing test or a runtime reproduction. Otherwise report it as High and add _needs repro_. |
| 75 | +- **Not handled by a library**: when the finding depends on how a framework or library behaves (for example, a callback captured by `useEditor(..., [])`), read that library's code in `node_modules` before reporting it. `@tiptap/react` forwards callbacks to the latest options, which once made a stale-callback finding a false positive. |
| 76 | +- **Critical needs proof**: report a finding as Critical only with proof you produced — a failing existing test, command output, or for a leaked secret the line itself. Otherwise report it as High and add _needs repro_. |
85 | 77 |
|
86 | 78 | Drop speculative findings silently. A short true report beats a long plausible one. |
87 | 79 |
|
88 | | -### 4. Write the report |
89 | | -
|
90 | | -Write to `packages/<type>/<widget>/AUDIT.md` using [report-template.md](report-template.md). Then print to the user: the category table, the finding counts per severity, and the 3 findings you would fix first. |
91 | | -
|
92 | | -**Stop there.** Phase 1 never edits source, never installs, never commits. |
93 | | -
|
94 | | -## Phase 2 — Fix, one category, then stop |
95 | | -
|
96 | | -### Order |
97 | | -
|
98 | | -`unit-tests` → `e2e-tests` → `performance` → `dependencies` → `smells` → `behaviours` → `docs` |
99 | | -
|
100 | | -Tests come first on purpose: they are the safety net for the later categories. `docs` comes last because the earlier categories can change behaviour the docs must then describe. If the user asks for a later category first, do it — but say in one line that the test net is not in place yet. |
101 | | -
|
102 | | -### Per-category loop |
103 | | -
|
104 | | -1. **Resolve the category.** Explicit arg wins; otherwise the first row in the table whose status is `pending`. If none are pending, report that the audit is complete and stop. |
105 | | -2. **Set status to `in-progress`** in `AUDIT.md`. |
106 | | -3. **Plan.** List the findings you will address, in order, and the ones you are deliberately leaving (with why). If the category has more than ~6 findings, propose a cut line and ask before starting — a 20-file change is not reviewable in one sitting. |
107 | | -4. **Fix.** Work finding by finding. Follow `AGENTS.md`, `docs/requirements/frontend-guidelines.md`, and for e2e work `docs/requirements/e2e-test-guidelines.md`. Prettier and ESLint run automatically on edit — do not invoke them manually. |
108 | | -5. **Verify.** From the package root: |
109 | | - - always: `pnpm run test`. To run a single spec, use `pnpm run test --testPathPatterns <name> --coverage=false`; a bare path argument does not filter, because the script is `jest --projects jest.config.js`. |
110 | | - - `unit-tests`: if a correct assertion fails because the widget is wrong, do not assert the broken behaviour and do not leave an `it.todo`. Add the bug to the report as a new finding (next free ID in the right category, marked _found by tests_) and leave the test out until the fix PR. |
111 | | - - `e2e-tests`: `pnpm run release` then `pnpm run e2e --no-setup-project`. If Docker or the test project is unavailable, say so plainly and leave the specs as written-but-unverified — do not claim a pass you did not see. |
112 | | - - `dependencies`: `pnpm run test` **and** `pnpm turbo build` |
113 | | - - `performance`, `behaviours`: `pnpm run test`; add or update a test that would have caught the issue |
114 | | - - `docs`: no widget command. Instead, before editing, confirm the mx-docs working tree is clean and not on its default branch (`development`); if it is, create a local branch `docs/<widget>-sync` — never edit on the default branch, never push. Edit following mx-docs `CLAUDE.md` and its style guide (it takes precedence over this repo's conventions inside mx-docs). Afterwards run `npx markdownlint-cli2 <page>` from the mx-docs root if available, and re-read every changed `{#anchor}` / URL with a grep for inbound references. |
115 | | -6. **Changelog.** If widget behaviour changed, add an entry under `## [Unreleased]` in the package `CHANGELOG.md`. User-facing wording only — no implementation detail. Do **not** bump the version. Pure test-only or dependency-only changes with no user-visible effect get no entry. `docs` never adds a widget changelog entry. |
116 | | -7. **Update `AUDIT.md`**: set each addressed finding's status to `fixed` (or `skipped` with a reason), set the category status to `done`, and append a line to the Log section: `<date> — <category> — N fixed, M skipped`. |
117 | | -8. **HALT.** |
118 | | -
|
119 | | -### The halt is the point |
120 | | -
|
121 | | -After one category, you are finished for this invocation. That means: |
122 | | -
|
123 | | -- Do **not** start the next category, even if it looks trivial or related. |
124 | | -- Do **not** `git add`, `git commit`, `git push`, or open a PR. The user commits. |
125 | | -- Do **not** ask "shall I continue?" — the user will invoke the skill again when ready. |
126 | | -
|
127 | | -Print exactly this shape and then end the turn: |
128 | | -
|
129 | | -``` |
130 | | -✅ <category> — N fixed, M skipped |
131 | | - <one line per fixed finding: ID — what changed, file> |
132 | | -
|
133 | | -Verification: <command run> → <result> |
134 | | -Next pending: <category> (K findings) |
135 | | -
|
136 | | -Suggested commit: |
137 | | -<type>(<widget>): <subject> |
138 | | -``` |
139 | | -
|
140 | | -Commit `type` by category: `unit-tests`/`e2e-tests` → `test`, `performance` → `perf`, `dependencies` → `chore`, `smells` → `refactor`, `behaviours` → `fix` or `feat`. Scope is the folder name (`combobox-web`). |
141 | | -
|
142 | | -For `docs` the commit lives in the **mx-docs** repo, not this one: print the mx-docs branch name and a plain subject line (mx-docs does not use conventional commits), e.g. `Combo box: document <prop>, sync Properties Pane with v2.4.0`. |
| 80 | +## 4. Write the report |
143 | 81 |
|
144 | | -## Resuming cold |
| 82 | +Write `packages/pluggableWidgets/<widget>/AUDIT.md` using [report-template.md](report-template.md). Then print to the user: the category table, the finding counts per severity, and the 3 findings you would fix first. |
145 | 83 |
|
146 | | -If `AUDIT.md` exists and you have no memory of writing it: trust it. Read it, read the widget's `AGENTS.md`, then act on the requested mode. Re-verify a finding's `file:line` before fixing it — the file may have moved since the report was written. If a finding no longer reproduces, mark it `stale` with a one-line note rather than inventing a fix. |
| 84 | +**Stop there.** |
0 commit comments