@r_masseater/oxlint-plugin-decision 0.0.0-stage → 0.0.3
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/LICENSE +22 -0
- package/README.md +450 -2
- package/dist/index.d.mts +3376 -0
- package/dist/index.mjs +712 -0
- package/dist/index.mjs.map +1 -0
- package/dist/openrouter-worker.d.mts +1 -0
- package/dist/openrouter-worker.mjs +133 -0
- package/dist/openrouter-worker.mjs.map +1 -0
- package/dist/wire-BGb5iQa9.mjs +548 -0
- package/dist/wire-BGb5iQa9.mjs.map +1 -0
- package/package.json +67 -3
- package/skills/write-decision-rules/SKILL.md +230 -0
- package/skills/write-decision-rules/references/providers.md +51 -0
- package/skills/write-decision-rules/references/tuning.md +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 masseater
|
|
4
|
+
Copyright (c) 2026 Robert Soriano
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,451 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @r_masseater/oxlint-plugin-decision
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> [!WARNING]
|
|
4
|
+
> This package is experimental. Use at your own risk.
|
|
5
|
+
|
|
6
|
+
[Oxlint](https://oxc.rs/docs/guide/usage/linter.html) rules written in plain English, answered by decision models on [OpenRouter](https://openrouter.ai).
|
|
7
|
+
|
|
8
|
+
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, and the plugin reports an error when the answer the rule cares about clears its cutoff.
|
|
9
|
+
|
|
10
|
+
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, and it is why every rule here is a question with a fixed set of answers.
|
|
11
|
+
|
|
12
|
+
For ready-made rules, see [`@r_masseater/oxlint-plugin-decision-presets`](https://www.npmjs.com/package/@r_masseater/oxlint-plugin-decision-presets).
|
|
13
|
+
|
|
14
|
+
This is a fork of [oxlint-plugin-jev](https://github.com/wobsoriano/oxlint-plugin-jev) by [Robert Soriano](https://github.com/wobsoriano), rebuilt on the OpenRouter Decisions API.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm i -D oxlint @r_masseater/oxlint-plugin-decision
|
|
20
|
+
export OPENROUTER_API_KEY="..." # https://openrouter.ai/settings/keys
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The plugin reads the key from the `OPENROUTER_API_KEY` environment variable. Without it, the plugin warns once and reports nothing. To read the key from a variable with another name, set `env` (see [Settings](#settings)). The key itself is never passed in code or config.
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
## Write your rules
|
|
28
|
+
|
|
29
|
+
The plugin ships no rules of its own. You write each rule with `defineDecisionRule` in a plugin file of your own, pass them to `createDecisionPlugin`, and load that file from `oxlint.config.ts`. For ready-made rules, use [`@r_masseater/oxlint-plugin-decision-presets`](https://www.npmjs.com/package/@r_masseater/oxlint-plugin-decision-presets).
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
// decision-plugin.mjs
|
|
33
|
+
import { createDecisionPlugin, defineDecisionRule } from "@r_masseater/oxlint-plugin-decision";
|
|
34
|
+
|
|
35
|
+
export default createDecisionPlugin({
|
|
36
|
+
name: "team",
|
|
37
|
+
rules: [
|
|
38
|
+
defineDecisionRule({
|
|
39
|
+
id: "no-pii-in-logs",
|
|
40
|
+
target: "call",
|
|
41
|
+
question:
|
|
42
|
+
"Does this call write personal data, such as an email or phone number, to a log or console?",
|
|
43
|
+
cutoff: 0.8,
|
|
44
|
+
}),
|
|
45
|
+
defineDecisionRule({
|
|
46
|
+
id: "name-matches-behavior",
|
|
47
|
+
target: "function",
|
|
48
|
+
question:
|
|
49
|
+
"Does this function's name describe only reading or fetching data (for example get, find, load or fetch), while its body also writes, logs or sends something?",
|
|
50
|
+
cutoff: 0.6,
|
|
51
|
+
context: { scope: "enclosing", kind: "class" },
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Each rule becomes an oxlint rule named `<plugin name>/<rule id>`, so you turn rules on and set their severity one by one, like any other oxlint rule. The plugin name defaults to `decision`.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// oxlint.config.ts
|
|
61
|
+
import { defineConfig } from "oxlint";
|
|
62
|
+
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
jsPlugins: ["./decision-plugin.mjs"],
|
|
65
|
+
rules: {
|
|
66
|
+
"team/no-pii-in-logs": "error",
|
|
67
|
+
"team/name-matches-behavior": "warn",
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The rules you turn on share one request per file and model, so turning on more rules does not add requests.
|
|
73
|
+
|
|
74
|
+
### Rules
|
|
75
|
+
|
|
76
|
+
| Field | What it is |
|
|
77
|
+
| ---------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
78
|
+
| `id` | The oxlint rule name after `<plugin name>/`. Lowercase words joined by hyphens, unique in the plugin. |
|
|
79
|
+
| `target` | `"function"`, `"call"`, `"jsx"`, or `"file"`. |
|
|
80
|
+
| `question` | The question, in English. With the default answer kind, "yes" means "report this". |
|
|
81
|
+
| `cutoff` | 0 to 1. The probability the reported answer needs, at or above. |
|
|
82
|
+
| `message` | Optional. A short sentence the error shows instead of the question. |
|
|
83
|
+
| `select` | Optional. A function of the AST node that says whether to ask about it. See [Selecting matches](#selecting-matches). |
|
|
84
|
+
| `answer` | Optional. What kind of answer to ask for. See [Answers](#answers). Defaults to `{ kind: "boolean" }`. |
|
|
85
|
+
| `context` | Optional. Extra source the model reads around the match. See [Context](#context). |
|
|
86
|
+
| `model` | Optional. Overrides the plugin's `model` for this rule. See [Rule options](#rule-options). |
|
|
87
|
+
| `location` | Optional for file rules: a source-location `question` and a `cutoff` greater than 0.5 and at most 1. |
|
|
88
|
+
|
|
89
|
+
`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.
|
|
90
|
+
|
|
91
|
+
| Target | The model sees | The error underlines |
|
|
92
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------ | -------------------- |
|
|
93
|
+
| `"function"` | The whole function. An arrow or method includes its name, so `const getUser = () => ...` reads as `getUser`. | The signature line |
|
|
94
|
+
| `"call"` | The whole call expression. | The whole call |
|
|
95
|
+
| `"jsx"` | The whole element, children included. | The opening tag |
|
|
96
|
+
| `"file"` | The whole file. | The first line |
|
|
97
|
+
|
|
98
|
+
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.
|
|
99
|
+
|
|
100
|
+
### Selecting matches
|
|
101
|
+
|
|
102
|
+
`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.
|
|
103
|
+
|
|
104
|
+
The second argument carries `context`, the oxlint rule context, and `name`, the match's name as source text, or `undefined` when it has none:
|
|
105
|
+
|
|
106
|
+
| Target | `name` |
|
|
107
|
+
| ------------ | --------------------------------------------------------------------------- |
|
|
108
|
+
| `"function"` | The function's own name, or the binding, property, or method that holds it. |
|
|
109
|
+
| `"call"` | The callee as written, such as `console.error` or `it.only`. |
|
|
110
|
+
| `"jsx"` | The tag name, such as `Button` or `motion.div`. |
|
|
111
|
+
| `"file"` | Always `undefined`. |
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
defineDecisionRule({
|
|
115
|
+
id: "pure-name-is-pure",
|
|
116
|
+
target: "function",
|
|
117
|
+
select: (node, { name }) => name !== undefined && name.startsWith("compute"),
|
|
118
|
+
question:
|
|
119
|
+
"This function's name presents it as a pure computation, but its body changes state outside itself or performs I/O.",
|
|
120
|
+
message: "The name promises a pure computation, but the body has side effects.",
|
|
121
|
+
cutoff: 0.54,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
defineDecisionRule({
|
|
125
|
+
id: "test-proves-its-name",
|
|
126
|
+
target: "call",
|
|
127
|
+
select: (node) =>
|
|
128
|
+
node.type === "CallExpression" &&
|
|
129
|
+
node.callee.type === "Identifier" &&
|
|
130
|
+
["it", "test"].includes(node.callee.name),
|
|
131
|
+
question: "Would this test still pass if the behaviour its name claims were broken?",
|
|
132
|
+
cutoff: 0.7,
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Answers
|
|
137
|
+
|
|
138
|
+
Pick a kind. You never write a schema.
|
|
139
|
+
|
|
140
|
+
| Kind | The model is asked | Reported when |
|
|
141
|
+
| ------------------- | -------------------------------------------------- | ---------------------------------------------------------------------------- |
|
|
142
|
+
| `boolean` (default) | The probability that the answer is yes. | That probability is at or above `cutoff`. |
|
|
143
|
+
| `classify` | To pick one of the `labels` you list. | The chosen label is in `report` and its probability is at or above `cutoff`. |
|
|
144
|
+
| `severity` | To rate the problem as none, info, warn, or error. | The rating is at or above `minimum` (default `"warn"`) and clears `cutoff`. |
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
defineDecisionRule({
|
|
148
|
+
id: "stale-comment",
|
|
149
|
+
target: "function",
|
|
150
|
+
question: "How does the comment right above this function relate to what the function does?",
|
|
151
|
+
cutoff: 0.7,
|
|
152
|
+
context: { scope: "lines", before: 5, after: 0 },
|
|
153
|
+
answer: {
|
|
154
|
+
kind: "classify",
|
|
155
|
+
labels: {
|
|
156
|
+
accurate: "The comment describes what the code does",
|
|
157
|
+
stale: "The comment describes behavior the code no longer has",
|
|
158
|
+
redundant: "The comment repeats the code without adding anything",
|
|
159
|
+
},
|
|
160
|
+
report: ["stale"],
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
defineDecisionRule({
|
|
167
|
+
id: "security-smell",
|
|
168
|
+
target: "function",
|
|
169
|
+
question: "Does this function handle untrusted input in a way that could be exploited?",
|
|
170
|
+
cutoff: 0.6,
|
|
171
|
+
answer: { kind: "severity", minimum: "warn" },
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The message names the answer: `[stale-comment] openrouter/... answered stale (0.91 >= 0.70): ...`.
|
|
176
|
+
|
|
177
|
+
### Context
|
|
178
|
+
|
|
179
|
+
By default the model reads only the match. `context` sends more source with it, marked as background so the verdict still targets the match.
|
|
180
|
+
|
|
181
|
+
| Context | Sent with the match |
|
|
182
|
+
| ------------------------------------------ | ---------------------------------------------------------- |
|
|
183
|
+
| `{ scope: "node" }` (default) | Nothing. |
|
|
184
|
+
| `{ scope: "lines", before: 5, after: 5 }` | Numbered lines around the match. Both counts default to 5. |
|
|
185
|
+
| `{ scope: "enclosing", kind: "function" }` | The nearest enclosing `function`, `class`, or `block`. |
|
|
186
|
+
| `{ scope: "file" }` | The whole file. |
|
|
187
|
+
| `{ scope: "comment" }` | See below. |
|
|
188
|
+
|
|
189
|
+
`{ scope: "comment" }` is for rules about the comment above the code. The match is sent starting at the comments directly above it (or above the `export` or declaration that holds it), with nothing between them but whitespace. A match without such a comment is not asked about.
|
|
190
|
+
|
|
191
|
+
More context costs more tokens and is cached together with the match, so an edit anywhere in the context re-asks that file.
|
|
192
|
+
|
|
193
|
+
### Models
|
|
194
|
+
|
|
195
|
+
A model id is `<provider>/<model>`. The built-in provider is `openrouter`, so `openrouter/inception/mercury-decide` asks `inception/mercury-decide` on OpenRouter. Browse decision models at [openrouter.ai/models](https://openrouter.ai/models?output_modalities=decisions).
|
|
196
|
+
|
|
197
|
+
`model` takes one id or a list. With a list, every model answers every match, each model's request is separate, and each model's yes is its own diagnostic, so you can compare models on the same code.
|
|
198
|
+
|
|
199
|
+
```js
|
|
200
|
+
createDecisionPlugin({
|
|
201
|
+
model: ["openrouter/~typesafe/jev-latest", "openrouter/respan/span-01-lite"],
|
|
202
|
+
rules: [ ... ],
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Respan models, such as `openrouter/respan/span-01-lite`, answer only yes/no questions, so the plugin splits every choice into yes/no questions for them:
|
|
207
|
+
|
|
208
|
+
- `classify` asks whether each label fits and picks the label with the highest yes probability.
|
|
209
|
+
- `severity` asks whether the match is at least `info`, at least `warn`, and at least `error`, and picks the most serious level with a yes probability of 0.5 or more. A level's probability is never below that of a more serious level.
|
|
210
|
+
- File-rule `location` asks about each candidate line. It finds clear cases, but is less precise than on the default model.
|
|
211
|
+
|
|
212
|
+
The probability in the message is the yes probability of the picked label or level. Respan models are also asked about one match per request, so they send more requests than other models on files with many matches. The default `openrouter/~typesafe/jev-latest` answers every answer kind in one question.
|
|
213
|
+
|
|
214
|
+
Probabilities are not calibrated the same way across models, so 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.
|
|
215
|
+
|
|
216
|
+
A key is required only for providers the rules you turned on use. `OPENROUTER_BASE_URL` points the plugin at another OpenRouter-compatible host.
|
|
217
|
+
|
|
218
|
+
### File locations
|
|
219
|
+
|
|
220
|
+
File rules can point editor diagnostics and GitHub annotations to the suspected violation:
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
defineDecisionRule({
|
|
224
|
+
id: "prefer-boolean-state-helper",
|
|
225
|
+
target: "file",
|
|
226
|
+
question:
|
|
227
|
+
"Does any boolean React state have a memoized callback that only sets it to true or false?",
|
|
228
|
+
cutoff: 0.9,
|
|
229
|
+
location: {
|
|
230
|
+
question: "Select the declaration of the state used by the offending callback.",
|
|
231
|
+
cutoff: 0.75,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
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, since location questions only use complete source.
|
|
237
|
+
|
|
238
|
+
### Settings
|
|
239
|
+
|
|
240
|
+
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.
|
|
241
|
+
|
|
242
|
+
```js
|
|
243
|
+
createDecisionPlugin({ name: "team", timeoutMs: 20_000, rules: [ ... ] });
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
// oxlint.config.ts
|
|
248
|
+
import { defineConfig } from "oxlint";
|
|
249
|
+
|
|
250
|
+
export default defineConfig({
|
|
251
|
+
jsPlugins: ["./decision-plugin.mjs"],
|
|
252
|
+
settings: {
|
|
253
|
+
team: {
|
|
254
|
+
model: "openrouter/respan/span-01-lite",
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
rules: {
|
|
258
|
+
"team/no-pii-in-logs": "error",
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
| Setting | Default | Meaning |
|
|
264
|
+
| ----------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
265
|
+
| `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. |
|
|
266
|
+
| `timeoutMs` | `10000` | Per-file budget shared by every model's request, retries and location refinements. |
|
|
267
|
+
| `maxSnippetChars` | `4000` | Longer snippets are cut and end with `/* ...truncated */`. |
|
|
268
|
+
| `model` | `"openrouter/~typesafe/jev-latest"` | The default model id or list of ids. |
|
|
269
|
+
| `env` | `{}` | Renames the environment variables providers read, such as `{ "OPENROUTER_API_KEY": "TEAM_OPENROUTER_KEY" }`. Values are variable names, not keys. |
|
|
270
|
+
| `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). |
|
|
271
|
+
|
|
272
|
+
## Explain mode
|
|
273
|
+
|
|
274
|
+
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:
|
|
275
|
+
|
|
276
|
+
```sh
|
|
277
|
+
OXLINT_DECISION_EXPLAIN=1 npx oxlint # readable text
|
|
278
|
+
OXLINT_DECISION_EXPLAIN=json npx oxlint # one JSON object per match
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
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.
|
|
282
|
+
|
|
283
|
+
For every match the plugin asked a model about, it prints to stderr, so oxlint's own output stays as it is:
|
|
284
|
+
|
|
285
|
+
```text
|
|
286
|
+
oxlint-plugin-decision explain: fail.js:5:3 [no-pii-in-logs] openrouter/respan/span-01-lite (served openrouter/respan/span-01-lite-20260925) cached=no 412ms
|
|
287
|
+
state: 64 chars "state.snippets.s3: console.log(\"loaded\", user.email, user.ph"
|
|
288
|
+
s3: yes=0.93
|
|
289
|
+
Consider only snippet "s3" in state.snippets. Does this call write personal data, such as an email or phone number, to a log or console?
|
|
290
|
+
verdict: yes 0.93, cutoff 0.80, reported
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
- The file and position, the rule, the model id the rule was asked with (after any per-rule override), and the model that served the answer.
|
|
294
|
+
- 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.
|
|
295
|
+
- The length and first characters of the source sent as state. The full source is not printed.
|
|
296
|
+
- 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.
|
|
297
|
+
- The verdict, the rule's cutoff, and whether it was reported.
|
|
298
|
+
|
|
299
|
+
If the request failed, the record says why instead. In JSON Lines the same fields are `file`, `line`, `column`, `rule`, `model`, `served`, `cutoff`, `cached`, `durationMs`, `state`, `questions`, `verdict`, `reported`, and `error`.
|
|
300
|
+
|
|
301
|
+
Explain mode only prints. It does not change what is asked, what is cached, or what is reported.
|
|
302
|
+
|
|
303
|
+
### Rule options
|
|
304
|
+
|
|
305
|
+
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.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
// oxlint.config.ts
|
|
309
|
+
import { defineConfig } from "oxlint";
|
|
310
|
+
|
|
311
|
+
export default defineConfig({
|
|
312
|
+
jsPlugins: ["./decision-plugin.mjs"],
|
|
313
|
+
settings: {
|
|
314
|
+
team: {
|
|
315
|
+
model: "openrouter/respan/span-01-lite",
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
rules: {
|
|
319
|
+
"team/no-pii-in-logs": "error",
|
|
320
|
+
"team/name-matches-behavior": [
|
|
321
|
+
"warn",
|
|
322
|
+
{
|
|
323
|
+
model: "openrouter/~typesafe/jev-latest",
|
|
324
|
+
},
|
|
325
|
+
],
|
|
326
|
+
},
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
| Option | Meaning |
|
|
331
|
+
| ------- | ---------------------------------------- |
|
|
332
|
+
| `model` | A model id or list of ids for this rule. |
|
|
333
|
+
|
|
334
|
+
A rule's model comes from the first of these that sets one: the rule's options in `oxlint.config.ts`, the rule's own `model`, `settings.<plugin name>.model`, the `model` passed to `createDecisionPlugin`, and the default.
|
|
335
|
+
|
|
336
|
+
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, so rules never share or overwrite each other's cached answers.
|
|
337
|
+
|
|
338
|
+
## Providers
|
|
339
|
+
|
|
340
|
+
`createDecisionPlugin` also takes providers, so rules can ask a decision service other than OpenRouter.
|
|
341
|
+
|
|
342
|
+
```js
|
|
343
|
+
// decision-plugin.mjs
|
|
344
|
+
import {
|
|
345
|
+
createDecisionPlugin,
|
|
346
|
+
defineDecisionRule,
|
|
347
|
+
defineProvider,
|
|
348
|
+
} from "@r_masseater/oxlint-plugin-decision";
|
|
349
|
+
|
|
350
|
+
export default createDecisionPlugin({
|
|
351
|
+
name: "team",
|
|
352
|
+
rules: [
|
|
353
|
+
defineDecisionRule({
|
|
354
|
+
id: "no-swallowed-catch",
|
|
355
|
+
target: "function",
|
|
356
|
+
question: "Does this function catch an error and neither handle nor rethrow it?",
|
|
357
|
+
cutoff: 0.8,
|
|
358
|
+
context: { scope: "lines", before: 3, after: 3 },
|
|
359
|
+
}),
|
|
360
|
+
],
|
|
361
|
+
providers: [
|
|
362
|
+
defineProvider({
|
|
363
|
+
name: "internal",
|
|
364
|
+
requiredEnv: ["INTERNAL_DECIDER_KEY"],
|
|
365
|
+
decide: ({ request, timeoutMs }) => ({
|
|
366
|
+
ok: true,
|
|
367
|
+
response: callYourDecider(request, timeoutMs),
|
|
368
|
+
}),
|
|
369
|
+
}),
|
|
370
|
+
],
|
|
371
|
+
});
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
```ts
|
|
375
|
+
// oxlint.config.ts
|
|
376
|
+
import { defineConfig } from "oxlint";
|
|
377
|
+
|
|
378
|
+
export default defineConfig({
|
|
379
|
+
jsPlugins: ["./decision-plugin.mjs"],
|
|
380
|
+
settings: {
|
|
381
|
+
team: {
|
|
382
|
+
model: "internal/v2",
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
rules: {
|
|
386
|
+
"team/no-swallowed-catch": "error",
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
`createDecisionPlugin` checks every rule and setting when the plugin loads, so a typo in a rule fails the oxlint run instead of being ignored.
|
|
392
|
+
|
|
393
|
+
A provider's `decide` is synchronous, because oxlint rules are. It gets an OpenRouter Decisions request (`model`, `state`, `questions`) and returns `{ ok: true, response }` with a Decisions response, or `{ ok: false, reason }`. The built-in `openRouter` provider does its network call on a worker thread through [synckit](https://github.com/un-ts/synckit); a custom provider that calls a network service should do the same.
|
|
394
|
+
|
|
395
|
+
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, and the built-in provider sends them at the same time. A provider without `decideAll` is asked one model at a time through `decide`.
|
|
396
|
+
|
|
397
|
+
The built-in provider's worker reports its `decide`, `ask` and `send` steps as spans over OTLP when the standard `OTEL_TRACES_EXPORTER=otlp` and `OTEL_EXPORTER_OTLP_ENDPOINT` (or `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`) are set, and does nothing otherwise.
|
|
398
|
+
|
|
399
|
+
Types for all of this are exported: `DecisionRule`, `DecisionOptions`, `RuleAnswer`, `RuleContext`, `DecisionProvider`, `DecisionRequest`, `DecideResult`, and more.
|
|
400
|
+
|
|
401
|
+
## How it works
|
|
402
|
+
|
|
403
|
+
Each file gets one request per model, with every match for that model in it. Respan models get one request per match instead, with each choice question split 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.
|
|
404
|
+
|
|
405
|
+
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](https://github.com/masseater/oxlint-plugin-decision#cost-and-caching) for how to keep the cost down.
|
|
406
|
+
|
|
407
|
+
Requests go through the official [`@openrouter/sdk`](https://www.npmjs.com/package/@openrouter/sdk) client, which retries rate limits and server errors within `timeoutMs`.
|
|
408
|
+
|
|
409
|
+
If a model can't be asked, because the key is missing, the request times out, or the API errors, the plugin prints one warning and reports nothing for that model on that file. Under CI the run fails instead, unless `ci` is `"skip"`.
|
|
410
|
+
|
|
411
|
+
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.
|
|
412
|
+
|
|
413
|
+
## In the editor
|
|
414
|
+
|
|
415
|
+
The oxlint VS Code extension lints as you type, and every keystroke inside a match is a paid request that blocks the language server until the model answers.
|
|
416
|
+
|
|
417
|
+
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.
|
|
418
|
+
|
|
419
|
+
```ts
|
|
420
|
+
// oxlint.ci.config.ts
|
|
421
|
+
import { defineConfig } from "oxlint";
|
|
422
|
+
|
|
423
|
+
import base from "./oxlint.config.ts";
|
|
424
|
+
|
|
425
|
+
export default defineConfig({
|
|
426
|
+
extends: [base],
|
|
427
|
+
rules: {
|
|
428
|
+
"team/no-pii-in-logs": "error",
|
|
429
|
+
"team/name-matches-behavior": "error",
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
```sh
|
|
435
|
+
oxlint # editor and local runs, no models
|
|
436
|
+
oxlint -c oxlint.ci.config.ts # CI and pre-push, models included
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
## Example
|
|
440
|
+
|
|
441
|
+
Three rules that a pattern-based linter can't express, and code each one fails and passes on. The rules are the ones in [Write your rules](#write-your-rules) plus a prompt-injection check, defined in [`example/plugin.mjs`](example/plugin.mjs).
|
|
442
|
+
|
|
443
|
+
| Rule | Fails on | Passes on |
|
|
444
|
+
| ----------------------- | ------------------------------------------------------- | ------------------------------------------- |
|
|
445
|
+
| `no-pii-in-logs` | `console.log("loaded", user.email, user.phone)` | `console.log("notified", { userId: id })` |
|
|
446
|
+
| `name-matches-behavior` | `getUser` that also sends an email | The same body named `notifySignIn` |
|
|
447
|
+
| `no-prompt-injection` | A customer message pasted into the system prompt string | The message passed as a separate user field |
|
|
448
|
+
|
|
449
|
+
## License
|
|
450
|
+
|
|
451
|
+
MIT.
|