@r_masseater/oxlint-plugin-decision 0.1.6 → 0.4.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 +53 -29
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +164 -101
- package/dist/index.mjs.map +1 -1
- package/dist/openrouter-app.d.mts +6 -0
- package/dist/openrouter-app.mjs +79 -0
- package/dist/openrouter-app.mjs.map +1 -0
- package/dist/openrouter-worker.mjs +48 -127
- package/dist/openrouter-worker.mjs.map +1 -1
- package/dist/{wire-XOgoBBuu.mjs → wire-XbLEwd0i.mjs} +166 -198
- package/dist/wire-XbLEwd0i.mjs.map +1 -0
- package/package.json +17 -11
- package/skills/write-decision-rules/SKILL.md +18 -18
- package/skills/write-decision-rules/references/providers.md +13 -9
- package/skills/write-decision-rules/references/tuning.md +7 -7
- package/dist/wire-XOgoBBuu.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
|
|
6
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
7
|
|
|
8
|
-
A rule is a question about a function, a call, a JSX element
|
|
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. The plugin reports an error when the answer the rule cares about clears its cutoff.
|
|
9
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
|
|
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. It is also why every rule here is a question with a fixed set of answers.
|
|
11
11
|
|
|
12
12
|
For ready-made rules, see [`@r_masseater/oxlint-plugin-decision-presets`](https://www.npmjs.com/package/@r_masseater/oxlint-plugin-decision-presets).
|
|
13
13
|
|
|
@@ -26,7 +26,7 @@ In CI (when the `CI` environment variable is set), a run that could not reach a
|
|
|
26
26
|
|
|
27
27
|
## Write your rules
|
|
28
28
|
|
|
29
|
-
The plugin ships no rules of its own. You write each rule with `defineDecisionRule` in a plugin file of your own
|
|
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 [`@r_masseater/oxlint-plugin-decision-presets`](https://www.npmjs.com/package/@r_masseater/oxlint-plugin-decision-presets).
|
|
30
30
|
|
|
31
31
|
```js
|
|
32
32
|
// decision-plugin.mjs
|
|
@@ -54,7 +54,7 @@ export default createDecisionPlugin({
|
|
|
54
54
|
});
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
Each rule becomes an oxlint rule named `<plugin name>/<rule id
|
|
57
|
+
Each rule becomes an oxlint rule named `<plugin name>/<rule id>`. You turn rules on and set their severity one by one, like any other oxlint rule. The plugin name defaults to `decision`.
|
|
58
58
|
|
|
59
59
|
```ts
|
|
60
60
|
// oxlint.config.ts
|
|
@@ -101,7 +101,7 @@ The wording of the question is the rule, so be precise about what counts. "Does
|
|
|
101
101
|
|
|
102
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
103
|
|
|
104
|
-
The second argument carries `context
|
|
104
|
+
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.
|
|
105
105
|
|
|
106
106
|
| Target | `name` |
|
|
107
107
|
| ------------ | --------------------------------------------------------------------------- |
|
|
@@ -186,15 +186,15 @@ By default the model reads only the match. `context` sends more source with it,
|
|
|
186
186
|
| `{ scope: "file" }` | The whole file. |
|
|
187
187
|
| `{ scope: "comment" }` | See below. |
|
|
188
188
|
|
|
189
|
-
`{ scope: "comment" }` is for rules about the comment above the code. The match is sent starting at the comments directly above it
|
|
189
|
+
`{ 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.
|
|
190
190
|
|
|
191
|
-
More context costs more tokens
|
|
191
|
+
More context costs more tokens. It is cached together with the match, so an edit anywhere in the context re-asks that file.
|
|
192
192
|
|
|
193
193
|
### Models
|
|
194
194
|
|
|
195
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
196
|
|
|
197
|
-
`model` takes one id or a list. With a list, every model answers every match
|
|
197
|
+
`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.
|
|
198
198
|
|
|
199
199
|
```js
|
|
200
200
|
createDecisionPlugin({
|
|
@@ -203,21 +203,21 @@ createDecisionPlugin({
|
|
|
203
203
|
});
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
-
Respan models, such as `openrouter/respan/span-01-lite`, answer only yes/no questions
|
|
206
|
+
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.
|
|
207
207
|
|
|
208
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
|
|
209
|
+
- `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.
|
|
210
210
|
- File-rule `location` asks about each candidate line. It finds clear cases, but is less precise than on the default model.
|
|
211
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
|
|
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
213
|
|
|
214
|
-
Probabilities are not calibrated the same way across models
|
|
214
|
+
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.
|
|
215
215
|
|
|
216
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
217
|
|
|
218
218
|
### File locations
|
|
219
219
|
|
|
220
|
-
File rules can point editor diagnostics and GitHub annotations to the suspected violation
|
|
220
|
+
File rules can point editor diagnostics and GitHub annotations to the suspected violation.
|
|
221
221
|
|
|
222
222
|
```js
|
|
223
223
|
defineDecisionRule({
|
|
@@ -233,7 +233,7 @@ defineDecisionRule({
|
|
|
233
233
|
});
|
|
234
234
|
```
|
|
235
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
|
|
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. Location questions only use complete source.
|
|
237
237
|
|
|
238
238
|
### Settings
|
|
239
239
|
|
|
@@ -271,7 +271,7 @@ export default defineConfig({
|
|
|
271
271
|
|
|
272
272
|
## Explain mode
|
|
273
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
|
|
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
275
|
|
|
276
276
|
```sh
|
|
277
277
|
OXLINT_DECISION_EXPLAIN=1 npx oxlint # readable text
|
|
@@ -280,7 +280,7 @@ OXLINT_DECISION_EXPLAIN=json npx oxlint # one JSON object per match
|
|
|
280
280
|
|
|
281
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
282
|
|
|
283
|
-
For every match the plugin asked a model about, it prints to stderr, so oxlint's own output stays as it is
|
|
283
|
+
For every match the plugin asked a model about, it prints to stderr, so oxlint's own output stays as it is.
|
|
284
284
|
|
|
285
285
|
```text
|
|
286
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
|
|
@@ -290,13 +290,14 @@ oxlint-plugin-decision explain: fail.js:5:3 [no-pii-in-logs] openrouter/respan/s
|
|
|
290
290
|
verdict: yes 0.93, cutoff 0.80, reported
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
- The file and position,
|
|
293
|
+
- The file and position, and the rule.
|
|
294
|
+
- The model id the rule was asked with (after any per-rule override), and the model that served the answer.
|
|
294
295
|
- 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
296
|
- The length and first characters of the source sent as state. The full source is not printed.
|
|
296
297
|
- 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
298
|
- The verdict, the rule's cutoff, and whether it was reported.
|
|
298
299
|
|
|
299
|
-
If the request failed, the record says why instead.
|
|
300
|
+
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`.
|
|
300
301
|
|
|
301
302
|
Explain mode only prints. It does not change what is asked, what is cached, or what is reported.
|
|
302
303
|
|
|
@@ -331,9 +332,9 @@ export default defineConfig({
|
|
|
331
332
|
| ------- | ---------------------------------------- |
|
|
332
333
|
| `model` | A model id or list of ids for this rule. |
|
|
333
334
|
|
|
334
|
-
A rule's model comes from the first
|
|
335
|
+
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.
|
|
335
336
|
|
|
336
|
-
Rules on different models are asked separately, one request per file and model
|
|
337
|
+
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.
|
|
337
338
|
|
|
338
339
|
## Providers
|
|
339
340
|
|
|
@@ -388,31 +389,54 @@ export default defineConfig({
|
|
|
388
389
|
});
|
|
389
390
|
```
|
|
390
391
|
|
|
391
|
-
`createDecisionPlugin` checks every rule and setting when the plugin loads
|
|
392
|
+
`createDecisionPlugin` checks every rule and setting when the plugin loads. A typo in a rule fails the oxlint run instead of being ignored.
|
|
392
393
|
|
|
393
|
-
A provider's `decide` is synchronous, because oxlint rules are. It gets an OpenRouter Decisions request (`model`, `state`, `questions`)
|
|
394
|
+
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 `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
|
|
|
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
|
|
396
|
+
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 provider sends them at the same time. A provider without `decideAll` is asked one model at a time through `decide`.
|
|
396
397
|
|
|
397
|
-
The built-in provider's worker
|
|
398
|
+
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.
|
|
398
399
|
|
|
399
|
-
Types for all of this are exported
|
|
400
|
+
Types for all of this are exported. The rule types include `DecisionRule`, `DecisionOptions`, `RuleAnswer` and `RuleContext`. The provider types include `DecisionProvider`, `DecisionRequest` and `DecideResult`.
|
|
400
401
|
|
|
401
402
|
## How it works
|
|
402
403
|
|
|
403
404
|
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
|
|
|
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](
|
|
406
|
+
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.
|
|
406
407
|
|
|
407
|
-
Requests go through
|
|
408
|
+
Requests go through Effect's [`@effect/ai-openrouter`](https://www.npmjs.com/package/@effect/ai-openrouter) client, which retries rate limits and server errors within `timeoutMs`.
|
|
408
409
|
|
|
409
|
-
|
|
410
|
+
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"`.
|
|
410
411
|
|
|
411
412
|
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
|
|
|
414
|
+
## Cost and caching
|
|
415
|
+
|
|
416
|
+
Before running the plugin on a real codebase, put these three in place.
|
|
417
|
+
|
|
418
|
+
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.
|
|
419
|
+
2. Lint only changed files instead of the whole tree.
|
|
420
|
+
|
|
421
|
+
```sh
|
|
422
|
+
git diff --name-only --diff-filter=d origin/main... -- '*.ts' '*.tsx' '*.js' '*.jsx' | xargs -r npx oxlint
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
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.
|
|
426
|
+
|
|
427
|
+
```yaml
|
|
428
|
+
- uses: actions/cache@v4
|
|
429
|
+
with:
|
|
430
|
+
path: node_modules/.cache/oxlint-plugin-decision
|
|
431
|
+
key: oxlint-decision-${{ github.sha }}
|
|
432
|
+
restore-keys: oxlint-decision-
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
To try rules without paying for requests, set a rule's model to the free `openrouter/respan/span-01-lite`. For example, use `"team/no-pii-in-logs": ["error", { "model": "openrouter/respan/span-01-lite" }]`.
|
|
436
|
+
|
|
413
437
|
## In the editor
|
|
414
438
|
|
|
415
|
-
The oxlint VS Code extension lints as you type
|
|
439
|
+
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.
|
|
416
440
|
|
|
417
441
|
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
442
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import {
|
|
2
|
+
import { ChoiceQuestion as ChoiceQuestion$1, DecisionsRequest, DecisionsResponse, NoulQuestion as NoulQuestion$1 } from "@effect/ai-openrouter/OpenRouterSchema";
|
|
3
3
|
//#endregion
|
|
4
4
|
//#region src-js/plugins/globals.d.ts
|
|
5
5
|
/**
|
|
@@ -3316,22 +3316,22 @@ interface DecisionOptions {
|
|
|
3316
3316
|
readonly env?: Readonly<Record<string, string>>;
|
|
3317
3317
|
readonly explain?: ExplainSetting;
|
|
3318
3318
|
}
|
|
3319
|
-
interface NoulQuestion extends Readonly<Pick<
|
|
3319
|
+
interface NoulQuestion extends Readonly<Pick<typeof NoulQuestion$1.Encoded, "type" | "instructions">> {
|
|
3320
3320
|
readonly instructions: string;
|
|
3321
3321
|
}
|
|
3322
|
-
interface ChoiceQuestion extends Readonly<Pick<
|
|
3322
|
+
interface ChoiceQuestion extends Readonly<Pick<typeof ChoiceQuestion$1.Encoded, "type" | "instructions" | "criteria">> {
|
|
3323
3323
|
readonly instructions: string;
|
|
3324
3324
|
readonly criteria: Readonly<Record<string, string | null>>;
|
|
3325
3325
|
}
|
|
3326
3326
|
type Question = NoulQuestion | ChoiceQuestion;
|
|
3327
|
-
interface DecisionRequest extends Readonly<Pick<DecisionsRequest, "model" | "state" | "questions">> {
|
|
3327
|
+
interface DecisionRequest extends Readonly<Pick<typeof DecisionsRequest.Encoded, "model" | "state" | "questions">> {
|
|
3328
3328
|
readonly state: {
|
|
3329
3329
|
readonly snippets: Readonly<Record<string, string>>;
|
|
3330
3330
|
readonly contexts?: Readonly<Record<string, string>>;
|
|
3331
3331
|
};
|
|
3332
3332
|
readonly questions: Readonly<Record<string, Question>>;
|
|
3333
3333
|
}
|
|
3334
|
-
type DecisionResponse =
|
|
3334
|
+
type DecisionResponse = Pick<typeof DecisionsResponse.Type, "model" | "answers">;
|
|
3335
3335
|
type DecideResult = {
|
|
3336
3336
|
readonly ok: true;
|
|
3337
3337
|
readonly response: DecisionResponse;
|