@andrueandersoncs/lint-anything 0.8.0 → 0.9.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 +20 -8
- package/dist/cli.js +59 -59
- package/dist/lib.js +58 -8
- package/dist/types/decision-model.d.ts +13 -6
- package/dist/types/lib.d.ts +1 -1
- package/package.json +2 -2
- package/skills/lint-anything/SKILL.md +15 -2
- package/skills/lint-anything/scripts/score.js +35 -35
- package/skills/lint-anything/scripts/select.js +351 -0
package/dist/lib.js
CHANGED
|
@@ -228,16 +228,56 @@ var choice = Effect.gen(function* () {
|
|
|
228
228
|
}
|
|
229
229
|
return { kind: "workers-ai", model: name };
|
|
230
230
|
});
|
|
231
|
+
var secondaryChoice = Effect.gen(function* () {
|
|
232
|
+
const endpoint = yield* setting("LINT_ANYTHING_SECONDARY_ENDPOINT");
|
|
233
|
+
const model = yield* setting("LINT_ANYTHING_SECONDARY_MODEL");
|
|
234
|
+
const apiKey = yield* setting("LINT_ANYTHING_SECONDARY_API_KEY");
|
|
235
|
+
if (Option.isSome(endpoint)) {
|
|
236
|
+
if (!isHttpUrl(endpoint.value)) {
|
|
237
|
+
return yield* configError(`LINT_ANYTHING_SECONDARY_ENDPOINT must be an http or https URL, such as http://localhost:4000/v1/systemone`);
|
|
238
|
+
}
|
|
239
|
+
if (Option.isNone(model)) {
|
|
240
|
+
return yield* configError(`LINT_ANYTHING_SECONDARY_MODEL is not set; LINT_ANYTHING_SECONDARY_ENDPOINT needs the name of the model to ask`);
|
|
241
|
+
}
|
|
242
|
+
return Option.some({
|
|
243
|
+
kind: "endpoint",
|
|
244
|
+
url: endpoint.value,
|
|
245
|
+
model: model.value,
|
|
246
|
+
token: Option.getOrUndefined(Option.map(apiKey, Redacted.make))
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
if (Option.isSome(apiKey)) {
|
|
250
|
+
return yield* configError("LINT_ANYTHING_SECONDARY_API_KEY is set but LINT_ANYTHING_SECONDARY_ENDPOINT is not; set the endpoint the key is for (Clef on Workers AI uses CLOUDFLARE_AUTH_TOKEN)");
|
|
251
|
+
}
|
|
252
|
+
if (Option.isNone(model))
|
|
253
|
+
return Option.none();
|
|
254
|
+
const name = model.value;
|
|
255
|
+
if (!/^[\w.-]+$/.test(name)) {
|
|
256
|
+
return yield* configError(`LINT_ANYTHING_SECONDARY_MODEL ${name} is not a Cloudflare model; to ask it, set LINT_ANYTHING_SECONDARY_ENDPOINT to the decision endpoint that serves it`);
|
|
257
|
+
}
|
|
258
|
+
return Option.some({ kind: "workers-ai", model: name });
|
|
259
|
+
});
|
|
260
|
+
var resolveWorkersAi = (model) => Effect.gen(function* () {
|
|
261
|
+
const required = (name, config) => config.pipe(Effect.mapError(() => configError(`${name} is not set; set it in the environment or in .env`)));
|
|
262
|
+
const accountId = yield* required("CLOUDFLARE_ACCOUNT_ID", Config.String("CLOUDFLARE_ACCOUNT_ID"));
|
|
263
|
+
const token = yield* required("CLOUDFLARE_AUTH_TOKEN", Config.Redacted("CLOUDFLARE_AUTH_TOKEN"));
|
|
264
|
+
const baseUrl = yield* Config.String("CLOUDFLARE_API_BASE_URL").pipe(Config.withDefault(defaultCloudflareBaseUrl), Effect.mapError((error) => configError(`CLOUDFLARE_API_BASE_URL: ${error.message}`)));
|
|
265
|
+
return workersAiTarget({ accountId, token, model, baseUrl });
|
|
266
|
+
});
|
|
231
267
|
var configuredModel = Effect.map(choice, (chosen) => chosen.kind === "endpoint" ? endpointModel(chosen.url, chosen.model) : workersAiModel(chosen.model));
|
|
232
268
|
var configuredTarget = Effect.gen(function* () {
|
|
233
269
|
const chosen = yield* choice;
|
|
234
270
|
if (chosen.kind === "endpoint")
|
|
235
271
|
return endpointTarget(chosen);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
272
|
+
return yield* resolveWorkersAi(chosen.model);
|
|
273
|
+
});
|
|
274
|
+
var configuredSecondaryTarget = Effect.gen(function* () {
|
|
275
|
+
const chosen = yield* secondaryChoice;
|
|
276
|
+
if (Option.isNone(chosen))
|
|
277
|
+
return Option.none();
|
|
278
|
+
if (chosen.value.kind === "endpoint")
|
|
279
|
+
return Option.some(endpointTarget(chosen.value));
|
|
280
|
+
return Option.some(yield* resolveWorkersAi(chosen.value.model));
|
|
241
281
|
});
|
|
242
282
|
var pack = (model, state, media, values, question) => {
|
|
243
283
|
const wire = wires[model.format];
|
|
@@ -364,13 +404,22 @@ var jsonRetryDelayMs = (text) => {
|
|
|
364
404
|
};
|
|
365
405
|
|
|
366
406
|
class DecisionModel extends Context.Service()("lint-anything/DecisionModel") {
|
|
367
|
-
static layer = (cacheDirectory) => Layer.effect(DecisionModel, Effect.
|
|
407
|
+
static layer = (cacheDirectory) => Layer.effect(DecisionModel, Effect.gen(function* () {
|
|
408
|
+
const primary = yield* configuredTarget;
|
|
409
|
+
const secondary = yield* configuredSecondaryTarget;
|
|
410
|
+
if (Option.isNone(secondary))
|
|
411
|
+
return yield* make(primary, cacheDirectory);
|
|
412
|
+
if (secondary.value.cacheKey === primary.cacheKey) {
|
|
413
|
+
return yield* configError(`secondary decision model (${secondary.value.name}) is the same as the primary model; use a different model for cascading`);
|
|
414
|
+
}
|
|
415
|
+
return yield* makeCascade(primary, secondary.value, cacheDirectory);
|
|
416
|
+
})).pipe(Layer.provide(FetchHttpClient.layer));
|
|
368
417
|
static layerFor = (target, cacheDirectory) => Layer.effect(DecisionModel, make(target, cacheDirectory)).pipe(Layer.provide(FetchHttpClient.layer));
|
|
369
418
|
static cascadeLayer = (primary, secondary, cacheDirectory, options) => Layer.effect(DecisionModel, makeCascade(primary, secondary, cacheDirectory, options)).pipe(Layer.provide(FetchHttpClient.layer));
|
|
370
419
|
}
|
|
371
420
|
var makeCascade = Effect.fnUntraced(function* (primaryTarget, secondaryTarget, cacheDirectory, options) {
|
|
372
|
-
const low = options?.low ?? 0.
|
|
373
|
-
const high = options?.high ?? 0.
|
|
421
|
+
const low = options?.low ?? 0.1;
|
|
422
|
+
const high = options?.high ?? 0.9;
|
|
374
423
|
const combine = options?.combine ?? ((a, b) => (a + b) / 2);
|
|
375
424
|
const primary = yield* make(primaryTarget, cacheDirectory);
|
|
376
425
|
const secondary = yield* make(secondaryTarget, cacheDirectory);
|
|
@@ -1142,6 +1191,7 @@ export {
|
|
|
1142
1191
|
cliThresholds,
|
|
1143
1192
|
concordance,
|
|
1144
1193
|
configuredModel,
|
|
1194
|
+
configuredSecondaryTarget,
|
|
1145
1195
|
configuredTarget,
|
|
1146
1196
|
decide,
|
|
1147
1197
|
declinesAll,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cause, Context, Effect, Layer, Redacted, Result, Runtime, Schema } from "effect";
|
|
1
|
+
import { Cause, Context, Effect, Layer, Option, Redacted, Result, Runtime, Schema } from "effect";
|
|
2
2
|
import { type MediaKind } from "./media.ts";
|
|
3
3
|
/**
|
|
4
4
|
* One yes/no question: `instructions` is what the decision model judges, and `criteria` say what a yes
|
|
@@ -138,6 +138,12 @@ export declare const configuredModel: Effect.Effect<Model, DecisionModelError>;
|
|
|
138
138
|
* `CLOUDFLARE_AUTH_TOKEN`, and optionally `CLOUDFLARE_API_BASE_URL`.
|
|
139
139
|
*/
|
|
140
140
|
export declare const configuredTarget: Effect.Effect<Target, DecisionModelError>;
|
|
141
|
+
/**
|
|
142
|
+
* The optional secondary decision model the environment configures for cascading (`LINT_ANYTHING_SECONDARY_ENDPOINT`,
|
|
143
|
+
* `LINT_ANYTHING_SECONDARY_MODEL`, `LINT_ANYTHING_SECONDARY_API_KEY`). Returns `Option.none()` when unset.
|
|
144
|
+
* Setting `LINT_ANYTHING_SECONDARY_MODEL` alone (for example `clef`) asks that Cloudflare model on Workers AI.
|
|
145
|
+
*/
|
|
146
|
+
export declare const configuredSecondaryTarget: Effect.Effect<Option.Option<Target>, DecisionModelError>;
|
|
141
147
|
/**
|
|
142
148
|
* One request: its exact body, the media its questions show (by path), and what each question id answers.
|
|
143
149
|
* The body of a request with media leaves them out; they are read, and put where its format takes them,
|
|
@@ -179,9 +185,9 @@ export declare const noUsage: Usage;
|
|
|
179
185
|
export declare const sumUsage: (usages: Iterable<Usage>) => Usage;
|
|
180
186
|
/** Configuration for cascading two decision models: a fast primary and a secondary tiebreaker. */
|
|
181
187
|
export interface CascadeOptions {
|
|
182
|
-
/** Primary probabilities below `low` are accepted directly without calling `secondary` (default: 0.
|
|
188
|
+
/** Primary probabilities below `low` are accepted directly without calling `secondary` (default: 0.10). */
|
|
183
189
|
readonly low?: number;
|
|
184
|
-
/** Primary probabilities above `high` are accepted directly without calling `secondary` (default: 0.
|
|
190
|
+
/** Primary probabilities above `high` are accepted directly without calling `secondary` (default: 0.90). */
|
|
185
191
|
readonly high?: number;
|
|
186
192
|
/** Combines primary and secondary probabilities for items sent to both (default: arithmetic mean). */
|
|
187
193
|
readonly combine?: (primary: number, secondary: number) => number;
|
|
@@ -199,9 +205,10 @@ declare const DecisionModel_base: Context.ServiceClass<DecisionModel, "lint-anyt
|
|
|
199
205
|
}>;
|
|
200
206
|
export declare class DecisionModel extends DecisionModel_base {
|
|
201
207
|
/**
|
|
202
|
-
* The decision model the environment configures (`configuredTarget`): Clef on Workers AI by default
|
|
203
|
-
*
|
|
204
|
-
*
|
|
208
|
+
* The decision model the environment configures (`configuredTarget`): Clef on Workers AI by default, or
|
|
209
|
+
* a cross-family cascade when `LINT_ANYTHING_SECONDARY_*` (`configuredSecondaryTarget`) is also set.
|
|
210
|
+
* With `cacheDirectory`, answers are cached in a database there per question across runs, and answers
|
|
211
|
+
* older than `cacheMaxAgeMs` are deleted and asked again.
|
|
205
212
|
*/
|
|
206
213
|
static readonly layer: (cacheDirectory?: string) => Layer.Layer<DecisionModel, DecisionModelError, never>;
|
|
207
214
|
/** `target`, whatever the environment says; answers are cached as with `layer`. */
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* with the metrics and bootstrap intervals the evals use; the skill's score script is built on it.
|
|
19
19
|
*/
|
|
20
20
|
import { DecisionModel, DecisionModelError } from "./decision-model.ts";
|
|
21
|
-
export { cacheMaxAgeMs, type CascadeOptions, clef, clefInputTokenPrice, configuredModel, configuredTarget, Declined, declinesAll, decodeReply, DecisionModel, DecisionModelError, endpointTarget, type Format, keyHeader, type Model, noUsage, planRequests, type Planned, type Question, RequestTooLarge, sumUsage, type Target, type Unanswered, type Usage, workersAiTarget } from "./decision-model.ts";
|
|
21
|
+
export { cacheMaxAgeMs, type CascadeOptions, clef, clefInputTokenPrice, configuredModel, configuredSecondaryTarget, configuredTarget, Declined, declinesAll, decodeReply, DecisionModel, DecisionModelError, endpointTarget, type Format, keyHeader, type Model, noUsage, planRequests, type Planned, type Question, RequestTooLarge, sumUsage, type Target, type Unanswered, type Usage, workersAiTarget } from "./decision-model.ts";
|
|
22
22
|
/** @deprecated Renamed `DecisionModel`: it asks whichever decision model is configured, Clef by default. */
|
|
23
23
|
export declare const Clef: typeof DecisionModel;
|
|
24
24
|
/** @deprecated Renamed `DecisionModel`. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrueandersoncs/lint-anything",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Check anything against plain-English policies, judged by the decision model of your choice: any System One, OpenAI Decisions, or Gemini Decisions endpoint, or Workers AI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Andrue Anderson",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "bun build index.ts --target=bun --minify --outfile dist/cli.js && bun build score.ts --target=bun --minify --outfile skills/lint-anything/scripts/score.js && bun build src/lib.ts --target=bun --external effect --external 'effect/*' --outfile dist/lib.js && rm -rf dist/types && tsc -p tsconfig.lib.json",
|
|
36
|
+
"build": "bun build index.ts --target=bun --minify --outfile dist/cli.js && bun build score.ts --target=bun --minify --outfile skills/lint-anything/scripts/score.js && bun build select-steps.ts --target=bun --minify --outfile skills/lint-anything/scripts/select.js && bun build src/lib.ts --target=bun --external effect --external 'effect/*' --outfile dist/lib.js && rm -rf dist/types && tsc -p tsconfig.lib.json",
|
|
37
37
|
"prepublishOnly": "bunx tsc --noEmit && bun run build"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -24,6 +24,7 @@ If `lint-anything` isn't found, install it with `bun add -d @andrueandersoncs/li
|
|
|
24
24
|
- **The working directory matters.** Policies are read from `./.lint-anything/rules`, and selectors run in the current directory. Run from a subdirectory and you get `error: cannot read policies in .lint-anything/rules`: there is no upward search.
|
|
25
25
|
- **The decision model** is the project's choice, set in the environment or in `.env` / `.env.local` in the current directory. Don't change it to make findings go away. With `LINT_ANYTHING_ENDPOINT` (a full URL), the model named by `LINT_ANYTHING_MODEL` is asked there, and `LINT_ANYTHING_API_KEY` is its key if it needs one. An endpoint on `generativelanguage.googleapis.com` speaks Google's Decisions API (`gemini-decision-1`, keyed by a Gemini API key); any other whose path ends in `/decisions` speaks OpenAI's; any other speaks System One (`/v1/systemone`: Jev, LiteLLM, LLM Gateway, and most decision-model servers).
|
|
26
26
|
- **Without an endpoint**, a Cloudflare model on Workers AI is asked: `clef`, or another that `LINT_ANYTHING_MODEL` names (`clef-flash`). `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_AUTH_TOKEN` are then required on every run, even when every answer would come from the cache. `CLOUDFLARE_API_BASE_URL` is optional.
|
|
27
|
+
- **Optional cross-family cascading**: setting `LINT_ANYTHING_SECONDARY_MODEL` (plus optionally `LINT_ANYTHING_SECONDARY_ENDPOINT` and `LINT_ANYTHING_SECONDARY_API_KEY`; or `LINT_ANYTHING_SECONDARY_MODEL=clef` alone for Workers AI) asks the primary model first and escalates only uncertain items in `[0.10, 0.90]` to the secondary model, averaging both answers. On the 216-file unseen holdout (H32/H34), `Gemini Decision 1 → Clef` cut false alarms nearly in half (`12.8% → 6.8%`) and cost less than single-model Clef while sharing the same SQLite cache.
|
|
27
28
|
- **What the model can see** besides text depends on it: Gemini Decision 1 and `clef-omni` take images, audio, and video; OpenAI Decisions, `clef`, and `clef-flash` take images only; another System One server takes what it takes. An item whose media the model can't take stops the run before anything is sent (`Clef takes text and images, not audio clips: …`).
|
|
28
29
|
- **Accuracy numbers in this skill were measured on Clef**, on text. A project on another model, or with media, should score its policies on its labels before trusting them.
|
|
29
30
|
- **Add `.lint-anything/cache` to `.gitignore`.** The answer cache (`answers.sqlite` plus `-wal`/`-shm` files) is written there.
|
|
@@ -198,7 +199,19 @@ rg --json -U -P '^(?:[ \t]*(?://|#).*\n)+.*' -g '*.{ts,py,go}' |
|
|
|
198
199
|
lines: [.data.line_number, .data.line_number + ($t | split("\n") | length) - 1], text: $t}'
|
|
199
200
|
```
|
|
200
201
|
|
|
201
|
-
Structural units with
|
|
202
|
+
Structural units with the bundled selector helper (`scripts/select.js`, run `--help` to see every step and flag):
|
|
203
|
+
|
|
204
|
+
```yaml
|
|
205
|
+
select: |
|
|
206
|
+
rg --files -g '*.{ts,tsx,js,py,go}' |
|
|
207
|
+
bun <this skill's directory>/scripts/select.js functions --flags --no-call-items |
|
|
208
|
+
bun <this skill's directory>/scripts/select.js file-role |
|
|
209
|
+
bun <this skill's directory>/scripts/select.js present --no-lines
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`scripts/select.js` bundles the eval-proven file cutters (`functions`, `comments`, `errors`, `errors-go`, `literals`, `module-exports`, `module-state`, `module-outline`, `tests`, `duplicates`, `excerpts`, `whole-file`) and pipe steps (`file-role`, `enclosing`, `blame`, `present`). Steps that parse ASTs resolve `ast-grep` from `PATH` or `./node_modules/.bin/ast-grep` (install with `bun add -d @ast-grep/cli`). Copy `scripts/select.js` into `.lint-anything/lib/select.js` (or reference it from `node_modules/@andrueandersoncs/lint-anything/skills/lint-anything/scripts/select.js`) so CI and teammates share the exact same selector path. Pass `--no-lines` to `present` to omit `(lines start-end)` from `text` and preserve cache hits when lines above shift.
|
|
213
|
+
|
|
214
|
+
Or write a custom ast-grep selector directly:
|
|
202
215
|
|
|
203
216
|
```sh
|
|
204
217
|
ast-grep run -p 'function $NAME($$$PARAMS) { $$$BODY }' -l ts --json=stream |
|
|
@@ -265,7 +278,7 @@ One JSON object per line, one per labeled file:
|
|
|
265
278
|
- Where they disagree, or any of them calls it ambiguous, **ask the user** about that file, showing the rule, the code, and each model's reasoning. Record what the user decides; if the user says reasonable reviewers could disagree, record `ambiguous`. Ambiguous files are left out of AUROC and counted as right when they land in `review`.
|
|
266
279
|
- One model alone labels with its own reading of the rule, and tuning against those labels only makes the policy agree with that reading.
|
|
267
280
|
|
|
268
|
-
The lint-anything repository has worked examples: 21 policies in `evals/corpus/policies/` and the
|
|
281
|
+
The lint-anything repository has worked examples: 21 policies in `evals/corpus/policies/` and the source of the bundled `scripts/select.js` helpers in `evals/steps/`. Its evals score them the same way, against a labeled corpus. `$EVAL_STEPS` exists only inside those evals; in real projects use `scripts/select.js` (or copy it into `.lint-anything/lib/`).
|
|
269
282
|
|
|
270
283
|
## Cache and cost
|
|
271
284
|
|