Skip to content

Commit 0c3a664

Browse files
chore(skills): make audit-widget report-only and add security checks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b0e4bc5 commit 0c3a664

4 files changed

Lines changed: 147 additions & 167 deletions

File tree

‎.agents/skills/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This directory contains all Claude Code skills for the web-widgets repository.
66

77
```
88
.agents/skills/
9-
├── audit-widget/ # Audit one widget (tests, perf, deps, smells, behaviours, docs) and fix by category
9+
├── audit-widget/ # Audit one widget into a report (tests, perf, deps, security, smells, behaviours, docs)
1010
├── code-review/ # PR review skill for Mendix widget conventions
1111
├── debug-widget/ # Debug Mendix pluggable widget runtime issues
1212
├── openspec-apply-change/ # Implement tasks from OpenSpec change
@@ -27,7 +27,7 @@ This directory contains all Claude Code skills for the web-widgets repository.
2727

2828
Skills are automatically loaded by Claude Code. Users can invoke them via slash commands:
2929

30-
- `/audit-widget <widget>` — Audit one widget into `AUDIT.md`, then `/audit-widget <widget> fix` one category at a time
30+
- `/audit-widget [widget]` — Audit one widget and write the report to its `AUDIT.md`
3131
- `/code-review` — Review current PR
3232
- `/debug-widget` — Debug widget runtime issues
3333
- `/openspec-*` or `/opsx:*` — OpenSpec workflow commands
Lines changed: 36 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,84 @@
11
---
22
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.
44
---
55

66
# Audit Widget
77

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.
119

1210
## Invocation
1311

1412
```
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>]
2014
```
2115

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.
2717

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.
2919

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
3521

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.
3727

38-
### 1. Orient (cheap, always do this first)
28+
## 1. Orient
3929

4030
```bash
4131
cd packages/pluggableWidgets/<widget>
32+
git rev-parse --short HEAD # record in the report header
4233
```
4334

4435
Read, in this order:
4536

46-
1. `package.json` — deps, scripts, `widgetName`, `marketplace.minimumMXVersion`
37+
1. `package.json` — deps, scripts, `widgetName`, `marketplace`
4738
2. `AGENTS.md` if present — the widget's own architecture map, the highest-value context you will get
4839
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
5041
5. `openspec/specs/**` and `openspec/changes/**` — declared requirements and in-flight work
5142
6. Inventory (do not read contents yet):
5243
```bash
5344
find src -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.scss" \) | sort
5445
find src -path "*__tests__*" -name "*.spec.*" | sort
5546
ls e2e/*.spec.js
5647
```
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.
5849

59-
### 2. Run the seven checks
50+
## 2. Run the eight checks
6051

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.
6253

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 |
7264
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.
7466
75-
### 3. Verify before writing
67+
## 3. Verify before writing
7668
7769
Every finding must survive this filter, or it does not go in the report:
7870
7971
- **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.
8173
- **Not already handled**: check the code path once more for the guard you are claiming is absent.
8274
- **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_.
8577

8678
Drop speculative findings silently. A short true report beats a long plausible one.
8779

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
14381

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.
14583

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

Comments
 (0)