ultra11y 5.56.2 → 5.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@
10
10
  "name": "ultra11y",
11
11
  "source": "./",
12
12
  "description": "RGAA 4.1.2 accessibility audits on a WCAG 2.2 AA core: automatic review before commit, push and pull request, plus dated, evidenced Markdown, HTML and per-page conformance reports in Claude Code.",
13
- "version": "5.56.2",
13
+ "version": "5.57.1",
14
14
  "author": { "name": "maxgfr" },
15
15
  "homepage": "https://github.com/SocialGouv/ultra11y",
16
16
  "repository": "https://github.com/SocialGouv/ultra11y",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ultra11y",
3
3
  "description": "RGAA 4.1.2 accessibility audits, the French State's standard, on a WCAG 2.2 AA core: automatic review before commit, push and pull request, plus dated, evidenced Markdown, HTML and per-page conformance reports. Never declares conforming what it has not verified.",
4
- "version": "5.56.2",
4
+ "version": "5.57.1",
5
5
  "author": { "name": "maxgfr" },
6
6
  "homepage": "https://github.com/SocialGouv/ultra11y",
7
7
  "repository": "https://github.com/SocialGouv/ultra11y",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ultra11y",
3
3
  "description": "RGAA 4.1.2 accessibility audits, the French State's standard, on a WCAG 2.2 AA core: automatic review before commit, push and pull request, plus dated, evidenced Markdown, HTML and per-page conformance reports. Never declares conforming what it has not verified.",
4
- "version": "5.56.2",
4
+ "version": "5.57.1",
5
5
  "author": { "name": "maxgfr", "url": "https://github.com/maxgfr" },
6
6
  "homepage": "https://github.com/SocialGouv/ultra11y",
7
7
  "repository": "https://github.com/SocialGouv/ultra11y",
@@ -7,27 +7,46 @@
7
7
  // the cost of a string test on each shell call, and the 2.5 MB engine is spawned only once
8
8
  // something could possibly be a publishing command.
9
9
  //
10
+ // ONE FILE, BOTH MAJORS. OpenCode 1 and OpenCode 2 read different things from this module:
11
+ //
12
+ // - OpenCode 2 reads the default export's `{ id, setup(ctx) }` and nothing else. `setup`
13
+ // registers the gate with `ctx.tool.hook("execute.before")` and the two skills with
14
+ // `ctx.skill.transform`.
15
+ // - OpenCode 1 ≥ 1.18.28 sees a default object carrying `server()` and calls ONLY that —
16
+ // the named exports are then ignored, so the gate is registered once.
17
+ // - Older OpenCode 1 calls every export that is a function (or an object's `server`), so
18
+ // it reaches the same `Ultra11yPlugin` twice. `oncePerCall` below makes the second
19
+ // registration a no-op on the same tool call, so the engine still runs once per call.
20
+ //
21
+ // The module therefore exports FUNCTIONS ONLY besides `default`: an old V1 loader throws
22
+ // "Plugin export is not a function" on any other value, and that kills the whole plugin.
23
+ //
10
24
  // TWO RULES, the same two that govern src/hook.ts.
11
25
  //
12
26
  // 1. NEVER break a session. Every unexpected condition — no engine, spawn failure,
13
- // timeout, unreadable output — is a silent no-op. The single `throw` below is our own
14
- // decision and nothing else; note that the try/catch closes BEFORE it, so a bug in here
15
- // can never surface to the user as a blocked `git push`.
27
+ // timeout, unreadable output, a host API that is missing or shaped differently — is a
28
+ // silent no-op. The single `throw` in each entry point is our own decision and nothing
29
+ // else; the try/catch closes BEFORE it, so a bug in here can never surface to the user
30
+ // as a blocked `git push`.
16
31
  // 2. NEVER loop. The anti-loop marker lives in the engine (loopKey/firstSighting in
17
32
  // src/hook.ts) and keys on the session id, so passing OpenCode's sessionID through is
18
33
  // all that is required: one review per state of the change, exactly as on Claude Code.
19
34
  //
20
- // Zero dependencies, `node:` builtins only — it is loaded straight from disk by OpenCode.
35
+ // Zero dependencies, `node:` builtins only — it is loaded straight from disk by OpenCode,
36
+ // and OpenCode 2 refuses to resolve `@opencode/plugin` from a plugin's own node_modules.
21
37
  import { spawnSync } from "node:child_process";
22
- import { existsSync } from "node:fs";
38
+ import { existsSync, readFileSync } from "node:fs";
23
39
  import { homedir } from "node:os";
24
- import { dirname, join } from "node:path";
40
+ import { dirname, isAbsolute, join } from "node:path";
25
41
  import { fileURLToPath } from "node:url";
26
42
 
27
43
  // Ownership marker: `ultra11y install --opencode` refuses to overwrite a plugin file that
28
- // does not carry it, so a user's own ultra11y.js is never clobbered.
44
+ // does not carry it, so a user's own ultra11y.js is never clobbered. Kept as text, not as
45
+ // an export (see above).
29
46
  const ULTRA11Y_OPENCODE_PLUGIN = "ULTRA11Y_OPENCODE_PLUGIN";
30
- const ULTRA11Y_PLUGIN_VERSION = "5.56.2";
47
+ const ULTRA11Y_PLUGIN_VERSION = "5.57.1";
48
+ const PLUGIN_ID = "ultra11y";
49
+ const SKILL_NAMES = ["ultra11y", "review-a11y"];
31
50
 
32
51
  const here = dirname(fileURLToPath(import.meta.url));
33
52
 
@@ -44,12 +63,117 @@ function resolveEngine() {
44
63
  return null;
45
64
  }
46
65
 
66
+ /** The directory holding the two skills, or null: the package's own `skills/` on the
67
+ * npm/checkout route, or `<configDir>/skills/` where `install --opencode` copies them. */
68
+ function resolveSkillsDir() {
69
+ for (const d of [join(here, "..", "..", "skills"), join(here, "..", "skills")]) {
70
+ if (SKILL_NAMES.every((n) => existsSync(join(d, n, "SKILL.md")))) return d;
71
+ }
72
+ return null;
73
+ }
74
+
75
+ /** The Node to run the engine with. Inside OpenCode `process.execPath` is NOT node: both
76
+ * majors ship as a Bun-compiled binary, and `<opencode> engine.mjs hook` prints
77
+ * OpenCode's own CLI help — which would then be thrown at the agent as a "finding". So
78
+ * under Bun the engine runs on the `node` from PATH; a missing node is a spawn error,
79
+ * and a spawn error is silence (rule 1). */
80
+ function nodeRuntime() {
81
+ if (process.env.ULTRA11Y_NODE) return process.env.ULTRA11Y_NODE;
82
+ return process.versions?.bun ? "node" : process.execPath;
83
+ }
84
+
85
+ /** Every block the engine emits starts with this (src/hook.ts). Anything else on stdout is
86
+ * not a decision of ours, and blocking a `git push` with it would break the session. */
87
+ const DECISION_PREFIX = "ultra11y:";
88
+
47
89
  /** Same literal as hooks/pre-tool-use.mjs — tests/harness-sync.test.ts asserts they match,
48
90
  * because two prefilters that disagree mean one harness silently reviews less. */
49
91
  const PREFILTER = /\bgit\b|\bgh\b/;
50
92
 
93
+ /** `bash` on both majors; `shell` is accepted too, should a release rename it. */
94
+ const isShell = (tool) => /^(?:bash|shell)$/i.test(String(tool ?? ""));
95
+
96
+ /**
97
+ * The decision, shared by both entry points: the text to block with, or "" to let the call
98
+ * through. NEVER throws — rule 1 — whatever the host hands in.
99
+ */
100
+ function review({ tool, args, directory, sessionID }) {
101
+ try {
102
+ if (!isShell(tool)) return "";
103
+ const command = args?.command;
104
+ if (typeof command !== "string" || !PREFILTER.test(command)) return "";
105
+ if (process.env.SKIP_A11Y || process.env.ULTRA11Y_HOOK === "off") return "";
106
+
107
+ const engine = resolveEngine();
108
+ if (!engine) return "";
109
+
110
+ // A `workdir` argument is where the command really runs; otherwise the plugin's own
111
+ // location is the best answer the host gives.
112
+ const workdir = typeof args?.workdir === "string" && isAbsolute(args.workdir) ? args.workdir : null;
113
+ const payload = {
114
+ tool_name: "Bash",
115
+ tool_input: { command },
116
+ cwd: workdir ?? (typeof directory === "string" && directory ? directory : process.cwd()),
117
+ session_id: typeof sessionID === "string" && sessionID ? sessionID : `opencode-${process.pid}`,
118
+ };
119
+ const run = spawnSync(nodeRuntime(), [engine, "hook", "--opencode"], {
120
+ input: JSON.stringify(payload),
121
+ encoding: "utf8",
122
+ timeout: 20_000,
123
+ maxBuffer: 8 * 1024 * 1024,
124
+ });
125
+ if (run.error || run.status !== 0) return "";
126
+ const text = (run.stdout ?? "").trim();
127
+ return text.startsWith(DECISION_PREFIX) ? text : "";
128
+ } catch {
129
+ return ""; // unreadable input, spawn failure, timeout — say nothing
130
+ }
131
+ }
132
+
133
+ /** Tool-call ids already reviewed. An old OpenCode 1 can register this plugin twice from
134
+ * one module (named export + default `server`); the second hook must not run the engine
135
+ * again on the same call. Bounded, and best-effort: no id means no de-duplication. */
136
+ const seenCalls = new Set();
137
+ function oncePerCall(callID) {
138
+ if (typeof callID !== "string" || !callID) return true;
139
+ if (seenCalls.has(callID)) return false;
140
+ seenCalls.add(callID);
141
+ if (seenCalls.size > 512) seenCalls.delete(seenCalls.values().next().value);
142
+ return true;
143
+ }
144
+
145
+ /** Read one bundled SKILL.md into the shape OpenCode 2's skill editor takes. The ids and
146
+ * names are branded strings in @opencode/schema, but the brand is type-only — a plain
147
+ * string is what the host stores. Null on anything unexpected. */
148
+ function readSkill(dir, name) {
149
+ try {
150
+ const path = join(dir, name, "SKILL.md");
151
+ const text = readFileSync(path, "utf8");
152
+ const fm = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
153
+ if (!fm) return null;
154
+ const field = (key) => {
155
+ const m = new RegExp(`^${key}:[ \\t]*(.*)$`, "m").exec(fm[1]);
156
+ if (!m) return undefined;
157
+ const raw = m[1].trim();
158
+ if (raw.startsWith('"')) {
159
+ try {
160
+ return JSON.parse(raw);
161
+ } catch {
162
+ return raw.slice(1, -1);
163
+ }
164
+ }
165
+ return raw;
166
+ };
167
+ const id = field("name") || name;
168
+ return { id, name: id, description: field("description"), path, content: text.slice(fm[0].length).trim() };
169
+ } catch {
170
+ return null;
171
+ }
172
+ }
173
+
174
+ /** OpenCode 1 — the plugin function. Also what `server()` returns for V1 ≥ 1.18.28. */
51
175
  export const Ultra11yPlugin = async (ctx) => {
52
- const skillsDir = join(here, "..", "..", "skills");
176
+ const directory = ctx?.directory ?? ctx?.worktree;
53
177
 
54
178
  return {
55
179
  /** Register the two bundled skills so `review-a11y` is invocable by name once the gate
@@ -57,7 +181,8 @@ export const Ultra11yPlugin = async (ctx) => {
57
181
  * the user still has the skills via `ultra11y install --opencode`. */
58
182
  config: async (config) => {
59
183
  try {
60
- if (!existsSync(skillsDir)) return;
184
+ const skillsDir = resolveSkillsDir();
185
+ if (!skillsDir) return;
61
186
  config.skills ??= {};
62
187
  config.skills.paths ??= [];
63
188
  if (!config.skills.paths.includes(skillsDir)) config.skills.paths.push(skillsDir);
@@ -67,31 +192,12 @@ export const Ultra11yPlugin = async (ctx) => {
67
192
  },
68
193
 
69
194
  "tool.execute.before": async (input, output) => {
70
- let text;
195
+ let text = "";
71
196
  try {
72
- if (String(input?.tool ?? "").toLowerCase() !== "bash") return;
73
- const command = output?.args?.command;
74
- if (typeof command !== "string" || !PREFILTER.test(command)) return;
75
- if (process.env.SKIP_A11Y || process.env.ULTRA11Y_HOOK === "off") return;
76
-
77
- const engine = resolveEngine();
78
- if (!engine) return;
79
-
80
- const payload = {
81
- tool_name: "Bash",
82
- tool_input: { command },
83
- cwd: ctx?.directory ?? ctx?.worktree ?? process.cwd(),
84
- session_id: input?.sessionID ?? `opencode-${process.pid}`,
85
- };
86
- const run = spawnSync(process.execPath, [engine, "hook", "--opencode"], {
87
- input: JSON.stringify(payload),
88
- encoding: "utf8",
89
- timeout: 20_000,
90
- maxBuffer: 8 * 1024 * 1024,
91
- });
92
- text = (run.stdout ?? "").trim();
197
+ if (!isShell(input?.tool) || !oncePerCall(input?.callID)) return;
198
+ text = review({ tool: input?.tool, args: output?.args, directory, sessionID: input?.sessionID });
93
199
  } catch {
94
- return; // unreadable input, spawn failure, timeout — say nothing
200
+ return;
95
201
  }
96
202
  // Outside the try on purpose: this is the ONLY error allowed to reach the agent.
97
203
  if (text) throw new Error(text);
@@ -99,4 +205,65 @@ export const Ultra11yPlugin = async (ctx) => {
99
205
  };
100
206
  };
101
207
 
102
- export { ULTRA11Y_OPENCODE_PLUGIN, ULTRA11Y_PLUGIN_VERSION };
208
+ /** OpenCode 2 — `setup(ctx)`. Each registration is independent and individually wrapped:
209
+ * a host without `ctx.skill` still gets the gate, and the reverse. The registrations are
210
+ * disposed with the plugin's scope; the returned cleanup only makes that explicit. */
211
+ async function setup(ctx) {
212
+ const registrations = [];
213
+ const keep = (r) => {
214
+ if (r && typeof r.dispose === "function") registrations.push(r);
215
+ };
216
+ const directory = ctx?.location?.directory ?? ctx?.location?.project?.directory;
217
+
218
+ try {
219
+ const skillsDir = resolveSkillsDir();
220
+ const skills = skillsDir ? SKILL_NAMES.map((n) => readSkill(skillsDir, n)).filter(Boolean) : [];
221
+ // Read once here: transform callbacks must be synchronous and replayable.
222
+ if (skills.length > 0 && typeof ctx?.skill?.transform === "function") {
223
+ keep(
224
+ await ctx.skill.transform((editor) => {
225
+ try {
226
+ // A copy the user installed under ~/.config/opencode/skills/ wins over ours.
227
+ for (const s of skills) if (!editor.get(s.id)) editor.add({ ...s });
228
+ } catch {
229
+ /* a registry that rejects us leaves the session as it was */
230
+ }
231
+ }),
232
+ );
233
+ }
234
+ } catch {
235
+ /* the skills are a convenience; never fail the plugin over them */
236
+ }
237
+
238
+ try {
239
+ if (typeof ctx?.tool?.hook === "function") {
240
+ keep(
241
+ await ctx.tool.hook("execute.before", async (event) => {
242
+ let text = "";
243
+ try {
244
+ text = review({ tool: event?.tool, args: event?.input, directory, sessionID: event?.sessionID });
245
+ } catch {
246
+ return;
247
+ }
248
+ // Outside the try on purpose: this is the ONLY error allowed to reach the agent.
249
+ if (text) throw new Error(text);
250
+ }),
251
+ );
252
+ }
253
+ } catch {
254
+ /* no gate is better than a broken session */
255
+ }
256
+
257
+ return async () => {
258
+ for (const r of registrations.splice(0)) {
259
+ try {
260
+ await r.dispose();
261
+ } catch {
262
+ /* already gone */
263
+ }
264
+ }
265
+ };
266
+ }
267
+
268
+ /** The entry both majors read: `setup` for OpenCode 2, `server` for OpenCode 1 ≥ 1.18.28. */
269
+ export default { id: PLUGIN_ID, setup, server: Ultra11yPlugin };
package/README.md CHANGED
@@ -17,7 +17,7 @@ pull request — you never type the skill's name:
17
17
  |---|---|
18
18
  | **Claude Code** | `/plugin marketplace add SocialGouv/ultra11y` then `/plugin install ultra11y@ultra11y` |
19
19
  | **OpenAI Codex CLI** | `codex plugin marketplace add SocialGouv/ultra11y` then `codex plugin add ultra11y@ultra11y` |
20
- | **OpenCode** | `npx ultra11y install --opencode` — or pin `"plugin": ["ultra11y@latest"]` in `opencode.json` |
20
+ | **OpenCode** 1.x and 2.x | `npx ultra11y install --opencode` — or pin `"plugins": ["ultra11y@latest"]` in `opencode.json` (OpenCode 1: `"plugin"`) |
21
21
  | **Anything else** | `npx ultra11y install --agents-md` (no hook API: see the caveat below) |
22
22
 
23
23
  <sub>Prefer the skills only, without the automatic hook? `npx skills add SocialGouv/ultra11y`
@@ -87,14 +87,15 @@ so `review-a11y` runs before the work goes out — you never type the skill's na
87
87
  ```
88
88
  /plugin marketplace add SocialGouv/ultra11y # Claude Code
89
89
  codex plugin marketplace add SocialGouv/ultra11y # Codex CLI
90
- npx ultra11y install --opencode # OpenCode
90
+ npx ultra11y install --opencode # OpenCode 1.x or 2.x (detected; --opencode-version 1|2)
91
91
  ```
92
92
 
93
93
  Codex's hook engine is a near-clone of Claude Code's — same events, same envelope, and it
94
94
  exports `${CLAUDE_PLUGIN_ROOT}` too — so both harnesses share one `hooks/hooks.json`.
95
- OpenCode has no permission-decision channel, so there the gate surfaces as a **failed bash
96
- call whose error message carries the findings**. Per-harness deltas, the Codex feature flag
97
- and the trust prompt: [`skills/ultra11y/references/harnesses.md`](skills/ultra11y/references/harnesses.md).
95
+ OpenCode has no permission-decision channel, so there the gate surfaces as a **failed shell
96
+ call whose error message carries the findings**. One plugin file serves OpenCode 1 and
97
+ OpenCode 2, whose plugin APIs differ: V2 reads its `setup(ctx)`, V1 its `server()`.
98
+ Per-harness deltas, the Codex feature flag and the trust prompt: [`skills/ultra11y/references/harnesses.md`](skills/ultra11y/references/harnesses.md).
98
99
 
99
100
  Four things worth knowing, because they bound what "automatic" means here:
100
101
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultra11y",
3
- "version": "5.56.2",
3
+ "version": "5.57.1",
4
4
  "description": "Audit d'accessibilité RGAA 4.1.2, le référentiel de l'État : rapport daté, grille des 106 critères, backlog et tickets. Moteur statique, navigateur et jugement IA contre-vérifié. Il ne déclare jamais conforme ce qu'il n'a pas vérifié. Socle WCAG 2.2 AA.",
5
5
  "homepage": "https://socialgouv.github.io/ultra11y/",
6
6
  "type": "module",
@@ -10,6 +10,7 @@
10
10
  },
11
11
  "exports": {
12
12
  ".": "./.opencode/plugins/ultra11y.js",
13
+ "./server": "./.opencode/plugins/ultra11y.js",
13
14
  "./playwright": {
14
15
  "types": "./dist/playwright.d.ts",
15
16
  "import": "./dist/playwright.mjs",
@@ -50,6 +51,7 @@
50
51
  "test:coverage": "vitest run --coverage",
51
52
  "test:perf": "vitest run --config vitest.perf.config.ts",
52
53
  "test:browser": "vitest run --config vitest.browser.config.ts",
54
+ "test:opencode": "vitest run --config vitest.opencode.config.ts",
53
55
  "bench": "node scripts/bench.mjs",
54
56
  "typecheck": "tsc --noEmit",
55
57
  "lint": "biome ci .",