@r_masseater/oxlint-plugin-decision 0.5.1 → 0.7.0
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.
- package/README.md +23 -395
- package/dist/app-Bso1uwY5.mjs +662 -0
- package/dist/app-Bso1uwY5.mjs.map +1 -0
- package/dist/cloudflare-worker.mjs +6 -179
- package/dist/cloudflare-worker.mjs.map +1 -1
- package/dist/decision-BtTZ52be.mjs +643 -0
- package/dist/decision-BtTZ52be.mjs.map +1 -0
- package/dist/define-presets-clyqLZxo.mjs +550 -0
- package/dist/define-presets-clyqLZxo.mjs.map +1 -0
- package/dist/index-BOrpK3Iv.d.mts +89 -0
- package/dist/index-Cgg-w0hb.d.mts +3370 -0
- package/dist/index-D7VrRpTx.d.mts +6 -0
- package/dist/index.d.mts +3 -3372
- package/dist/index.mjs +1 -786
- package/dist/openrouter-app.d.mts +12 -4
- package/dist/openrouter-app.mjs +1 -87
- package/dist/openrouter-worker.mjs +5 -35
- package/dist/openrouter-worker.mjs.map +1 -1
- package/dist/preset-plugin-AAwedMeS.mjs +10 -0
- package/dist/preset-plugin-AAwedMeS.mjs.map +1 -0
- package/dist/presets/ai-slop.d.mts +6 -0
- package/dist/presets/ai-slop.mjs +10 -0
- package/dist/presets/ai-slop.mjs.map +1 -0
- package/dist/presets/index.d.mts +3 -0
- package/dist/presets/index.mjs +3 -0
- package/dist/presets/recommended.d.mts +5 -0
- package/dist/presets/recommended.mjs +7 -0
- package/dist/presets/recommended.mjs.map +1 -0
- package/dist/presets/review-only.d.mts +5 -0
- package/dist/presets/review-only.mjs +7 -0
- package/dist/presets/review-only.mjs.map +1 -0
- package/dist/presets/strict.d.mts +5 -0
- package/dist/presets/strict.mjs +7 -0
- package/dist/presets/strict.mjs.map +1 -0
- package/dist/serve-decisions-CjlhvYm7.mjs +290 -0
- package/dist/serve-decisions-CjlhvYm7.mjs.map +1 -0
- package/package.json +25 -3
- package/skills/write-decision-rules/SKILL.md +18 -17
- package/skills/write-decision-rules/references/tuning.md +1 -1
- package/dist/index.mjs.map +0 -1
- package/dist/openrouter-app.mjs.map +0 -1
- package/dist/runtime-CICpEidL.mjs +0 -271
- package/dist/runtime-CICpEidL.mjs.map +0 -1
- package/dist/serve-decisions-cQpGj_Fq.mjs +0 -112
- package/dist/serve-decisions-cQpGj_Fq.mjs.map +0 -1
- package/dist/wire-CRD1mSAo.mjs +0 -251
- package/dist/wire-CRD1mSAo.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
> [!WARNING]
|
|
4
4
|
> This package is experimental. Use at your own risk.
|
|
5
5
|
|
|
6
|
-
[Oxlint](https://oxc.rs/docs/guide/usage/linter.html) rules written in plain English, answered by
|
|
6
|
+
[Oxlint](https://oxc.rs/docs/guide/usage/linter.html) rules written in plain English, answered by decision models.
|
|
7
|
+
The default is [Clef](https://developers.cloudflare.com/workers-ai/models/clef-flash/) on Workers AI through [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/).
|
|
8
|
+
Jev on [OpenRouter](https://openrouter.ai) also works.
|
|
9
|
+
It never asks a chat model.
|
|
7
10
|
|
|
8
11
|
A rule is a question about a function, a call, a JSX element or a whole file. Each match is sent to one or more decision models with the question. The plugin reports an error when the answer the rule cares about clears its cutoff.
|
|
9
12
|
|
|
10
13
|
Decision models do not write text. They return a probability for a yes/no question, or pick one of the options you list. That makes them fast and cheap enough to run over a codebase. It is also why every rule here is a question with a fixed set of answers.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
This is a fork of [oxlint-plugin-jev](https://github.com/wobsoriano/oxlint-plugin-jev) by [Robert Soriano](https://github.com/wobsoriano). It asks Cloudflare AI Gateway or the OpenRouter Decisions API.
|
|
15
|
+
This is a fork of [oxlint-plugin-jev](https://github.com/wobsoriano/oxlint-plugin-jev) by [Robert Soriano](https://github.com/wobsoriano). It asks Clef on Workers AI or the OpenRouter Decisions API.
|
|
15
16
|
|
|
16
17
|
## Install
|
|
17
18
|
|
|
@@ -21,15 +22,11 @@ export CLOUDFLARE_ACCOUNT_ID="..."
|
|
|
21
22
|
export CLOUDFLARE_API_TOKEN="..." # an account API token with Workers AI Read
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
The default model runs on Workers AI
|
|
25
|
-
|
|
26
|
-
Requests go to the gateway named `default`, which Cloudflare creates on the first request. `CLOUDFLARE_AI_GATEWAY_ID` picks another gateway. Its cache, logs and rate limits apply to every request.
|
|
27
|
-
|
|
28
|
-
In CI (when the `CI` environment variable is set), a run that could not reach a model fails instead of passing quietly. Set `ci: "skip"` to only warn there too. A provider that refuses for a spent budget only warns, even in CI. That is HTTP 402, or a 403 that names the budget.
|
|
25
|
+
The default model, `cloudflare/@cf/cloudflare/clef-flash`, runs on Workers AI and needs no other key. The `cloudflare` provider accepts only Clef decision models and refuses any other Workers AI model. Without the two variables, the plugin warns once and reports nothing.
|
|
29
26
|
|
|
30
27
|
## Write your rules
|
|
31
28
|
|
|
32
|
-
The plugin ships no rules of its own. You write each rule with `defineDecisionRule` in a plugin file of your own and pass the rules to `createDecisionPlugin`. Then you load that file from `oxlint.config.ts`. For ready-made rules, use [
|
|
29
|
+
The plugin ships no rules of its own. You write each rule with `defineDecisionRule` in a plugin file of your own and pass the rules to `createDecisionPlugin`. Then you load that file from `oxlint.config.ts`. For ready-made rules, use a [preset](#use-a-preset).
|
|
33
30
|
|
|
34
31
|
```js
|
|
35
32
|
// decision-plugin.mjs
|
|
@@ -74,407 +71,38 @@ export default defineConfig({
|
|
|
74
71
|
|
|
75
72
|
The rules you turn on share one request per file and model, so turning on more rules does not add requests.
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
| Field | What it is |
|
|
80
|
-
| ---------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
81
|
-
| `id` | The oxlint rule name after `<plugin name>/`. Lowercase words joined by hyphens, unique in the plugin. |
|
|
82
|
-
| `target` | `"function"`, `"call"`, `"jsx"`, or `"file"`. |
|
|
83
|
-
| `question` | The question, in English. With the default answer kind, "yes" means "report this". |
|
|
84
|
-
| `cutoff` | 0.8 to 1. The probability the reported answer needs, at or above. |
|
|
85
|
-
| `message` | Optional. A short sentence the error shows instead of the question. |
|
|
86
|
-
| `select` | Optional. A function of the AST node that says whether to ask about it. See [Selecting matches](#selecting-matches). |
|
|
87
|
-
| `answer` | Optional. What kind of answer to ask for. See [Answers](#answers). Defaults to `{ kind: "boolean" }`. |
|
|
88
|
-
| `context` | Optional. Extra source the model reads around the match. See [Context](#context). |
|
|
89
|
-
| `model` | Optional. Overrides the plugin's `model` for this rule. See [Rule options](#rule-options). |
|
|
90
|
-
| `location` | Optional for file rules: a source-location `question` and a `cutoff` from 0.8 to 1. |
|
|
91
|
-
|
|
92
|
-
`target` decides what the model gets to read. There is no selector syntax and no other target; `select` narrows a target down by looking at the AST.
|
|
93
|
-
|
|
94
|
-
| Target | The model sees | The error underlines |
|
|
95
|
-
| ------------ | ------------------------------------------------------------------------------------------------------------ | -------------------- |
|
|
96
|
-
| `"function"` | The whole function. An arrow or method includes its name, so `const getUser = () => ...` reads as `getUser`. | The signature line |
|
|
97
|
-
| `"call"` | The whole call expression. | The whole call |
|
|
98
|
-
| `"jsx"` | The whole element, children included. | The opening tag |
|
|
99
|
-
| `"file"` | The whole file. | The first line |
|
|
100
|
-
|
|
101
|
-
The wording of the question is the rule, so be precise about what counts. "Does this send personal data" also fires on a legitimate `mailer.send(user.email, ...)`. "To a log or console" does not.
|
|
102
|
-
|
|
103
|
-
### Selecting matches
|
|
104
|
-
|
|
105
|
-
`select` decides from the AST which matches are worth a question, before any request is sent. It gets the matched ESTree node, as oxlint parsed it, and returns `true` to ask about it. Matches it rejects cost nothing.
|
|
106
|
-
|
|
107
|
-
The second argument carries `context` and `name`. `context` is the oxlint rule context. `name` is the match's name as source text, or `undefined` when it has none.
|
|
108
|
-
|
|
109
|
-
| Target | `name` |
|
|
110
|
-
| ------------ | --------------------------------------------------------------------------- |
|
|
111
|
-
| `"function"` | The function's own name, or the binding, property, or method that holds it. |
|
|
112
|
-
| `"call"` | The callee as written, such as `console.error` or `it.only`. |
|
|
113
|
-
| `"jsx"` | The tag name, such as `Button` or `motion.div`. |
|
|
114
|
-
| `"file"` | Always `undefined`. |
|
|
115
|
-
|
|
116
|
-
```js
|
|
117
|
-
defineDecisionRule({
|
|
118
|
-
id: "pure-name-is-pure",
|
|
119
|
-
target: "function",
|
|
120
|
-
select: (node, { name }) => name !== undefined && name.startsWith("compute"),
|
|
121
|
-
question:
|
|
122
|
-
"This function's name presents it as a pure computation, but its body changes state outside itself or performs I/O.",
|
|
123
|
-
message: "The name promises a pure computation, but the body has side effects.",
|
|
124
|
-
cutoff: 0.8,
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
defineDecisionRule({
|
|
128
|
-
id: "test-proves-its-name",
|
|
129
|
-
target: "call",
|
|
130
|
-
select: (node) =>
|
|
131
|
-
node.type === "CallExpression" &&
|
|
132
|
-
node.callee.type === "Identifier" &&
|
|
133
|
-
["it", "test"].includes(node.callee.name),
|
|
134
|
-
question: "Would this test still pass if the behaviour its name claims were broken?",
|
|
135
|
-
cutoff: 0.8,
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Answers
|
|
140
|
-
|
|
141
|
-
Pick a kind. You never write a schema.
|
|
142
|
-
|
|
143
|
-
| Kind | The model is asked | Reported when |
|
|
144
|
-
| ------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
145
|
-
| `boolean` (default) | The probability that the answer is yes. | That probability is at or above `cutoff`. |
|
|
146
|
-
| `classify` | To pick one of the `labels` you list. | The chosen label is in `report` and its probability is at or above `cutoff`. |
|
|
147
|
-
| `severity` | To rate the problem as none, info, warn, or error. | The rating is at or above `minimum` (default `"warn"`) and clears `cutoff`. |
|
|
74
|
+
## Use a preset
|
|
148
75
|
|
|
149
|
-
|
|
150
|
-
defineDecisionRule({
|
|
151
|
-
id: "stale-comment",
|
|
152
|
-
target: "function",
|
|
153
|
-
question: "How does the comment right above this function relate to what the function does?",
|
|
154
|
-
cutoff: 0.8,
|
|
155
|
-
context: { scope: "lines", before: 5, after: 0 },
|
|
156
|
-
answer: {
|
|
157
|
-
kind: "classify",
|
|
158
|
-
labels: {
|
|
159
|
-
accurate: "The comment describes what the code does",
|
|
160
|
-
stale: "The comment describes behavior the code no longer has",
|
|
161
|
-
redundant: "The comment repeats the code without adding anything",
|
|
162
|
-
},
|
|
163
|
-
report: ["stale"],
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
```js
|
|
169
|
-
defineDecisionRule({
|
|
170
|
-
id: "security-smell",
|
|
171
|
-
target: "function",
|
|
172
|
-
question: "Does this function handle untrusted input in a way that could be exploited?",
|
|
173
|
-
cutoff: 0.8,
|
|
174
|
-
answer: { kind: "severity", minimum: "warn" },
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
The message names the answer: `[stale-comment] openrouter/... answered stale (0.91 >= 0.70): ...`.
|
|
179
|
-
|
|
180
|
-
### Context
|
|
181
|
-
|
|
182
|
-
By default the model reads only the match. `context` sends more source with it, marked as background so the verdict still targets the match.
|
|
183
|
-
|
|
184
|
-
| Context | Sent with the match |
|
|
185
|
-
| ------------------------------------------ | ---------------------------------------------------------- |
|
|
186
|
-
| `{ scope: "node" }` (default) | Nothing. |
|
|
187
|
-
| `{ scope: "lines", before: 5, after: 5 }` | Numbered lines around the match. Both counts default to 5. |
|
|
188
|
-
| `{ scope: "enclosing", kind: "function" }` | The nearest enclosing `function`, `class`, or `block`. |
|
|
189
|
-
| `{ scope: "file" }` | The whole file. |
|
|
190
|
-
| `{ scope: "comment" }` | See below. |
|
|
191
|
-
|
|
192
|
-
`{ scope: "comment" }` is for rules about the comment above the code. The match is sent starting at the comments directly above it, with nothing between them but whitespace. The comments may also sit above the `export` or declaration that holds the match. A match without such a comment is not asked about.
|
|
193
|
-
|
|
194
|
-
More context costs more tokens. It is cached together with the match, so an edit anywhere in the context re-asks that file.
|
|
195
|
-
|
|
196
|
-
### Models
|
|
197
|
-
|
|
198
|
-
A model id is `<provider>/<model>`. There are two built-in providers.
|
|
199
|
-
|
|
200
|
-
- `cloudflare` asks a chat model through the [AI Gateway REST API](https://developers.cloudflare.com/ai-gateway/usage/rest-api/). `cloudflare/@cf/qwen/qwen3.8-27b`, the default, asks `@cf/qwen/qwen3.8-27b` on Workers AI. The model answers each question with `yes` or `no`, and the yes probability comes from the log probabilities of that word. A model must return `logprobs` to be used here. Third-party models such as `cloudflare/openai/gpt-5.5` are billed through Unified Billing and need credits on the account.
|
|
201
|
-
- `openrouter` asks a decision model on the OpenRouter Decisions API. `openrouter/inception/mercury-decide` asks `inception/mercury-decide`. It reads the key from `OPENROUTER_API_KEY`. Browse decision models at [openrouter.ai/models](https://openrouter.ai/models?output_modalities=decisions).
|
|
202
|
-
|
|
203
|
-
`model` takes one id or a list. With a list, every model answers every match in a separate request. Each model's yes is its own diagnostic, so you can compare models on the same code.
|
|
204
|
-
|
|
205
|
-
```js
|
|
206
|
-
createDecisionPlugin({
|
|
207
|
-
model: ["openrouter/~typesafe/jev-latest", "openrouter/respan/span-01-lite"],
|
|
208
|
-
rules: [ ... ],
|
|
209
|
-
});
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
Cloudflare models and Respan models, such as `openrouter/respan/span-01-lite`, answer only yes/no questions. The plugin splits every choice into yes/no questions for them.
|
|
213
|
-
|
|
214
|
-
- `classify` asks whether each label fits and picks the label with the highest yes probability.
|
|
215
|
-
- `severity` asks whether the match is at least `info`, at least `warn` and at least `error`. It picks the most serious level with a yes probability of 0.8 or more. A level's probability is never below that of a more serious level.
|
|
216
|
-
- File-rule `location` asks about each candidate line. It finds clear cases, but is less precise than on the default model.
|
|
217
|
-
|
|
218
|
-
The probability in the message is the yes probability of the picked label or level. These models are also asked one question per request. So they send more requests than other models on files with many matches. `openrouter/~typesafe/jev-latest` answers every answer kind in one question.
|
|
219
|
-
|
|
220
|
-
Probabilities are not calibrated the same way across models. A cutoff tuned for one model does not carry over to another. Pin a versioned id once your cutoffs are tuned. Each diagnostic names the model that answered.
|
|
221
|
-
|
|
222
|
-
A key is required only for providers the rules you turned on use. `OPENROUTER_BASE_URL` points the plugin at another OpenRouter-compatible host. `CLOUDFLARE_API_BASE_URL` points it at another Cloudflare API host.
|
|
223
|
-
|
|
224
|
-
### File locations
|
|
225
|
-
|
|
226
|
-
File rules can point editor diagnostics and GitHub annotations to the suspected violation.
|
|
227
|
-
|
|
228
|
-
```js
|
|
229
|
-
defineDecisionRule({
|
|
230
|
-
id: "prefer-boolean-state-helper",
|
|
231
|
-
target: "file",
|
|
232
|
-
question:
|
|
233
|
-
"Does any boolean React state have a memoized callback that only sets it to true or false?",
|
|
234
|
-
cutoff: 0.9,
|
|
235
|
-
location: {
|
|
236
|
-
question: "Select the declaration of the state used by the offending callback.",
|
|
237
|
-
cutoff: 0.8,
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
The violation and location have separate cutoffs. An uncertain or invalid location keeps the finding on the first line. Files truncated by `maxSnippetChars` also keep the first-line diagnostic. Location questions only use complete source.
|
|
243
|
-
|
|
244
|
-
### Settings
|
|
245
|
-
|
|
246
|
-
Settings apply to the whole plugin, not to one rule. Pass them to `createDecisionPlugin`, or put them under `settings.<plugin name>` in `oxlint.config.ts`. Values in the config file win, so one plugin file can run with different settings in different configs.
|
|
247
|
-
|
|
248
|
-
```js
|
|
249
|
-
createDecisionPlugin({ name: "team", timeoutMs: 20_000, rules: [ ... ] });
|
|
250
|
-
```
|
|
76
|
+
Point `jsPlugins` at a preset and turn on its rules. Each rule is its own oxlint rule, named `decision-presets/<id>`, so you choose which ones run and at what severity. Settings such as `model`, `ci` and `timeoutMs` go under `settings["decision-presets"]` and apply to every rule of the preset.
|
|
251
77
|
|
|
252
78
|
```ts
|
|
253
79
|
// oxlint.config.ts
|
|
254
80
|
import { defineConfig } from "oxlint";
|
|
255
81
|
|
|
256
82
|
export default defineConfig({
|
|
257
|
-
jsPlugins: ["
|
|
258
|
-
settings: {
|
|
259
|
-
team: {
|
|
260
|
-
model: "openrouter/respan/span-01-lite",
|
|
261
|
-
},
|
|
262
|
-
},
|
|
83
|
+
jsPlugins: ["@r_masseater/oxlint-plugin-decision/presets/recommended"],
|
|
263
84
|
rules: {
|
|
264
|
-
"
|
|
85
|
+
"decision-presets/no-pii-in-logs": "error",
|
|
86
|
+
"decision-presets/no-prompt-injection": "error",
|
|
87
|
+
"decision-presets/no-hardcoded-secrets": "error",
|
|
265
88
|
},
|
|
266
89
|
});
|
|
267
90
|
```
|
|
268
91
|
|
|
269
|
-
|
|
270
|
-
| ----------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
271
|
-
| `ci` | `"fail"` | What happens when a model can't be asked and `CI` is set. `"fail"` fails the run. `"skip"` warns once and reports nothing. Outside CI it always skips. |
|
|
272
|
-
| `timeoutMs` | `10000` | Per-file budget shared by every model's request, retries and location refinements. |
|
|
273
|
-
| `maxSnippetChars` | `4000` | Longer snippets are cut and end with `/* ...truncated */`. |
|
|
274
|
-
| `model` | `"cloudflare/@cf/qwen/qwen3.8-27b"` | The default model id or list of ids. |
|
|
275
|
-
| `env` | `{}` | Renames the environment variables providers read, such as `{ "OPENROUTER_API_KEY": "TEAM_OPENROUTER_KEY" }`. Values are variable names, not keys. |
|
|
276
|
-
| `explain` | `false` | `true` or `"text"` prints why each match was or wasn't reported, `"json"` prints the same as JSON Lines. See [Explain mode](#explain-mode). |
|
|
277
|
-
|
|
278
|
-
## Explain mode
|
|
279
|
-
|
|
280
|
-
When you tune a question or try another model, explain mode shows why each match was or wasn't reported. Turn it on for one run with an environment variable, since oxlint does not pass command-line flags to plugins.
|
|
281
|
-
|
|
282
|
-
```sh
|
|
283
|
-
OXLINT_DECISION_EXPLAIN=1 npx oxlint # readable text
|
|
284
|
-
OXLINT_DECISION_EXPLAIN=json npx oxlint # one JSON object per match
|
|
285
|
-
```
|
|
286
|
-
|
|
287
|
-
You can also set `explain: true` (or `"json"`) in `createDecisionPlugin` or in `settings.<plugin name>`. The environment variable wins when it is set, and `OXLINT_DECISION_EXPLAIN=0` turns it off.
|
|
288
|
-
|
|
289
|
-
For every match the plugin asked a model about, it prints to stderr, so oxlint's own output stays as it is.
|
|
92
|
+
A preset decides which rules the plugin registers. A rule turns on only when you list it under `rules`.
|
|
290
93
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
- The file and position, and the rule.
|
|
300
|
-
- The model id the rule was asked with (after any per-rule override), and the model that served the answer.
|
|
301
|
-
- Whether the answer came from the cache, and how long the plugin waited for the answers of that file, in milliseconds. Every model of a file is asked together, so they share one wait.
|
|
302
|
-
- The length and first characters of the source sent as state. The full source is not printed.
|
|
303
|
-
- Each question exactly as sent, with the probability of each answer. When a Respan model answers a `classify` or `severity` rule, each yes/no question it was asked is listed on its own.
|
|
304
|
-
- The verdict, the rule's cutoff, and whether it was reported.
|
|
305
|
-
|
|
306
|
-
If the request failed, the record says why instead. JSON Lines uses the same fields. The position is in `file`, `line` and `column`. The rule and models are in `rule`, `model` and `served`. The cutoff and cache state are in `cutoff` and `cached`, and the time taken is in `durationMs`. The request is in `state` and `questions`. The result is in `verdict`, `reported` and `error`.
|
|
307
|
-
|
|
308
|
-
Explain mode only prints. It does not change what is asked, what is cached, or what is reported.
|
|
309
|
-
|
|
310
|
-
### Rule options
|
|
311
|
-
|
|
312
|
-
Each rule also takes options in `oxlint.config.ts`, next to its severity. They change only that rule, so one config can run different rules on different models.
|
|
313
|
-
|
|
314
|
-
```ts
|
|
315
|
-
// oxlint.config.ts
|
|
316
|
-
import { defineConfig } from "oxlint";
|
|
317
|
-
|
|
318
|
-
export default defineConfig({
|
|
319
|
-
jsPlugins: ["./decision-plugin.mjs"],
|
|
320
|
-
settings: {
|
|
321
|
-
team: {
|
|
322
|
-
model: "openrouter/respan/span-01-lite",
|
|
323
|
-
},
|
|
324
|
-
},
|
|
325
|
-
rules: {
|
|
326
|
-
"team/no-pii-in-logs": "error",
|
|
327
|
-
"team/name-matches-behavior": [
|
|
328
|
-
"warn",
|
|
329
|
-
{
|
|
330
|
-
model: "openrouter/~typesafe/jev-latest",
|
|
331
|
-
},
|
|
332
|
-
],
|
|
333
|
-
},
|
|
334
|
-
});
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
| Option | Meaning |
|
|
338
|
-
| ------- | ---------------------------------------- |
|
|
339
|
-
| `model` | A model id or list of ids for this rule. |
|
|
340
|
-
|
|
341
|
-
A rule's model comes from the first source that sets one. The rule's options in `oxlint.config.ts` come first. Next comes the rule's own `model`, and then `settings.<plugin name>.model`. After that comes the `model` passed to `createDecisionPlugin`. The default comes last.
|
|
342
|
-
|
|
343
|
-
Rules on different models are asked separately, one request per file and model. So a Respan model and `~typesafe/jev-latest` can share a config. Each model gets only the matches of the rules that use it. Answers are cached by the request each model receives. Rules never share or overwrite each other's cached answers.
|
|
344
|
-
|
|
345
|
-
## Providers
|
|
346
|
-
|
|
347
|
-
`createDecisionPlugin` also takes providers, so rules can ask a decision service other than Cloudflare and OpenRouter.
|
|
348
|
-
|
|
349
|
-
```js
|
|
350
|
-
// decision-plugin.mjs
|
|
351
|
-
import {
|
|
352
|
-
createDecisionPlugin,
|
|
353
|
-
defineDecisionRule,
|
|
354
|
-
defineProvider,
|
|
355
|
-
} from "@r_masseater/oxlint-plugin-decision";
|
|
356
|
-
|
|
357
|
-
export default createDecisionPlugin({
|
|
358
|
-
name: "team",
|
|
359
|
-
rules: [
|
|
360
|
-
defineDecisionRule({
|
|
361
|
-
id: "no-swallowed-catch",
|
|
362
|
-
target: "function",
|
|
363
|
-
question: "Does this function catch an error and neither handle nor rethrow it?",
|
|
364
|
-
cutoff: 0.8,
|
|
365
|
-
context: { scope: "lines", before: 3, after: 3 },
|
|
366
|
-
}),
|
|
367
|
-
],
|
|
368
|
-
providers: [
|
|
369
|
-
defineProvider({
|
|
370
|
-
name: "internal",
|
|
371
|
-
requiredEnv: ["INTERNAL_DECIDER_KEY"],
|
|
372
|
-
decide: ({ request, timeoutMs }) => ({
|
|
373
|
-
ok: true,
|
|
374
|
-
response: callYourDecider(request, timeoutMs),
|
|
375
|
-
}),
|
|
376
|
-
}),
|
|
377
|
-
],
|
|
378
|
-
});
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
```ts
|
|
382
|
-
// oxlint.config.ts
|
|
383
|
-
import { defineConfig } from "oxlint";
|
|
384
|
-
|
|
385
|
-
export default defineConfig({
|
|
386
|
-
jsPlugins: ["./decision-plugin.mjs"],
|
|
387
|
-
settings: {
|
|
388
|
-
team: {
|
|
389
|
-
model: "internal/v2",
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
rules: {
|
|
393
|
-
"team/no-swallowed-catch": "error",
|
|
394
|
-
},
|
|
395
|
-
});
|
|
396
|
-
```
|
|
397
|
-
|
|
398
|
-
`createDecisionPlugin` checks every rule and setting when the plugin loads. A typo in a rule fails the oxlint run instead of being ignored.
|
|
399
|
-
|
|
400
|
-
A provider's `decide` is synchronous, because oxlint rules are. It gets an OpenRouter Decisions request (`model`, `state`, `questions`). It returns `{ ok: true, response }` with a Decisions response, or `{ ok: false, reason }`. The built-in `cloudflare` and `openRouter` providers do their network calls on a worker thread through [synckit](https://github.com/un-ts/synckit). A custom provider that calls a network service should do the same.
|
|
401
|
-
|
|
402
|
-
oxlint runs JS plugins on one thread, so files are asked one after another. Within a file, the plugin hands every model of the same provider to the provider's optional `decideAll` in one call. The built-in providers send them at the same time. A provider without `decideAll` is asked one model at a time through `decide`.
|
|
403
|
-
|
|
404
|
-
The built-in provider's worker can report its `decide`, `ask` and `send` steps as spans over OTLP. It does so when the standard `OTEL_TRACES_EXPORTER=otlp` and `OTEL_EXPORTER_OTLP_ENDPOINT` are set. `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` also works in place of the endpoint. Otherwise it does nothing.
|
|
405
|
-
|
|
406
|
-
Types for all of this are exported. The rule types include `DecisionRule`, `DecisionOptions`, `RuleAnswer` and `RuleContext`. The provider types include `DecisionProvider`, `DecisionRequest` and `DecideResult`.
|
|
407
|
-
|
|
408
|
-
## How it works
|
|
409
|
-
|
|
410
|
-
Each file gets one request per model, with every match for that model in it. Respan models get one request per match instead. Cloudflare and Respan models split each choice question into yes/no questions. A file rule with `location` adds numbered source and a choice question. Above 254 nonblank lines the model selects a range and refines it in follow-up requests with the same context. All requests share the per-file `timeoutMs` budget.
|
|
411
|
-
|
|
412
|
-
Answers are cached under `node_modules/.cache/oxlint-plugin-decision`, keyed by the endpoint and the request. Changing a snippet, its context, a question or an answer kind re-asks that file. Changing a cutoff or an `id` does not. Malformed answers are never cached, and malformed entries already on disk are asked again. See [Cost and caching](#cost-and-caching) for how to keep the cost down.
|
|
413
|
-
|
|
414
|
-
OpenRouter requests use Effect's [`@effect/ai-openrouter`](https://www.npmjs.com/package/@effect/ai-openrouter) client. Cloudflare requests use Effect's HTTP client. Both retry rate limits and server errors within `timeoutMs`.
|
|
415
|
-
|
|
416
|
-
A model may not be reachable, because the key is missing, the request times out or the API errors. Then the plugin prints one warning and reports nothing for that model on that file. Under CI the run fails instead, unless `ci` is `"skip"`.
|
|
417
|
-
|
|
418
|
-
If only a location refinement fails, confirmed violations are still reported at the file level. Under CI (unless `ci` is `"skip"`), the refinement failure produces a separate diagnostic; otherwise it warns.
|
|
419
|
-
|
|
420
|
-
## Cost and caching
|
|
421
|
-
|
|
422
|
-
Before running the plugin on a real codebase, put these three in place.
|
|
423
|
-
|
|
424
|
-
1. Exclude files you don't need. List generated and vendored code in `ignorePatterns`, and use `overrides` to turn rules on only where they matter.
|
|
425
|
-
2. Lint only changed files instead of the whole tree.
|
|
426
|
-
|
|
427
|
-
```sh
|
|
428
|
-
git diff --name-only --diff-filter=d origin/main... -- '*.ts' '*.tsx' '*.js' '*.jsx' | xargs -r npx oxlint
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
3. Keep the cache. Answers are cached under `node_modules/.cache/oxlint-plugin-decision`, so unchanged code is not asked again. Don't delete it between local runs, and persist it in CI.
|
|
432
|
-
|
|
433
|
-
```yaml
|
|
434
|
-
- uses: actions/cache@v4
|
|
435
|
-
with:
|
|
436
|
-
path: node_modules/.cache/oxlint-plugin-decision
|
|
437
|
-
key: oxlint-decision-${{ github.sha }}
|
|
438
|
-
restore-keys: oxlint-decision-
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
Workers AI models are billed by the account's Workers AI usage, which includes a free daily allocation. The AI Gateway cache can also answer a request the account has already sent, so set a cache TTL on the gateway.
|
|
442
|
-
|
|
443
|
-
## In the editor
|
|
444
|
-
|
|
445
|
-
The oxlint VS Code extension lints as you type. Every keystroke inside a match is a paid request that blocks the language server until the model answers.
|
|
446
|
-
|
|
447
|
-
Keep your decision rules off in the config your editor reads, and turn them on in an overlay for CI and pre-push. Leave `jsPlugins` in the base config, since the overlay inherits it.
|
|
448
|
-
|
|
449
|
-
```ts
|
|
450
|
-
// oxlint.ci.config.ts
|
|
451
|
-
import { defineConfig } from "oxlint";
|
|
452
|
-
|
|
453
|
-
import base from "./oxlint.config.ts";
|
|
454
|
-
|
|
455
|
-
export default defineConfig({
|
|
456
|
-
extends: [base],
|
|
457
|
-
rules: {
|
|
458
|
-
"team/no-pii-in-logs": "error",
|
|
459
|
-
"team/name-matches-behavior": "error",
|
|
460
|
-
},
|
|
461
|
-
});
|
|
462
|
-
```
|
|
463
|
-
|
|
464
|
-
```sh
|
|
465
|
-
oxlint # editor and local runs, no models
|
|
466
|
-
oxlint -c oxlint.ci.config.ts # CI and pre-push, models included
|
|
467
|
-
```
|
|
94
|
+
| Preset | Import path | Rule prefix | What it is for | Run it as |
|
|
95
|
+
| ------------- | --------------------------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------ |
|
|
96
|
+
| `recommended` | `@r_masseater/oxlint-plugin-decision/presets/recommended` | `decision-presets/` | Security problems that should never ship: personal data in logs, prompt injection, hard-coded secrets. | `"error"` |
|
|
97
|
+
| `strict` | `@r_masseater/oxlint-plugin-decision/presets/strict` | `decision-presets/` | `recommended` plus code that breaks a promise its name makes, hidden failures, and tests that cannot fail. | `"error"` |
|
|
98
|
+
| `review-only` | `@r_masseater/oxlint-plugin-decision/presets/review-only` | `decision-presets/` | Judgment calls worth a look in review, mostly text that misdescribes the code next to it. | `"warn"` |
|
|
99
|
+
| `ai-slop` | `@r_masseater/oxlint-plugin-decision/presets/ai-slop` | `decision-ai-slop/` | Padding that coding agents tend to leave behind. | `"warn"`, `"error"` for placeholders |
|
|
468
100
|
|
|
469
|
-
|
|
101
|
+
The package root (`@r_masseater/oxlint-plugin-decision/presets`) is the `recommended` preset.
|
|
470
102
|
|
|
471
|
-
|
|
103
|
+
## Credits
|
|
472
104
|
|
|
473
|
-
|
|
474
|
-
| ----------------------- | ------------------------------------------------------- | ------------------------------------------- |
|
|
475
|
-
| `no-pii-in-logs` | `console.log("loaded", user.email, user.phone)` | `console.log("notified", { userId: id })` |
|
|
476
|
-
| `name-matches-behavior` | `getUser` that also sends an email | The same body named `notifySignIn` |
|
|
477
|
-
| `no-prompt-injection` | A customer message pasted into the system prompt string | The message passed as a separate user field |
|
|
105
|
+
The rules that check a claim the code makes about itself are adapted from [jev-lint](https://github.com/mizchi/jev-lint) by mizchi.
|
|
478
106
|
|
|
479
107
|
## License
|
|
480
108
|
|