@r_masseater/oxlint-plugin-decision 0.0.1 → 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 CHANGED
@@ -1,5 +1,6 @@
1
1
  MIT License
2
2
 
3
+ Copyright (c) 2026 masseater
3
4
  Copyright (c) 2026 Robert Soriano
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
package/README.md CHANGED
@@ -20,57 +20,73 @@ npm i -D oxlint @r_masseater/oxlint-plugin-decision
20
20
  export OPENROUTER_API_KEY="..." # https://openrouter.ai/settings/keys
21
21
  ```
22
22
 
23
- The plugin reads the key from the `OPENROUTER_API_KEY` environment variable. Without it, the plugin warns once and reports nothing.
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
24
 
25
- In CI, set `ci: "fail"` so a run that could not reach a model fails instead of passing quietly.
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
26
 
27
- ## Config
27
+ ## Write your rules
28
28
 
29
- Add the plugin and its one rule, `decision/ask`, to `.oxlintrc.json`. Your English rules go in the options.
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
30
 
31
- ```json
32
- {
33
- "jsPlugins": ["@r_masseater/oxlint-plugin-decision"],
34
- "rules": {
35
- "decision/ask": [
36
- "error",
37
- {
38
- "model": "openrouter/~typesafe/jev-latest",
39
- "rules": [
40
- {
41
- "id": "no-pii-in-logs",
42
- "target": "call",
43
- "question": "Does this call write personal data, such as an email or phone number, to a log or console?",
44
- "cutoff": 0.8
45
- },
46
- {
47
- "id": "name-matches-behavior",
48
- "target": "function",
49
- "question": "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
- }
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
+ });
58
55
  ```
59
56
 
60
- ### Rules
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";
61
62
 
62
- | Field | What it is |
63
- | ---------- | ------------------------------------------------------------------------------------------------------- |
64
- | `id` | Shown in the error message. Unique in the list. |
65
- | `target` | `"function"`, `"call"`, `"jsx"`, or `"file"`. |
66
- | `question` | The question, in English. With the default answer kind, "yes" means "report this". |
67
- | `cutoff` | 0 to 1. The probability the reported answer needs, at or above. |
68
- | `answer` | Optional. What kind of answer to ask for. See [Answers](#answers). Defaults to `{ "kind": "boolean" }`. |
69
- | `context` | Optional. Extra source the model reads around the match. See [Context](#context). |
70
- | `model` | Optional. Overrides the top-level `model` for this rule. |
71
- | `location` | Optional for file rules: a source-location `question` and a `cutoff` greater than 0.5 and at most 1. |
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
72
75
 
73
- `target` decides what the model gets to read. There is no selector syntax and no other target.
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.
74
90
 
75
91
  | Target | The model sees | The error underlines |
76
92
  | ------------ | ------------------------------------------------------------------------------------------------------------ | -------------------- |
@@ -81,6 +97,42 @@ Add the plugin and its one rule, `decision/ask`, to `.oxlintrc.json`. Your Engli
81
97
 
82
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.
83
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
+
84
136
  ### Answers
85
137
 
86
138
  Pick a kind. You never write a schema.
@@ -91,33 +143,33 @@ Pick a kind. You never write a schema.
91
143
  | `classify` | To pick one of the `labels` you list. | The chosen label is in `report` and its probability is at or above `cutoff`. |
92
144
  | `severity` | To rate the problem as none, info, warn, or error. | The rating is at or above `minimum` (default `"warn"`) and clears `cutoff`. |
93
145
 
94
- ```json
95
- {
96
- "id": "stale-comment",
97
- "target": "function",
98
- "question": "How does the comment right above this function relate to what the function does?",
99
- "cutoff": 0.7,
100
- "context": { "scope": "lines", "before": 5, "after": 0 },
101
- "answer": {
102
- "kind": "classify",
103
- "labels": {
104
- "accurate": "The comment describes what the code does",
105
- "stale": "The comment describes behavior the code no longer has",
106
- "redundant": "The comment repeats the code without adding anything"
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",
107
159
  },
108
- "report": ["stale"]
109
- }
110
- }
160
+ report: ["stale"],
161
+ },
162
+ });
111
163
  ```
112
164
 
113
- ```json
114
- {
115
- "id": "security-smell",
116
- "target": "function",
117
- "question": "Does this function handle untrusted input in a way that could be exploited?",
118
- "cutoff": 0.6,
119
- "answer": { "kind": "severity", "minimum": "warn" }
120
- }
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
+ });
121
173
  ```
122
174
 
123
175
  The message names the answer: `[stale-comment] openrouter/... answered stale (0.91 >= 0.70): ...`.
@@ -126,12 +178,15 @@ The message names the answer: `[stale-comment] openrouter/... answered stale (0.
126
178
 
127
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.
128
180
 
129
- | Context | Sent with the match |
130
- | ----------------------------------------------- | ---------------------------------------------------------- |
131
- | `{ "scope": "node" }` (default) | Nothing. |
132
- | `{ "scope": "lines", "before": 5, "after": 5 }` | Numbered lines around the match. Both counts default to 5. |
133
- | `{ "scope": "enclosing", "kind": "function" }` | The nearest enclosing `function`, `class`, or `block`. |
134
- | `{ "scope": "file" }` | The whole file. |
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.
135
190
 
136
191
  More context costs more tokens and is cached together with the match, so an edit anywhere in the context re-asks that file.
137
192
 
@@ -141,48 +196,148 @@ A model id is `<provider>/<model>`. The built-in provider is `openrouter`, so `o
141
196
 
142
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.
143
198
 
144
- ```json
145
- { "model": ["openrouter/~typesafe/jev-latest", "openrouter/respan/span-01-lite"] }
199
+ ```js
200
+ createDecisionPlugin({
201
+ model: ["openrouter/~typesafe/jev-latest", "openrouter/respan/span-01-lite"],
202
+ rules: [ ... ],
203
+ });
146
204
  ```
147
205
 
148
- Respan models, such as `openrouter/respan/span-01-lite`, answer only yes/no questions: use them with `boolean` rules, not `classify`, `severity` or file-rule `location`. They 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` supports every answer kind.
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.
149
213
 
150
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.
151
215
 
152
- A key is required only for providers your config references. `OPENROUTER_BASE_URL` points the plugin at another OpenRouter-compatible host.
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.
153
217
 
154
218
  ### File locations
155
219
 
156
220
  File rules can point editor diagnostics and GitHub annotations to the suspected violation:
157
221
 
158
- ```json
159
- {
160
- "id": "prefer-boolean-state-helper",
161
- "target": "file",
162
- "question": "Does any boolean React state have a memoized callback that only sets it to true or false?",
163
- "cutoff": 0.9,
164
- "location": {
165
- "question": "Select the declaration of the state used by the offending callback.",
166
- "cutoff": 0.75
167
- }
168
- }
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
+ });
169
234
  ```
170
235
 
171
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.
172
237
 
173
238
  ### Settings
174
239
 
175
- | Setting | Default | Meaning |
176
- | ------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
177
- | `ci` | `"skip"` | What happens when a model can't be asked and `CI` is set. `"skip"` warns once and reports nothing. `"fail"` fails the run. Outside CI it always skips. |
178
- | `timeoutMs` | `10000` | Per-file budget shared by every model's request, retries and location refinements. |
179
- | `maxMatchesPerFile` | `25` | Matches sent per file across all rules. Extra matches are dropped in source order and the file is named on stderr. |
180
- | `maxSnippetChars` | `4000` | Longer snippets are cut and end with `/* ...truncated */`. |
181
- | `model` | `"openrouter/~typesafe/jev-latest"` | The default model id or list of ids. |
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.
182
241
 
183
- ## Rules and providers in code
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.
184
306
 
185
- `createDecisionPlugin` builds a plugin with rules and providers defined in JavaScript. Export it from a local file and list that file in `jsPlugins`.
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.
186
341
 
187
342
  ```js
188
343
  // decision-plugin.mjs
@@ -216,65 +371,74 @@ export default createDecisionPlugin({
216
371
  });
217
372
  ```
218
373
 
219
- ```json
220
- {
221
- "jsPlugins": ["./decision-plugin.mjs"],
222
- "rules": { "team/ask": ["error", { "model": "internal/v2" }] }
223
- }
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
+ });
224
389
  ```
225
390
 
226
- Rules from code come first, then rules from the config. Oxlint checks config rules against the plugin's JSON schema; rules from code are checked with the same constraints when linting starts.
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.
227
392
 
228
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.
229
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
+
230
399
  Types for all of this are exported: `DecisionRule`, `DecisionOptions`, `RuleAnswer`, `RuleContext`, `DecisionProvider`, `DecisionRequest`, `DecideResult`, and more.
231
400
 
232
401
  ## How it works
233
402
 
234
- Each file gets one request per model, with every match for that model in it. Respan models get one request per match instead. 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.
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.
235
404
 
236
- 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.
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.
237
406
 
238
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`.
239
408
 
240
- 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. Set `ci: "fail"` to fail the run instead.
241
-
242
- If only a location refinement fails, confirmed violations are still reported at the file level. Under CI with `ci: "fail"`, the refinement failure produces a separate diagnostic; otherwise it warns.
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"`.
243
410
 
244
- ## Cost and caching
245
-
246
- Every match is a paid model request unless its answer is already cached, so keep an eye on what your rules match.
247
-
248
- - A broad target, such as `"call"` on a large codebase, sends many matches. `maxMatchesPerFile` caps how many are sent per file.
249
- - Wider `context` and longer snippets cost more tokens. `maxSnippetChars` caps each snippet.
250
- - A list of models multiplies the requests: each model answers every match.
251
- - Answers are cached on disk under `node_modules/.cache/oxlint-plugin-decision`. Unchanged code is not asked again, so a second run over the same files is free. Editing a snippet, its context, a question or an answer kind re-asks that file; changing a cutoff or an `id` does not.
252
- - In CI, persist `node_modules/.cache/oxlint-plugin-decision` between runs to keep the cache warm.
253
- - Free models such as `openrouter/respan/span-01-lite` are a cheap way to try rules before switching to a paid model.
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.
254
412
 
255
413
  ## In the editor
256
414
 
257
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.
258
416
 
259
- Keep `decision/ask` out of the config your editor reads, and put it in an overlay for CI and pre-push. Leave `jsPlugins` in the base config, since the overlay inherits it.
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";
260
422
 
261
- ```json
262
- {
263
- "extends": [".oxlintrc.json"],
264
- "rules": {
265
- "decision/ask": ["error", { "rules": [ ... ] }]
266
- }
267
- }
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
+ });
268
432
  ```
269
433
 
270
434
  ```sh
271
- oxlint # editor and local runs, no models
272
- oxlint -c .oxlintrc.ci.json # CI and pre-push, models included
435
+ oxlint # editor and local runs, no models
436
+ oxlint -c oxlint.ci.config.ts # CI and pre-push, models included
273
437
  ```
274
438
 
275
439
  ## Example
276
440
 
277
- Three rules that a pattern-based linter can't express, and code each one fails and passes on. The rules are the ones in the [Config](#config) section plus a prompt-injection check.
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).
278
442
 
279
443
  | Rule | Fails on | Passes on |
280
444
  | ----------------------- | ------------------------------------------------------- | ------------------------------------------- |
@@ -284,4 +448,4 @@ Three rules that a pattern-based linter can't express, and code each one fails a
284
448
 
285
449
  ## License
286
450
 
287
- MIT
451
+ MIT.