@r_masseater/oxlint-plugin-decision 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/dist/{src-CknkhDKf.mjs → app-Bso1uwY5.mjs} +18 -142
- package/dist/app-Bso1uwY5.mjs.map +1 -0
- package/dist/cloudflare-worker.mjs +6 -182
- package/dist/cloudflare-worker.mjs.map +1 -1
- package/dist/decision-BtTZ52be.mjs +643 -0
- package/dist/decision-BtTZ52be.mjs.map +1 -0
- package/dist/{presets-CxYinkkJ.mjs → define-presets-clyqLZxo.mjs} +197 -17
- package/dist/define-presets-clyqLZxo.mjs.map +1 -0
- package/dist/index-BOrpK3Iv.d.mts +89 -0
- package/dist/{index-DiH-hZUS.d.mts → index-Cgg-w0hb.d.mts} +5 -7
- package/dist/index-D7VrRpTx.d.mts +6 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +1 -1
- package/dist/openrouter-app.d.mts +8 -4
- package/dist/openrouter-app.mjs +1 -89
- package/dist/openrouter-worker.mjs +5 -36
- package/dist/openrouter-worker.mjs.map +1 -1
- package/dist/preset-plugin-AAwedMeS.mjs +10 -0
- package/dist/preset-plugin-AAwedMeS.mjs.map +1 -0
- package/dist/presets/ai-slop.d.mts +4 -13
- package/dist/presets/ai-slop.mjs +3 -183
- package/dist/presets/ai-slop.mjs.map +1 -1
- package/dist/presets/index.d.mts +2 -78
- package/dist/presets/index.mjs +1 -1
- package/dist/presets/recommended.d.mts +2 -1
- package/dist/presets/recommended.mjs +3 -2
- package/dist/presets/recommended.mjs.map +1 -1
- package/dist/presets/review-only.d.mts +2 -1
- package/dist/presets/review-only.mjs +3 -2
- package/dist/presets/review-only.mjs.map +1 -1
- package/dist/presets/strict.d.mts +2 -1
- package/dist/presets/strict.mjs +3 -2
- package/dist/presets/strict.mjs.map +1 -1
- package/dist/serve-decisions-CjlhvYm7.mjs +290 -0
- package/dist/serve-decisions-CjlhvYm7.mjs.map +1 -0
- package/package.json +4 -4
- package/skills/write-decision-rules/SKILL.md +15 -14
- package/skills/write-decision-rules/references/tuning.md +1 -1
- package/dist/openrouter-app.mjs.map +0 -1
- package/dist/presets-CxYinkkJ.mjs.map +0 -1
- package/dist/runtime-CICpEidL.mjs +0 -271
- package/dist/runtime-CICpEidL.mjs.map +0 -1
- package/dist/select-bvQylrUt.mjs +0 -12
- package/dist/select-bvQylrUt.mjs.map +0 -1
- package/dist/serve-decisions-BM0bUWWe.mjs +0 -119
- package/dist/serve-decisions-BM0bUWWe.mjs.map +0 -1
- package/dist/src-CknkhDKf.mjs.map +0 -1
- package/dist/wire-CRD1mSAo.mjs +0 -251
- package/dist/wire-CRD1mSAo.mjs.map +0 -1
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { Array, Cause, Config, Console, DateTime, Effect, Exit, Function, Option, Predicate, Record, Result, Schema, String as String$1, pipe } from "effect";
|
|
2
|
-
// src/schema.ts
|
|
3
|
-
const NONE = 0;
|
|
4
|
-
const MINIMUM_LABELS = 2;
|
|
5
|
-
const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(NONE));
|
|
6
|
-
const Probability = Schema.Finite.check(Schema.isBetween({
|
|
7
|
-
minimum: 0,
|
|
8
|
-
maximum: 1
|
|
9
|
-
}));
|
|
10
|
-
const CONFIDENT = .8;
|
|
11
|
-
const Cutoff = Schema.Finite.check(Schema.isBetween({
|
|
12
|
-
minimum: CONFIDENT,
|
|
13
|
-
maximum: 1
|
|
14
|
-
}, { message: `cutoff must be between ${CONFIDENT} and 1` }));
|
|
15
|
-
const TargetSchema = Schema.Literals([
|
|
16
|
-
"function",
|
|
17
|
-
"call",
|
|
18
|
-
"jsx",
|
|
19
|
-
"file"
|
|
20
|
-
]);
|
|
21
|
-
const CiBehaviorSchema = Schema.Literals(["skip", "fail"]);
|
|
22
|
-
const ExplainSettingSchema = Schema.Union([Schema.Boolean, Schema.Literals(["text", "json"])]);
|
|
23
|
-
const EnclosingKindSchema = Schema.Literals([
|
|
24
|
-
"function",
|
|
25
|
-
"class",
|
|
26
|
-
"block"
|
|
27
|
-
]);
|
|
28
|
-
const RuleContextSchema = Schema.Union([
|
|
29
|
-
Schema.Struct({ scope: Schema.Literals([
|
|
30
|
-
"node",
|
|
31
|
-
"file",
|
|
32
|
-
"comment"
|
|
33
|
-
]) }),
|
|
34
|
-
Schema.Struct({
|
|
35
|
-
scope: Schema.Literal("lines"),
|
|
36
|
-
before: Schema.optionalKey(NonNegativeInt),
|
|
37
|
-
after: Schema.optionalKey(NonNegativeInt)
|
|
38
|
-
}),
|
|
39
|
-
Schema.Struct({
|
|
40
|
-
scope: Schema.Literal("enclosing"),
|
|
41
|
-
kind: EnclosingKindSchema
|
|
42
|
-
})
|
|
43
|
-
]);
|
|
44
|
-
const SeveritySchema = Schema.Literals([
|
|
45
|
-
"info",
|
|
46
|
-
"warn",
|
|
47
|
-
"error"
|
|
48
|
-
]);
|
|
49
|
-
const Label = Schema.NonEmptyString;
|
|
50
|
-
const BooleanAnswer = Schema.Struct({ kind: Schema.Literal("boolean") });
|
|
51
|
-
const ClassifyAnswer = Schema.Struct({
|
|
52
|
-
kind: Schema.Literal("classify"),
|
|
53
|
-
labels: Schema.Record(Label, Schema.String).check(Schema.isMinProperties(MINIMUM_LABELS)),
|
|
54
|
-
report: Schema.NonEmptyArray(Label)
|
|
55
|
-
}).check(Schema.makeFilter(({ labels, report }) => pipe(report, Array.every((label) => Record.has(labels, label))), { message: "every label in report must be one of labels" }));
|
|
56
|
-
const SeverityAnswer = Schema.Struct({
|
|
57
|
-
kind: Schema.Literal("severity"),
|
|
58
|
-
minimum: Schema.optionalKey(SeveritySchema)
|
|
59
|
-
});
|
|
60
|
-
const RuleAnswerSchema = Schema.Union([
|
|
61
|
-
BooleanAnswer,
|
|
62
|
-
ClassifyAnswer,
|
|
63
|
-
SeverityAnswer
|
|
64
|
-
]);
|
|
65
|
-
// src/answer.ts
|
|
66
|
-
const DATA_FIRST_ARITY$2 = 2;
|
|
67
|
-
const YES = "yes";
|
|
68
|
-
const DEFAULT_MINIMUM = "warn";
|
|
69
|
-
const SEVERITY_CRITERIA = {
|
|
70
|
-
none: "No problem",
|
|
71
|
-
info: "Worth noting, but not a problem",
|
|
72
|
-
warn: "Likely a problem",
|
|
73
|
-
error: "Clearly a problem"
|
|
74
|
-
};
|
|
75
|
-
const SEVERITY_ORDER = Record.keys(SEVERITY_CRITERIA);
|
|
76
|
-
const BOOLEAN_ANSWER = { kind: "boolean" };
|
|
77
|
-
const decodeAnswer = Schema.decodeUnknownResult(RuleAnswerSchema);
|
|
78
|
-
const decodeRuleAnswer = (answer) => {
|
|
79
|
-
const decoded = decodeAnswer(answer);
|
|
80
|
-
if (Result.isSuccess(decoded)) return Result.succeed(decoded.success);
|
|
81
|
-
return Result.fail(decoded.failure.message);
|
|
82
|
-
};
|
|
83
|
-
const NoulAnswerSchema = Schema.Struct({
|
|
84
|
-
type: Schema.Literal("noul"),
|
|
85
|
-
noul: Probability
|
|
86
|
-
});
|
|
87
|
-
const ChoiceAnswerSchema = Schema.Struct({
|
|
88
|
-
type: Schema.Literal("choice"),
|
|
89
|
-
choice: Schema.String,
|
|
90
|
-
probabilities: Schema.optional(Schema.Record(Schema.String, Probability))
|
|
91
|
-
});
|
|
92
|
-
const AnswerSchema = Schema.Union([NoulAnswerSchema, ChoiceAnswerSchema]);
|
|
93
|
-
const decodeNoul = Schema.decodeOption(NoulAnswerSchema);
|
|
94
|
-
const decodeChoice = Schema.decodeOption(ChoiceAnswerSchema);
|
|
95
|
-
const isNoul = (answer) => answer.type === "noul";
|
|
96
|
-
const isChoice = (answer) => answer.type === "choice";
|
|
97
|
-
const noulOf = (answer) => Option.fromUndefinedOr(answer).pipe(Option.filter(isNoul), Option.flatMap(decodeNoul));
|
|
98
|
-
const choiceOf = (answer) => Option.fromUndefinedOr(answer).pipe(Option.filter(isChoice), Option.flatMap(decodeChoice));
|
|
99
|
-
const probabilityOfChoice = ({ choice, probabilities }) => Option.fromUndefinedOr(probabilities).pipe(Option.flatMap((byLabel) => Option.fromUndefinedOr(byLabel[choice])));
|
|
100
|
-
const questionFor = Function.dual(DATA_FIRST_ARITY$2, (answer, instructions) => {
|
|
101
|
-
switch (answer.kind) {
|
|
102
|
-
case "classify": return {
|
|
103
|
-
type: "choice",
|
|
104
|
-
instructions: `${instructions} Select the label that fits best.`,
|
|
105
|
-
criteria: answer.labels
|
|
106
|
-
};
|
|
107
|
-
case "severity": return {
|
|
108
|
-
type: "choice",
|
|
109
|
-
instructions: `${instructions} Rate how serious the problem is, and select none if there is no problem.`,
|
|
110
|
-
criteria: SEVERITY_CRITERIA
|
|
111
|
-
};
|
|
112
|
-
case "boolean": return {
|
|
113
|
-
type: "noul",
|
|
114
|
-
instructions
|
|
115
|
-
};
|
|
116
|
-
default: return {
|
|
117
|
-
type: "noul",
|
|
118
|
-
instructions
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
const choiceVerdictOf = (criteria, answer) => choiceOf(answer).pipe(Option.filter(({ choice }) => Record.has(criteria, choice)), Option.flatMap((chosen) => Option.map(probabilityOfChoice(chosen), (probability) => ({
|
|
123
|
-
answer: chosen.choice,
|
|
124
|
-
probability
|
|
125
|
-
}))));
|
|
126
|
-
const verdictOf = Function.dual(DATA_FIRST_ARITY$2, (question, answer) => {
|
|
127
|
-
if (question.type === "choice") return choiceVerdictOf(question.criteria, answer);
|
|
128
|
-
return noulOf(answer).pipe(Option.map(({ noul }) => ({
|
|
129
|
-
answer: YES,
|
|
130
|
-
probability: noul
|
|
131
|
-
})));
|
|
132
|
-
});
|
|
133
|
-
const severityMatches = ({ minimum = DEFAULT_MINIMUM }, label) => SEVERITY_ORDER.indexOf(label) >= SEVERITY_ORDER.indexOf(minimum);
|
|
134
|
-
const answerMatches = (answer, label) => {
|
|
135
|
-
switch (answer.kind) {
|
|
136
|
-
case "classify": return answer.report.includes(label);
|
|
137
|
-
case "severity": return severityMatches(answer, label);
|
|
138
|
-
case "boolean": return label === YES;
|
|
139
|
-
default: return false;
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
const isReported = Function.dual(DATA_FIRST_ARITY$2, (rule, verdict) => verdict.probability >= rule.cutoff && answerMatches(rule.answer, verdict.answer));
|
|
143
|
-
// src/options.ts
|
|
144
|
-
const DATA_FIRST_ARITY_3 = 3;
|
|
145
|
-
const DATA_FIRST_ARITY$1 = 2;
|
|
146
|
-
const PREFIX = "oxlint-plugin-decision";
|
|
147
|
-
const PROVIDER_SEPARATOR = "/";
|
|
148
|
-
const ONE_RULE = 1;
|
|
149
|
-
const DEFAULTS = {
|
|
150
|
-
ci: "fail",
|
|
151
|
-
timeoutMs: 1e4,
|
|
152
|
-
maxSnippetChars: 4e3,
|
|
153
|
-
model: "cloudflare/@cf/qwen/qwen3.8-27b",
|
|
154
|
-
env: {},
|
|
155
|
-
explain: false
|
|
156
|
-
};
|
|
157
|
-
const isSelector = (input) => Predicate.isFunction(input);
|
|
158
|
-
const RULE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
159
|
-
const ModelSpecSchema = Schema.Union([Schema.NonEmptyString, Schema.NonEmptyArray(Schema.NonEmptyString)]);
|
|
160
|
-
const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
|
|
161
|
-
const RuleId = Schema.NonEmptyString.check(Schema.isPattern(RULE_ID, { message: "id must be lowercase words joined by hyphens" }));
|
|
162
|
-
const OptionsSchema = Schema.Struct({
|
|
163
|
-
ci: Schema.optionalKey(CiBehaviorSchema),
|
|
164
|
-
timeoutMs: Schema.optionalKey(PositiveInt),
|
|
165
|
-
maxSnippetChars: Schema.optionalKey(PositiveInt),
|
|
166
|
-
model: Schema.optionalKey(ModelSpecSchema),
|
|
167
|
-
env: Schema.optionalKey(Schema.Record(Schema.NonEmptyString, Schema.NonEmptyString)),
|
|
168
|
-
explain: Schema.optionalKey(ExplainSettingSchema)
|
|
169
|
-
});
|
|
170
|
-
const RuleSchema = Schema.Struct({
|
|
171
|
-
id: RuleId,
|
|
172
|
-
target: TargetSchema,
|
|
173
|
-
question: Schema.NonEmptyString,
|
|
174
|
-
cutoff: Cutoff,
|
|
175
|
-
message: Schema.optionalKey(Schema.NonEmptyString),
|
|
176
|
-
select: Schema.optionalKey(Schema.declare(isSelector)),
|
|
177
|
-
location: Schema.optionalKey(Schema.Struct({
|
|
178
|
-
question: Schema.NonEmptyString,
|
|
179
|
-
cutoff: Cutoff
|
|
180
|
-
})),
|
|
181
|
-
model: Schema.optionalKey(ModelSpecSchema),
|
|
182
|
-
context: Schema.optionalKey(RuleContextSchema),
|
|
183
|
-
answer: Schema.optionalKey(Schema.Unknown)
|
|
184
|
-
});
|
|
185
|
-
const STRICT = { onExcessProperty: "error" };
|
|
186
|
-
const decodeOptions = Schema.decodeUnknownResult(OptionsSchema, STRICT);
|
|
187
|
-
const decodeRule = Schema.decodeUnknownResult(RuleSchema, STRICT);
|
|
188
|
-
const taggedError = Schema.TaggedError;
|
|
189
|
-
var OptionsError = class extends taggedError()("OptionsError", { message: Schema.String }) {};
|
|
190
|
-
const optionsError = (message) => OptionsError.make({ message: `${PREFIX}: ${message}` });
|
|
191
|
-
const modelIdsOf = (spec) => Array.dedupe(Array.ensure(spec));
|
|
192
|
-
const splitModelId = (id) => {
|
|
193
|
-
const [provider, ...rest] = String$1.split(id, PROVIDER_SEPARATOR);
|
|
194
|
-
const model = pipe(rest, Array.join(PROVIDER_SEPARATOR));
|
|
195
|
-
return Option.liftPredicate([provider, model], ([left, right]) => String$1.isNonEmpty(left) && String$1.isNonEmpty(right));
|
|
196
|
-
};
|
|
197
|
-
const resolveModel = Function.dual(DATA_FIRST_ARITY$1, (id, providers) => splitModelId(id).pipe(Option.flatMap(([name, model]) => Option.map(Option.fromUndefinedOr(providers[name]), (provider) => ({
|
|
198
|
-
id,
|
|
199
|
-
provider,
|
|
200
|
-
model
|
|
201
|
-
}))), Option.getOrThrowWith(() => optionsError(`model "${id}" must be "<provider>/<model>" with a provider from: ${pipe(Record.keys(providers), Array.join(", "))}`))));
|
|
202
|
-
const duplicateIdOf = (rules) => Array.findFirst(Record.toEntries(Array.groupBy(rules, ({ id }) => id)), ([, same]) => same.length > ONE_RULE).pipe(Option.map(([id]) => id));
|
|
203
|
-
const answerOf = (rule) => {
|
|
204
|
-
if (Predicate.isUndefined(rule.answer)) return BOOLEAN_ANSWER;
|
|
205
|
-
return Result.getOrThrowWith(decodeRuleAnswer(rule.answer), (issue) => optionsError(`rule "${rule.id}" has an invalid answer: ${issue}`));
|
|
206
|
-
};
|
|
207
|
-
const checked = Function.dual(DATA_FIRST_ARITY_3, (decode, input, what) => Result.getOrThrowWith(decode(input), (issue) => optionsError(`invalid ${what}: ${issue.message}`)));
|
|
208
|
-
const checkRule = (rule) => {
|
|
209
|
-
checked(decodeRule, rule, `rule "${rule.id}"`);
|
|
210
|
-
if (Predicate.isNotUndefined(rule.location) && rule.target !== "file") throw optionsError("location is supported only for file rules");
|
|
211
|
-
answerOf(rule);
|
|
212
|
-
return rule;
|
|
213
|
-
};
|
|
214
|
-
const checkRules = (rules) => {
|
|
215
|
-
if (!Array.isReadonlyArrayNonEmpty(rules)) throw optionsError("rules must list at least one rule");
|
|
216
|
-
Option.map(duplicateIdOf(rules), (duplicate) => {
|
|
217
|
-
throw optionsError(`rule id "${duplicate}" is used more than once`);
|
|
218
|
-
});
|
|
219
|
-
return pipe(rules, Array.map((rule) => checkRule(rule)));
|
|
220
|
-
};
|
|
221
|
-
const resolveRule = (fallback, providers) => (rule) => ({
|
|
222
|
-
...rule,
|
|
223
|
-
answer: answerOf(rule),
|
|
224
|
-
models: pipe(modelIdsOf(rule.model ?? fallback), Array.map((id) => resolveModel(id, providers)))
|
|
225
|
-
});
|
|
226
|
-
const settingsFrom = (settings) => {
|
|
227
|
-
if (Predicate.isUndefined(settings)) return {};
|
|
228
|
-
return checked(decodeOptions, settings, "settings");
|
|
229
|
-
};
|
|
230
|
-
const resolveOptions = Function.dual(DATA_FIRST_ARITY_3, ({ options, settings }, rules, providers) => {
|
|
231
|
-
const fromCode = checked(decodeOptions, options, "createDecisionPlugin options");
|
|
232
|
-
const { model, ...merged } = {
|
|
233
|
-
...DEFAULTS,
|
|
234
|
-
...fromCode,
|
|
235
|
-
...settingsFrom(settings)
|
|
236
|
-
};
|
|
237
|
-
return {
|
|
238
|
-
ci: merged.ci,
|
|
239
|
-
timeoutMs: merged.timeoutMs,
|
|
240
|
-
maxSnippetChars: merged.maxSnippetChars,
|
|
241
|
-
env: merged.env,
|
|
242
|
-
explain: merged.explain,
|
|
243
|
-
rules: pipe(checkRules(rules), Array.map((rule) => resolveRule(model, providers)(rule)))
|
|
244
|
-
};
|
|
245
|
-
});
|
|
246
|
-
// src/runtime.ts
|
|
247
|
-
const DATA_FIRST_ARITY = 2;
|
|
248
|
-
const encodeJson = Schema.encodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
249
|
-
const toJson = (value) => Option.getOrElse(encodeJson(value), () => String(value));
|
|
250
|
-
const nowMs = () => DateTime.toEpochMillis(DateTime.nowUnsafe());
|
|
251
|
-
const runOrElse = Function.dual(DATA_FIRST_ARITY, (effect, fallback) => Exit.match(Effect.runSyncExit(effect), {
|
|
252
|
-
onSuccess: (value) => value,
|
|
253
|
-
onFailure: (cause) => fallback(Cause.squash(cause))
|
|
254
|
-
}));
|
|
255
|
-
const envOf = (name) => runOrElse(Config.option(Config.NonEmptyString(name)), () => Option.none()).pipe(Option.map((value) => String$1.trim(value)), Option.filter(String$1.isNonEmpty));
|
|
256
|
-
const envNameOf = Function.dual(DATA_FIRST_ARITY, (env, name) => env[name] ?? name);
|
|
257
|
-
const failsInCi = (options) => options.ci === "fail" && Option.isSome(envOf("CI"));
|
|
258
|
-
const warned = /* @__PURE__ */ new Set();
|
|
259
|
-
const warnOnce = Function.dual(DATA_FIRST_ARITY, (reason, message) => {
|
|
260
|
-
if (warned.has(reason)) return;
|
|
261
|
-
warned.add(reason);
|
|
262
|
-
Effect.runFork(Console.warn(`${PREFIX}: ${message}`));
|
|
263
|
-
});
|
|
264
|
-
const messageOf = (error) => {
|
|
265
|
-
if (error instanceof Error) return error.message;
|
|
266
|
-
return String(error);
|
|
267
|
-
};
|
|
268
|
-
const captured = Function.dual(DATA_FIRST_ARITY, (match, name) => match.pipe(Option.flatMap((found) => Option.fromNullishOr(found.groups)), Option.flatMap((groups) => Option.fromNullishOr(groups[name]))));
|
|
269
|
-
export { noulOf as C, CONFIDENT as D, verdictOf as E, isReported as S, questionFor as T, resolveModel as _, messageOf as a, SEVERITY_ORDER as b, toJson as c, PREFIX as d, STRICT as f, optionsError as g, modelIdsOf as h, failsInCi as i, warnOnce as l, checked as m, envNameOf as n, nowMs as o, checkRules as p, envOf as r, runOrElse as s, captured as t, ModelSpecSchema as u, resolveOptions as v, probabilityOfChoice as w, choiceOf as x, AnswerSchema as y };
|
|
270
|
-
|
|
271
|
-
//# sourceMappingURL=runtime-CICpEidL.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-CICpEidL.mjs","names":["Arr","Rec","DATA_FIRST_ARITY","Rec","Fn","DATA_FIRST_ARITY","Arr","Str","Fn","Rec","Fn","Str"],"sources":["../src/schema.ts","../src/answer.ts","../src/options.ts","../src/runtime.ts"],"sourcesContent":["import { Schema, Array as Arr, Record as Rec, pipe } from \"effect\";\n\nconst NONE = 0;\nconst MINIMUM_LABELS = 2;\n\nconst NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(NONE));\n\nexport const Probability = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 1 }));\n\nexport const CONFIDENT = 0.8;\n\nexport const Cutoff = Schema.Finite.check(\n Schema.isBetween(\n { minimum: CONFIDENT, maximum: 1 },\n { message: `cutoff must be between ${CONFIDENT} and 1` },\n ),\n);\n\nexport const TargetSchema = Schema.Literals([\"function\", \"call\", \"jsx\", \"file\"]);\n\nexport const CiBehaviorSchema = Schema.Literals([\"skip\", \"fail\"]);\n\nexport const ExplainSettingSchema = Schema.Union([\n Schema.Boolean,\n Schema.Literals([\"text\", \"json\"]),\n]);\n\nexport const EnclosingKindSchema = Schema.Literals([\"function\", \"class\", \"block\"]);\n\nexport const RuleContextSchema = Schema.Union([\n Schema.Struct({ scope: Schema.Literals([\"node\", \"file\", \"comment\"]) }),\n Schema.Struct({\n scope: Schema.Literal(\"lines\"),\n before: Schema.optionalKey(NonNegativeInt),\n after: Schema.optionalKey(NonNegativeInt),\n }),\n Schema.Struct({ scope: Schema.Literal(\"enclosing\"), kind: EnclosingKindSchema }),\n]);\n\nexport const SeveritySchema = Schema.Literals([\"info\", \"warn\", \"error\"]);\n\nconst Label = Schema.NonEmptyString;\n\nconst BooleanAnswer = Schema.Struct({ kind: Schema.Literal(\"boolean\") });\n\nconst ClassifyAnswer = Schema.Struct({\n kind: Schema.Literal(\"classify\"),\n labels: Schema.Record(Label, Schema.String).check(Schema.isMinProperties(MINIMUM_LABELS)),\n report: Schema.NonEmptyArray(Label),\n}).check(\n Schema.makeFilter(\n ({ labels, report }) =>\n pipe(\n report,\n Arr.every((label) => Rec.has(labels, label)),\n ),\n {\n message: \"every label in report must be one of labels\",\n },\n ),\n);\n\nconst SeverityAnswer = Schema.Struct({\n kind: Schema.Literal(\"severity\"),\n minimum: Schema.optionalKey(SeveritySchema),\n});\n\nexport const RuleAnswerSchema = Schema.Union([BooleanAnswer, ClassifyAnswer, SeverityAnswer]);\n","import { Option, Result, Schema, Record as Rec, Function as Fn } from \"effect\";\n\nimport { Probability, RuleAnswerSchema } from \"./schema.ts\";\nimport type {\n Answer,\n ChoiceAnswer,\n NoulAnswer,\n Question,\n RuleAnswer,\n Severity,\n Verdict,\n} from \"./types.ts\";\n\nconst DATA_FIRST_ARITY = 2;\n\nconst YES = \"yes\";\nconst DEFAULT_MINIMUM: Severity = \"warn\";\n\nconst SEVERITY_CRITERIA = {\n none: \"No problem\",\n info: \"Worth noting, but not a problem\",\n warn: \"Likely a problem\",\n error: \"Clearly a problem\",\n} as const;\n\nexport const SEVERITY_ORDER: readonly string[] = Rec.keys(SEVERITY_CRITERIA);\n\nexport const BOOLEAN_ANSWER: RuleAnswer = { kind: \"boolean\" };\n\nconst decodeAnswer = Schema.decodeUnknownResult(RuleAnswerSchema);\n\nexport const decodeRuleAnswer = (answer: unknown): Result.Result<RuleAnswer, string> => {\n const decoded = decodeAnswer(answer);\n if (Result.isSuccess(decoded)) {\n return Result.succeed(decoded.success);\n }\n return Result.fail(decoded.failure.message);\n};\n\nconst NoulAnswerSchema = Schema.Struct({ type: Schema.Literal(\"noul\"), noul: Probability });\n\nconst ChoiceAnswerSchema = Schema.Struct({\n type: Schema.Literal(\"choice\"),\n choice: Schema.String,\n probabilities: Schema.optional(Schema.Record(Schema.String, Probability)),\n} satisfies Partial<Record<keyof ChoiceAnswer, Schema.Top>>);\n\nexport const AnswerSchema = Schema.Union([NoulAnswerSchema, ChoiceAnswerSchema]);\n\nconst decodeNoul = Schema.decodeOption(NoulAnswerSchema);\n\nconst decodeChoice = Schema.decodeOption(ChoiceAnswerSchema);\n\nconst isNoul = (answer: Answer): answer is NoulAnswer => answer.type === \"noul\";\n\nconst isChoice = (answer: Answer): answer is ChoiceAnswer => answer.type === \"choice\";\n\nexport const noulOf = (answer: Answer | undefined): Option.Option<NoulAnswer> =>\n Option.fromUndefinedOr(answer).pipe(Option.filter(isNoul), Option.flatMap(decodeNoul));\n\nexport const choiceOf = (answer: Answer | undefined): Option.Option<ChoiceAnswer> =>\n Option.fromUndefinedOr(answer).pipe(Option.filter(isChoice), Option.flatMap(decodeChoice));\n\nexport const probabilityOfChoice = ({\n choice,\n probabilities,\n}: ChoiceAnswer): Option.Option<number> =>\n Option.fromUndefinedOr(probabilities).pipe(\n Option.flatMap((byLabel) => Option.fromUndefinedOr(byLabel[choice])),\n );\n\nexport const questionFor: {\n (instructions: string): (answer: RuleAnswer) => Question;\n (answer: RuleAnswer, instructions: string): Question;\n} = Fn.dual(DATA_FIRST_ARITY, (answer: RuleAnswer, instructions: string): Question => {\n switch (answer.kind) {\n case \"classify\": {\n return {\n type: \"choice\",\n instructions: `${instructions} Select the label that fits best.`,\n criteria: answer.labels,\n };\n }\n case \"severity\": {\n return {\n type: \"choice\",\n instructions: `${instructions} Rate how serious the problem is, and select none if there is no problem.`,\n criteria: SEVERITY_CRITERIA,\n };\n }\n case \"boolean\": {\n return { type: \"noul\", instructions };\n }\n default: {\n return { type: \"noul\", instructions };\n }\n }\n});\n\nconst choiceVerdictOf = (\n criteria: Readonly<Record<string, unknown>>,\n answer: Answer | undefined,\n): Option.Option<Verdict> =>\n choiceOf(answer).pipe(\n Option.filter(({ choice }) => Rec.has(criteria, choice)),\n Option.flatMap((chosen) =>\n Option.map(probabilityOfChoice(chosen), (probability) => ({\n answer: chosen.choice,\n probability,\n })),\n ),\n );\n\nexport const verdictOf: {\n (answer: Answer | undefined): (question: Question) => Option.Option<Verdict>;\n (question: Question, answer: Answer | undefined): Option.Option<Verdict>;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (question: Question, answer: Answer | undefined): Option.Option<Verdict> => {\n if (question.type === \"choice\") {\n return choiceVerdictOf(question.criteria, answer);\n }\n return noulOf(answer).pipe(Option.map(({ noul }) => ({ answer: YES, probability: noul })));\n },\n);\n\nconst severityMatches = (\n { minimum = DEFAULT_MINIMUM }: { readonly minimum?: Severity },\n label: string,\n): boolean => SEVERITY_ORDER.indexOf(label) >= SEVERITY_ORDER.indexOf(minimum);\n\nconst answerMatches = (answer: RuleAnswer, label: string): boolean => {\n switch (answer.kind) {\n case \"classify\": {\n return answer.report.includes(label);\n }\n case \"severity\": {\n return severityMatches(answer, label);\n }\n case \"boolean\": {\n return label === YES;\n }\n default: {\n return false;\n }\n }\n};\n\nexport const isReported: {\n (verdict: Verdict): (rule: { readonly answer: RuleAnswer; readonly cutoff: number }) => boolean;\n (rule: { readonly answer: RuleAnswer; readonly cutoff: number }, verdict: Verdict): boolean;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (rule: { readonly answer: RuleAnswer; readonly cutoff: number }, verdict: Verdict): boolean =>\n verdict.probability >= rule.cutoff && answerMatches(rule.answer, verdict.answer),\n);\n","import {\n Array as Arr,\n Option,\n Predicate,\n Result,\n Schema,\n String as Str,\n Record as Rec,\n pipe,\n Function as Fn,\n} from \"effect\";\n\nimport { BOOLEAN_ANSWER, decodeRuleAnswer } from \"./answer.ts\";\nimport {\n CiBehaviorSchema,\n Cutoff,\n ExplainSettingSchema,\n RuleContextSchema,\n TargetSchema,\n} from \"./schema.ts\";\nimport type {\n DecisionOptions,\n DecisionProvider,\n DecisionRule,\n ModelRef,\n ModelSpec,\n ResolvedOptions,\n ResolvedRule,\n RuleAnswer,\n} from \"./types.ts\";\n\nconst DATA_FIRST_ARITY_3 = 3;\n\nconst DATA_FIRST_ARITY = 2;\n\nexport const PREFIX = \"oxlint-plugin-decision\";\nconst PROVIDER_SEPARATOR = \"/\";\nconst ONE_RULE = 1;\n\nconst DEFAULTS = {\n ci: \"fail\",\n timeoutMs: 10_000,\n maxSnippetChars: 4000,\n model: \"cloudflare/@cf/qwen/qwen3.8-27b\",\n env: {},\n explain: false,\n} as const satisfies Required<DecisionOptions>;\n\nconst isSelector = (input: unknown): input is DecisionRule[\"select\"] => Predicate.isFunction(input);\n\nconst RULE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;\n\nexport const ModelSpecSchema = Schema.Union([\n Schema.NonEmptyString,\n Schema.NonEmptyArray(Schema.NonEmptyString),\n]);\n\nconst ONE = 1;\n\nconst PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(ONE));\n\nconst RuleId = Schema.NonEmptyString.check(\n Schema.isPattern(RULE_ID, { message: \"id must be lowercase words joined by hyphens\" }),\n);\n\nconst OptionsSchema = Schema.Struct({\n ci: Schema.optionalKey(CiBehaviorSchema),\n timeoutMs: Schema.optionalKey(PositiveInt),\n maxSnippetChars: Schema.optionalKey(PositiveInt),\n model: Schema.optionalKey(ModelSpecSchema),\n env: Schema.optionalKey(Schema.Record(Schema.NonEmptyString, Schema.NonEmptyString)),\n explain: Schema.optionalKey(ExplainSettingSchema),\n});\n\nconst RuleSchema = Schema.Struct({\n id: RuleId,\n target: TargetSchema,\n question: Schema.NonEmptyString,\n cutoff: Cutoff,\n message: Schema.optionalKey(Schema.NonEmptyString),\n select: Schema.optionalKey(Schema.declare(isSelector)),\n location: Schema.optionalKey(Schema.Struct({ question: Schema.NonEmptyString, cutoff: Cutoff })),\n model: Schema.optionalKey(ModelSpecSchema),\n context: Schema.optionalKey(RuleContextSchema),\n answer: Schema.optionalKey(Schema.Unknown),\n});\n\nexport const STRICT = { onExcessProperty: \"error\" } as const;\n\nconst decodeOptions = Schema.decodeUnknownResult(OptionsSchema, STRICT);\nconst decodeRule = Schema.decodeUnknownResult(RuleSchema, STRICT);\n\nconst taggedError = Schema.TaggedError;\n\nclass OptionsError extends taggedError<OptionsError, { readonly brand: unique symbol }>()(\n \"OptionsError\",\n { message: Schema.String },\n) {}\n\nexport const optionsError = (message: string): Error =>\n OptionsError.make({ message: `${PREFIX}: ${message}` });\n\nexport const modelIdsOf = (spec: ModelSpec): readonly string[] => Arr.dedupe(Arr.ensure(spec));\n\nconst splitModelId = (id: string): Option.Option<readonly [string, string]> => {\n const [provider, ...rest] = Str.split(id, PROVIDER_SEPARATOR);\n const model = pipe(rest, Arr.join(PROVIDER_SEPARATOR));\n return Option.liftPredicate(\n [provider, model] as const,\n ([left, right]) => Str.isNonEmpty(left) && Str.isNonEmpty(right),\n );\n};\n\nexport const resolveModel: {\n (providers: Readonly<Record<string, DecisionProvider>>): (id: string) => ModelRef;\n (id: string, providers: Readonly<Record<string, DecisionProvider>>): ModelRef;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (id: string, providers: Readonly<Record<string, DecisionProvider>>): ModelRef =>\n splitModelId(id).pipe(\n Option.flatMap(([name, model]) =>\n Option.map(Option.fromUndefinedOr(providers[name]), (provider) => ({\n id,\n provider,\n model,\n })),\n ),\n Option.getOrThrowWith(() =>\n optionsError(\n `model \"${id}\" must be \"<provider>/<model>\" with a provider from: ${pipe(Rec.keys(providers), Arr.join(\", \"))}`,\n ),\n ),\n ),\n);\n\nconst duplicateIdOf = (rules: readonly DecisionRule[]): Option.Option<string> =>\n Arr.findFirst(\n Rec.toEntries(Arr.groupBy(rules, ({ id }) => id)),\n ([, same]) => same.length > ONE_RULE,\n ).pipe(Option.map(([id]) => id));\n\nconst answerOf = (rule: DecisionRule): RuleAnswer => {\n if (Predicate.isUndefined(rule.answer)) {\n return BOOLEAN_ANSWER;\n }\n return Result.getOrThrowWith(decodeRuleAnswer(rule.answer), (issue) =>\n optionsError(`rule \"${rule.id}\" has an invalid answer: ${issue}`),\n );\n};\n\nexport type Decode<Value> = (input: unknown) => Result.Result<Value, Schema.SchemaError>;\n\nexport const checked: {\n (input: unknown, what: string): <Value>(decode: Decode<Value>) => Value;\n <Value>(decode: Decode<Value>, input: unknown, what: string): Value;\n} = Fn.dual(\n DATA_FIRST_ARITY_3,\n <Value>(decode: Decode<Value>, input: unknown, what: string): Value =>\n Result.getOrThrowWith(decode(input), (issue) =>\n optionsError(`invalid ${what}: ${issue.message}`),\n ),\n);\n\nconst checkRule = (rule: DecisionRule): DecisionRule => {\n checked(decodeRule, rule, `rule \"${rule.id}\"`);\n if (Predicate.isNotUndefined(rule.location) && rule.target !== \"file\") {\n throw optionsError(\"location is supported only for file rules\");\n }\n answerOf(rule);\n return rule;\n};\n\nexport const checkRules = (rules: readonly DecisionRule[]): readonly DecisionRule[] => {\n if (!Arr.isReadonlyArrayNonEmpty(rules)) {\n throw optionsError(\"rules must list at least one rule\");\n }\n Option.map(duplicateIdOf(rules), (duplicate) => {\n throw optionsError(`rule id \"${duplicate}\" is used more than once`);\n });\n return pipe(\n rules,\n Arr.map((rule) => checkRule(rule)),\n );\n};\n\nconst resolveRule =\n (fallback: ModelSpec, providers: Readonly<Record<string, DecisionProvider>>) =>\n (rule: DecisionRule): ResolvedRule => ({\n ...rule,\n answer: answerOf(rule),\n models: pipe(\n modelIdsOf(rule.model ?? fallback),\n Arr.map((id) => resolveModel(id, providers)),\n ),\n });\n\nexport interface Sources {\n readonly options: DecisionOptions;\n readonly settings?: unknown;\n}\n\nconst settingsFrom = (settings: unknown): DecisionOptions => {\n if (Predicate.isUndefined(settings)) {\n return {};\n }\n return checked(decodeOptions, settings, \"settings\");\n};\n\nexport const resolveOptions: {\n (\n rules: readonly DecisionRule[],\n providers: Readonly<Record<string, DecisionProvider>>,\n ): (sources: Sources) => ResolvedOptions;\n (\n sources: Sources,\n rules: readonly DecisionRule[],\n providers: Readonly<Record<string, DecisionProvider>>,\n ): ResolvedOptions;\n} = Fn.dual(\n DATA_FIRST_ARITY_3,\n (\n { options, settings }: Sources,\n rules: readonly DecisionRule[],\n providers: Readonly<Record<string, DecisionProvider>>,\n ): ResolvedOptions => {\n const fromCode = checked(decodeOptions, options, \"createDecisionPlugin options\");\n const { model, ...merged } = { ...DEFAULTS, ...fromCode, ...settingsFrom(settings) };\n return {\n ci: merged.ci,\n timeoutMs: merged.timeoutMs,\n maxSnippetChars: merged.maxSnippetChars,\n env: merged.env,\n explain: merged.explain,\n rules: pipe(\n checkRules(rules),\n Arr.map((rule) => resolveRule(model, providers)(rule)),\n ),\n };\n },\n);\n","import {\n Cause,\n DateTime,\n Config,\n Console,\n Effect,\n Exit,\n Option,\n Schema,\n String as Str,\n Function as Fn,\n} from \"effect\";\n\nimport { PREFIX } from \"./options.ts\";\nimport type { ResolvedOptions } from \"./types.ts\";\n\nconst DATA_FIRST_ARITY = 2;\n\nconst encodeJson = Schema.encodeUnknownOption(Schema.fromJsonString(Schema.Unknown));\n\nexport const toJson = (value: unknown): string =>\n Option.getOrElse(encodeJson(value), () => String(value));\n\nexport const nowMs = (): number => DateTime.toEpochMillis(DateTime.nowUnsafe());\n\nexport const runOrElse: {\n <Value>(\n fallback: (error: unknown) => Value,\n ): <Failure>(effect: Effect.Effect<Value, Failure>) => Value;\n <Value, Failure>(\n effect: Effect.Effect<Value, Failure>,\n fallback: (error: unknown) => Value,\n ): Value;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n <Value, Failure>(\n effect: Effect.Effect<Value, Failure>,\n fallback: (error: unknown) => Value,\n ): Value =>\n Exit.match(Effect.runSyncExit(effect), {\n onSuccess: (value) => value,\n onFailure: (cause) => fallback(Cause.squash(cause)),\n }),\n);\n\nexport const envOf = (name: string): Option.Option<string> =>\n runOrElse(Config.option(Config.NonEmptyString(name)), () => Option.none()).pipe(\n Option.map((value) => Str.trim(value)),\n Option.filter(Str.isNonEmpty),\n );\n\nexport const envNameOf: {\n (name: string): (env: Readonly<Record<string, string>>) => string;\n (env: Readonly<Record<string, string>>, name: string): string;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (env: Readonly<Record<string, string>>, name: string): string => env[name] ?? name,\n);\n\nexport const failsInCi = (options: ResolvedOptions): boolean =>\n options.ci === \"fail\" && Option.isSome(envOf(\"CI\"));\n\nconst warned = new Set<string>();\n\nexport const warnOnce: {\n (message: string): (reason: string) => void;\n (reason: string, message: string): void;\n} = Fn.dual(DATA_FIRST_ARITY, (reason: string, message: string): void => {\n if (warned.has(reason)) {\n return;\n }\n warned.add(reason);\n Effect.runFork(Console.warn(`${PREFIX}: ${message}`));\n});\n\nexport const messageOf = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n};\n\nexport const captured: {\n (name: string): (match: Option.Option<RegExpMatchArray>) => Option.Option<string>;\n (match: Option.Option<RegExpMatchArray>, name: string): Option.Option<string>;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (match: Option.Option<RegExpMatchArray>, name: string): Option.Option<string> =>\n match.pipe(\n Option.flatMap((found) => Option.fromNullishOr(found.groups)),\n Option.flatMap((groups) => Option.fromNullishOr(groups[name])),\n ),\n);\n"],"mappings":";;AAEA,MAAM,OAAO;AACb,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB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yBAAS,IAAI,IAAY;AAE/B,MAAa,WAGTA,SAAG,KAAK,mBAAmB,QAAgB,YAA0B;CACvE,IAAI,OAAO,IAAI,MAAM,GACnB;CAEF,OAAO,IAAI,MAAM;CACjB,OAAO,QAAQ,QAAQ,KAAK,GAAG,OAAO,IAAI,SAAS,CAAC;AACtD,CAAC;AAED,MAAa,aAAa,UAA2B;CACnD,IAAI,iBAAiB,OACnB,OAAO,MAAM;CAEf,OAAO,OAAO,KAAK;AACrB;AAEA,MAAa,WAGTA,SAAG,KACL,mBACC,OAAwC,SACvC,MAAM,KACJ,OAAO,SAAS,UAAU,OAAO,cAAc,MAAM,MAAM,CAAC,GAC5D,OAAO,SAAS,WAAW,OAAO,cAAc,OAAO,KAAK,CAAC,CAC/D,CACJ"}
|
package/dist/select-bvQylrUt.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Array, Function, Match, Option, Predicate, Record, pipe } from "effect";
|
|
2
|
-
// src/presets/select.ts
|
|
3
|
-
const DATA_FIRST_ARITY = 2;
|
|
4
|
-
const dualSelect = (select) => Function.dual(DATA_FIRST_ARITY, select);
|
|
5
|
-
const childrenOf = (node) => pipe(Record.toEntries(node), Array.filter(([key]) => key !== "parent"), Array.flatMap(([, value]) => Array.ensure(value)), Array.filter((value) => Predicate.hasProperty(value, "type")));
|
|
6
|
-
const descendantsOf = (node) => [node, ...pipe(childrenOf(node), Array.flatMap((child) => descendantsOf(child)))];
|
|
7
|
-
const containing = (test) => (node) => pipe(descendantsOf(node), Array.some((found) => test(found)));
|
|
8
|
-
const ofType = (...types) => (node) => types.includes(node.type);
|
|
9
|
-
const identifierOf = (node) => Match.value(node).pipe(Match.when({ type: "Identifier" }, (identifier) => Option.some(identifier.name)), Match.orElse(() => Option.none()));
|
|
10
|
-
export { ofType as i, dualSelect as n, identifierOf as r, containing as t };
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=select-bvQylrUt.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"select-bvQylrUt.mjs","names":["Fn","Rec","Arr"],"sources":["../src/presets/select.ts"],"sourcesContent":["import type { DecisionRule, SelectMatch, SelectedNode } from \"@r_masseater/oxlint-plugin-decision\";\nimport {\n Match,\n Option,\n Predicate,\n Array as Arr,\n Record as Rec,\n pipe,\n Function as Fn,\n} from \"effect\";\n\nconst DATA_FIRST_ARITY = 2;\n\nexport type Select = NonNullable<DecisionRule[\"select\"]>;\n\nexport interface DualSelect {\n (match: SelectMatch): (node: SelectedNode) => boolean;\n (node: SelectedNode, match: SelectMatch): boolean;\n}\n\nexport const dualSelect = (select: Select): DualSelect => Fn.dual(DATA_FIRST_ARITY, select);\n\nexport type NodeTest = Predicate.Predicate<SelectedNode>;\n\nconst childrenOf = (node: SelectedNode): readonly SelectedNode[] =>\n pipe(\n Rec.toEntries<string, unknown>(node),\n Arr.filter(([key]) => key !== \"parent\"),\n Arr.flatMap(([, value]) => Arr.ensure(value)),\n Arr.filter((value): value is SelectedNode => Predicate.hasProperty(value, \"type\")),\n );\n\nconst descendantsOf = (node: SelectedNode): readonly SelectedNode[] => [\n node,\n ...pipe(\n childrenOf(node),\n Arr.flatMap((child) => descendantsOf(child)),\n ),\n];\n\nexport const containing =\n (test: NodeTest): NodeTest =>\n (node) =>\n pipe(\n descendantsOf(node),\n Arr.some((found) => test(found)),\n );\n\nexport const ofType =\n (...types: readonly string[]): NodeTest =>\n (node) =>\n types.includes(node.type);\n\nexport const identifierOf = (node: SelectedNode): Option.Option<string> =>\n Match.value(node).pipe(\n Match.when({ type: \"Identifier\" }, (identifier) => Option.some(identifier.name)),\n Match.orElse(() => Option.none()),\n );\n"],"mappings":";;AAWA,MAAM,mBAAmB;AASzB,MAAa,cAAc,WAA+BA,SAAG,KAAK,kBAAkB,MAAM;AAI1F,MAAM,cAAc,SAClB,KACEC,OAAI,UAA2B,IAAI,GACnCC,MAAI,QAAQ,CAAC,SAAS,QAAQ,QAAQ,GACtCA,MAAI,SAAS,GAAG,WAAWA,MAAI,OAAO,KAAK,CAAC,GAC5CA,MAAI,QAAQ,UAAiC,UAAU,YAAY,OAAO,MAAM,CAAC,CACnF;AAEF,MAAM,iBAAiB,SAAgD,CACrE,MACA,GAAG,KACD,WAAW,IAAI,GACfA,MAAI,SAAS,UAAU,cAAc,KAAK,CAAC,CAC7C,CACF;AAEA,MAAa,cACV,UACA,SACC,KACE,cAAc,IAAI,GAClBA,MAAI,MAAM,UAAU,KAAK,KAAK,CAAC,CACjC;AAEJ,MAAa,UACV,GAAG,WACH,SACC,MAAM,SAAS,KAAK,IAAI;AAE5B,MAAa,gBAAgB,SAC3B,MAAM,MAAM,IAAI,CAAC,CAAC,KAChB,MAAM,KAAK,EAAE,MAAM,aAAa,IAAI,eAAe,OAAO,KAAK,WAAW,IAAI,CAAC,GAC/E,MAAM,aAAa,OAAO,KAAK,CAAC,CAClC"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { a as messageOf, y as AnswerSchema } from "./runtime-CICpEidL.mjs";
|
|
2
|
-
import { c as parseVerdicts } from "./wire-CRD1mSAo.mjs";
|
|
3
|
-
import { Array, Clock, Effect, FileSystem, Function, Layer, Option, Path, Schema, pipe } from "effect";
|
|
4
|
-
import { runAsWorker } from "synckit";
|
|
5
|
-
import { FetchHttpClient } from "effect/http";
|
|
6
|
-
import { Digest } from "effect/crypto";
|
|
7
|
-
import { layerDigest } from "@effect/platform-node-shared/NodeCrypto";
|
|
8
|
-
import { layer } from "@effect/platform-node-shared/NodeFileSystem";
|
|
9
|
-
import { layer as layer$1 } from "@effect/platform-node-shared/NodePath";
|
|
10
|
-
import { OtlpSerialization, OtlpTracer } from "effect/observability";
|
|
11
|
-
// src/cache.ts
|
|
12
|
-
const DATA_FIRST_ARITY = 2;
|
|
13
|
-
const CACHE_VERSION = 7;
|
|
14
|
-
/** @internal */
|
|
15
|
-
const CACHE_DIR = [
|
|
16
|
-
"node_modules",
|
|
17
|
-
".cache",
|
|
18
|
-
"oxlint-plugin-decision"
|
|
19
|
-
];
|
|
20
|
-
const encodeJson = (value) => Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(value).pipe(Effect.orDie);
|
|
21
|
-
/** @internal */
|
|
22
|
-
const cacheFile = Effect.fn("cacheFile")(function* cacheFile(endpoint, request) {
|
|
23
|
-
const digest = yield* Digest.Digest;
|
|
24
|
-
const path = yield* Path.Path;
|
|
25
|
-
const json = yield* encodeJson({
|
|
26
|
-
version: CACHE_VERSION,
|
|
27
|
-
endpoint,
|
|
28
|
-
request
|
|
29
|
-
});
|
|
30
|
-
const payload = new TextEncoder().encode(json);
|
|
31
|
-
const hash = yield* digest.digestHex(Digest.sha256, payload);
|
|
32
|
-
return path.resolve(...CACHE_DIR, `${hash}.json`);
|
|
33
|
-
});
|
|
34
|
-
const CachedResponse = Schema.Struct({
|
|
35
|
-
model: Schema.NonEmptyString,
|
|
36
|
-
answers: Schema.Record(Schema.String, AnswerSchema)
|
|
37
|
-
});
|
|
38
|
-
const decodeCached = Schema.decodeOption(Schema.fromJsonString(CachedResponse));
|
|
39
|
-
/** @internal */
|
|
40
|
-
const isComplete = Function.dual(DATA_FIRST_ARITY, (response, request) => Option.liftThrowable(() => parseVerdicts(response, request).complete)().pipe(Option.getOrElse(() => false)));
|
|
41
|
-
/** @internal */
|
|
42
|
-
const readCache = Effect.fn("readCache")(function* readCache(file, request) {
|
|
43
|
-
return (yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(Effect.option)).pipe(Option.flatMap((raw) => decodeCached(raw)), Option.filter((response) => isComplete(response, request)));
|
|
44
|
-
});
|
|
45
|
-
/** @internal */
|
|
46
|
-
const writeCache = Effect.fn("writeCache")(function* writeCache(file, response) {
|
|
47
|
-
const fs = yield* FileSystem.FileSystem;
|
|
48
|
-
const path = yield* Path.Path;
|
|
49
|
-
const now = yield* Clock.currentTimeMillis;
|
|
50
|
-
const temp = `${file}.tmp-${String(now)}`;
|
|
51
|
-
const json = yield* encodeJson(response);
|
|
52
|
-
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
|
|
53
|
-
yield* fs.writeFileString(temp, json);
|
|
54
|
-
yield* fs.rename(temp, file);
|
|
55
|
-
});
|
|
56
|
-
// src/services.ts
|
|
57
|
-
const tracing = OtlpTracer.layerFromConfig({ resource: { serviceName: "oxlint-plugin-decision" } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
|
|
58
|
-
/** @internal */
|
|
59
|
-
const workerServices = [
|
|
60
|
-
layer,
|
|
61
|
-
layer$1,
|
|
62
|
-
layerDigest,
|
|
63
|
-
FetchHttpClient.layer,
|
|
64
|
-
tracing
|
|
65
|
-
];
|
|
66
|
-
// src/serve-decisions.ts
|
|
67
|
-
const ask = Effect.fn("ask")(function* ask(transport, endpoint, { request, timeoutMs, env }) {
|
|
68
|
-
const responses = yield* Effect.forEach(transport.wires(request), (wire) => transport.send(endpoint, wire, { env }), { concurrency: "unbounded" }).pipe(Effect.timeoutOrElse({
|
|
69
|
-
duration: timeoutMs,
|
|
70
|
-
orElse: () => Effect.fail("timeout")
|
|
71
|
-
}));
|
|
72
|
-
return transport.combine(request, responses);
|
|
73
|
-
});
|
|
74
|
-
const askAndStore = Effect.fn("askAndStore")(function* askAndStore(transport, { endpoint, file }, input) {
|
|
75
|
-
const response = yield* ask(transport, endpoint, input);
|
|
76
|
-
if (isComplete(response, input.request)) yield* writeCache(file, response).pipe(Effect.ignore);
|
|
77
|
-
return response;
|
|
78
|
-
});
|
|
79
|
-
const decide = Effect.fn("decide")(function* decide(transport, input) {
|
|
80
|
-
yield* Effect.annotateCurrentSpan({ model: input.request.model });
|
|
81
|
-
const endpoint = yield* transport.endpoint(input.env);
|
|
82
|
-
const file = yield* cacheFile(endpoint, input.request);
|
|
83
|
-
const cached = yield* readCache(file, input.request);
|
|
84
|
-
yield* Effect.annotateCurrentSpan({ cached: Option.isSome(cached) });
|
|
85
|
-
if (Option.isSome(cached)) return {
|
|
86
|
-
response: cached.value,
|
|
87
|
-
cached: true
|
|
88
|
-
};
|
|
89
|
-
return {
|
|
90
|
-
response: yield* askAndStore(transport, {
|
|
91
|
-
endpoint,
|
|
92
|
-
file
|
|
93
|
-
}, input),
|
|
94
|
-
cached: false
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
const reasonOf = (error) => {
|
|
98
|
-
if (typeof error === "string") return error;
|
|
99
|
-
return messageOf(error);
|
|
100
|
-
};
|
|
101
|
-
const decideOne = (transport, input) => decide(transport, input).pipe(Effect.match({
|
|
102
|
-
onSuccess: ({ response, cached }) => ({
|
|
103
|
-
ok: true,
|
|
104
|
-
response,
|
|
105
|
-
cached
|
|
106
|
-
}),
|
|
107
|
-
onFailure: (error) => ({
|
|
108
|
-
ok: false,
|
|
109
|
-
reason: reasonOf(error)
|
|
110
|
-
})
|
|
111
|
-
}));
|
|
112
|
-
const decideEach = (transport, inputs) => Effect.all(pipe(inputs, Array.map((input) => decideOne(transport, input))), { concurrency: "unbounded" }).pipe(Effect.provide(workerServices));
|
|
113
|
-
/** @internal */
|
|
114
|
-
const serveDecisions = (transport) => {
|
|
115
|
-
runAsWorker((inputs) => Effect.runPromise(decideEach(transport, inputs)));
|
|
116
|
-
};
|
|
117
|
-
export { serveDecisions as t };
|
|
118
|
-
|
|
119
|
-
//# sourceMappingURL=serve-decisions-BM0bUWWe.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serve-decisions-BM0bUWWe.mjs","names":["Fn","fileSystem","path","Arr"],"sources":["../src/cache.ts","../src/services.ts","../src/serve-decisions.ts"],"sourcesContent":["import { Clock, Effect, FileSystem, Option, Path, Schema, Function as Fn } from \"effect\";\nimport { Digest } from \"effect/crypto\";\n\nimport { AnswerSchema } from \"./answer.ts\";\nimport { parseVerdicts } from \"./request.ts\";\nimport type { DecisionRequest, DecisionResponse } from \"./types.ts\";\n\nconst DATA_FIRST_ARITY = 2;\n\nconst CACHE_VERSION = 7;\n/** @internal */\nexport const CACHE_DIR = [\"node_modules\", \".cache\", \"oxlint-plugin-decision\"] as const;\n\nconst encodeJson = (value: unknown): Effect.Effect<string> =>\n Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(value).pipe(Effect.orDie);\n\n/** @internal */\nexport const cacheFile = Effect.fn(\"cacheFile\")(function* cacheFile(\n endpoint: string,\n request: DecisionRequest,\n) {\n const digest = yield* Digest.Digest;\n const path = yield* Path.Path;\n const json = yield* encodeJson({ version: CACHE_VERSION, endpoint, request });\n const payload = new TextEncoder().encode(json);\n const hash = yield* digest.digestHex(Digest.sha256, payload);\n return path.resolve(...CACHE_DIR, `${hash}.json`);\n});\n\nconst CachedResponse = Schema.Struct({\n model: Schema.NonEmptyString,\n answers: Schema.Record(Schema.String, AnswerSchema),\n});\n\nconst decodeCached = Schema.decodeOption(Schema.fromJsonString(CachedResponse));\n\n/** @internal */\nexport const isComplete: {\n (request: DecisionRequest): (response: DecisionResponse) => boolean;\n (response: DecisionResponse, request: DecisionRequest): boolean;\n} = Fn.dual(DATA_FIRST_ARITY, (response: DecisionResponse, request: DecisionRequest): boolean =>\n Option.liftThrowable(() => parseVerdicts(response, request).complete)().pipe(\n Option.getOrElse(() => false),\n ),\n);\n\n/** @internal */\nexport const readCache = Effect.fn(\"readCache\")(function* readCache(\n file: string,\n request: DecisionRequest,\n) {\n const fs = yield* FileSystem.FileSystem;\n const text = yield* fs.readFileString(file).pipe(Effect.option);\n return text.pipe(\n Option.flatMap((raw): Option.Option<DecisionResponse> => decodeCached(raw)),\n Option.filter((response) => isComplete(response, request)),\n );\n});\n\n/** @internal */\nexport const writeCache = Effect.fn(\"writeCache\")(function* writeCache(\n file: string,\n response: DecisionResponse,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const now = yield* Clock.currentTimeMillis;\n const temp = `${file}.tmp-${String(now)}`;\n const json = yield* encodeJson(response);\n yield* fs.makeDirectory(path.dirname(file), { recursive: true });\n yield* fs.writeFileString(temp, json);\n yield* fs.rename(temp, file);\n});\n\n/** @internal */\nexport type CacheServices = Digest.Digest | FileSystem.FileSystem | Path.Path;\n","import { layerDigest } from \"@effect/platform-node-shared/NodeCrypto\";\nimport { layer as fileSystem } from \"@effect/platform-node-shared/NodeFileSystem\";\nimport { layer as path } from \"@effect/platform-node-shared/NodePath\";\nimport { Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { OtlpSerialization, OtlpTracer } from \"effect/observability\";\n\nconst tracing = OtlpTracer.layerFromConfig({\n resource: { serviceName: \"oxlint-plugin-decision\" },\n}).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));\n\n/** @internal */\nexport const workerServices: [\n typeof fileSystem,\n typeof path,\n typeof layerDigest,\n typeof FetchHttpClient.layer,\n typeof tracing,\n] = [fileSystem, path, layerDigest, FetchHttpClient.layer, tracing];\n","import { Array as Arr, Effect, Option, pipe } from \"effect\";\nimport type { Config } from \"effect\";\nimport type { HttpClient } from \"effect/http\";\nimport { runAsWorker } from \"synckit\";\n\nimport { cacheFile, isComplete, readCache, writeCache } from \"./cache.ts\";\nimport type { CacheServices } from \"./cache.ts\";\nimport type { AppServices } from \"./openrouter-app.ts\";\nimport { messageOf } from \"./runtime.ts\";\nimport { workerServices } from \"./services.ts\";\nimport type { DecideInput, DecideResult, DecisionRequest, DecisionResponse } from \"./types.ts\";\nimport type { WireRequest } from \"./wire.ts\";\n\n/** @internal */\nexport type Services = AppServices | CacheServices | HttpClient.HttpClient;\n\ntype Inputs = Arr.NonEmptyReadonlyArray<DecideInput>;\n\n/** @internal */\nexport interface Transport {\n readonly endpoint: (env: DecideInput[\"env\"]) => Config.Config<string>;\n readonly wires: (request: DecisionRequest) => Arr.NonEmptyReadonlyArray<WireRequest>;\n readonly combine: (\n request: DecisionRequest,\n responses: Arr.NonEmptyReadonlyArray<DecisionResponse>,\n ) => DecisionResponse;\n readonly send: (\n endpoint: string,\n wire: WireRequest,\n input: Pick<DecideInput, \"env\">,\n ) => Effect.Effect<DecisionResponse, Config.ConfigError | string, Services>;\n}\n\nconst ask = Effect.fn(\"ask\")(function* ask(\n transport: Transport,\n endpoint: string,\n { request, timeoutMs, env }: DecideInput,\n) {\n const responses = yield* Effect.forEach(\n transport.wires(request),\n (wire) => transport.send(endpoint, wire, { env }),\n { concurrency: \"unbounded\" },\n ).pipe(\n Effect.timeoutOrElse({\n duration: timeoutMs,\n orElse: () => Effect.fail(\"timeout\"),\n }),\n );\n return transport.combine(request, responses);\n});\n\nconst askAndStore = Effect.fn(\"askAndStore\")(function* askAndStore(\n transport: Transport,\n { endpoint, file }: Readonly<{ endpoint: string; file: string }>,\n input: DecideInput,\n) {\n const response = yield* ask(transport, endpoint, input);\n if (isComplete(response, input.request)) {\n yield* writeCache(file, response).pipe(Effect.ignore);\n }\n return response;\n});\n\nconst decide = Effect.fn(\"decide\")(function* decide(transport: Transport, input: DecideInput) {\n yield* Effect.annotateCurrentSpan({ model: input.request.model });\n const endpoint = yield* transport.endpoint(input.env);\n const file = yield* cacheFile(endpoint, input.request);\n const cached = yield* readCache(file, input.request);\n yield* Effect.annotateCurrentSpan({ cached: Option.isSome(cached) });\n if (Option.isSome(cached)) {\n return { response: cached.value, cached: true };\n }\n return { response: yield* askAndStore(transport, { endpoint, file }, input), cached: false };\n});\n\nconst reasonOf = (error: unknown): string => {\n if (typeof error === \"string\") {\n return error;\n }\n return messageOf(error);\n};\n\nconst decideOne = (\n transport: Transport,\n input: DecideInput,\n): Effect.Effect<DecideResult, never, Services> =>\n decide(transport, input).pipe(\n Effect.match({\n onSuccess: ({ response, cached }): DecideResult => ({ ok: true, response, cached }),\n onFailure: (error): DecideResult => ({ ok: false, reason: reasonOf(error) }),\n }),\n );\n\nconst decideEach = (\n transport: Transport,\n inputs: Inputs,\n): Effect.Effect<Arr.NonEmptyReadonlyArray<DecideResult>> =>\n Effect.all(\n pipe(\n inputs,\n Arr.map((input) => decideOne(transport, input)),\n ),\n { concurrency: \"unbounded\" },\n ).pipe(Effect.provide(workerServices));\n\n/** @internal */\nexport const serveDecisions = (transport: Transport): void => {\n runAsWorker((inputs: Inputs): Promise<Arr.NonEmptyReadonlyArray<DecideResult>> =>\n Effect.runPromise(decideEach(transport, inputs)),\n );\n};\n"],"mappings":";;;;;;;;;;;AAOA,MAAM,mBAAmB;AAEzB,MAAM,gBAAgB;;AAEtB,MAAa,YAAY;CAAC;CAAgB;CAAU;AAAwB;AAE5E,MAAM,cAAc,UAClB,OAAO,oBAAoB,OAAO,eAAe,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;;AAG5F,MAAa,YAAY,OAAO,GAAG,WAAW,CAAC,CAAC,UAAU,UACxD,UACA,SACA;CACA,MAAM,SAAS,OAAO,OAAO;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,OAAO,OAAO,WAAW;EAAE,SAAS;EAAe;EAAU;CAAQ,CAAC;CAC5E,MAAM,UAAU,IAAI,YAAY,CAAC,CAAC,OAAO,IAAI;CAC7C,MAAM,OAAO,OAAO,OAAO,UAAU,OAAO,QAAQ,OAAO;CAC3D,OAAO,KAAK,QAAQ,GAAG,WAAW,GAAG,KAAK,MAAM;AAClD,CAAC;AAED,MAAM,iBAAiB,OAAO,OAAO;CACnC,OAAO,OAAO;CACd,SAAS,OAAO,OAAO,OAAO,QAAQ,YAAY;AACpD,CAAC;AAED,MAAM,eAAe,OAAO,aAAa,OAAO,eAAe,cAAc,CAAC;;AAG9E,MAAa,aAGTA,SAAG,KAAK,mBAAmB,UAA4B,YACzD,OAAO,oBAAoB,cAAc,UAAU,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KACtE,OAAO,gBAAgB,KAAK,CAC9B,CACF;;AAGA,MAAa,YAAY,OAAO,GAAG,WAAW,CAAC,CAAC,UAAU,UACxD,MACA,SACA;CAGA,QAAO,QADa,OADF,WAAW,WAAA,CACN,eAAe,IAAI,CAAC,CAAC,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