@r_masseater/oxlint-plugin-decision 0.5.1 → 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 +23 -395
- package/dist/app-Bso1uwY5.mjs +662 -0
- package/dist/app-Bso1uwY5.mjs.map +1 -0
- package/dist/cloudflare-worker.mjs +6 -179
- 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/define-presets-clyqLZxo.mjs +550 -0
- package/dist/define-presets-clyqLZxo.mjs.map +1 -0
- package/dist/index-BOrpK3Iv.d.mts +89 -0
- package/dist/index-Cgg-w0hb.d.mts +3370 -0
- package/dist/index-D7VrRpTx.d.mts +6 -0
- package/dist/index.d.mts +3 -3372
- package/dist/index.mjs +1 -786
- package/dist/openrouter-app.d.mts +12 -4
- package/dist/openrouter-app.mjs +1 -87
- package/dist/openrouter-worker.mjs +5 -35
- 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 +6 -0
- package/dist/presets/ai-slop.mjs +10 -0
- package/dist/presets/ai-slop.mjs.map +1 -0
- package/dist/presets/index.d.mts +3 -0
- package/dist/presets/index.mjs +3 -0
- package/dist/presets/recommended.d.mts +5 -0
- package/dist/presets/recommended.mjs +7 -0
- package/dist/presets/recommended.mjs.map +1 -0
- package/dist/presets/review-only.d.mts +5 -0
- package/dist/presets/review-only.mjs +7 -0
- package/dist/presets/review-only.mjs.map +1 -0
- package/dist/presets/strict.d.mts +5 -0
- package/dist/presets/strict.mjs +7 -0
- package/dist/presets/strict.mjs.map +1 -0
- package/dist/serve-decisions-CjlhvYm7.mjs +290 -0
- package/dist/serve-decisions-CjlhvYm7.mjs.map +1 -0
- package/package.json +25 -3
- package/skills/write-decision-rules/SKILL.md +18 -17
- package/skills/write-decision-rules/references/tuning.md +1 -1
- package/dist/index.mjs.map +0 -1
- package/dist/openrouter-app.mjs.map +0 -1
- package/dist/runtime-CICpEidL.mjs +0 -271
- package/dist/runtime-CICpEidL.mjs.map +0 -1
- package/dist/serve-decisions-cQpGj_Fq.mjs +0 -112
- package/dist/serve-decisions-cQpGj_Fq.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\nconst Probability = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 1 }));\n\nconst CONFIDENT = 0.8;\n\nconst Cutoff = Schema.Finite.check(\n Schema.isBetween(\n { minimum: CONFIDENT, maximum: 1 },\n { message: `cutoff must be between ${CONFIDENT} and 1` },\n ),\n);\n\nconst TargetSchema = Schema.Literals([\"function\", \"call\", \"jsx\", \"file\"]);\n\nconst CiBehaviorSchema = Schema.Literals([\"skip\", \"fail\"]);\n\nconst ExplainSettingSchema = Schema.Union([Schema.Boolean, Schema.Literals([\"text\", \"json\"])]);\n\nconst EnclosingKindSchema = Schema.Literals([\"function\", \"class\", \"block\"]);\n\nconst 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\nconst 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\nconst RuleAnswerSchema = Schema.Union([BooleanAnswer, ClassifyAnswer, SeverityAnswer]);\n\nexport {\n CONFIDENT,\n CiBehaviorSchema,\n Cutoff,\n EnclosingKindSchema,\n ExplainSettingSchema,\n Probability,\n RuleAnswerSchema,\n RuleContextSchema,\n SeveritySchema,\n TargetSchema,\n};\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\nconst SEVERITY_ORDER: readonly string[] = Rec.keys(SEVERITY_CRITERIA);\n\nconst BOOLEAN_ANSWER: RuleAnswer = { kind: \"boolean\" };\n\nconst decodeAnswer = Schema.decodeUnknownResult(RuleAnswerSchema);\n\nconst 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\nconst 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\nconst noulOf = (answer: Answer | undefined): Option.Option<NoulAnswer> =>\n Option.fromUndefinedOr(answer).pipe(Option.filter(isNoul), Option.flatMap(decodeNoul));\n\nconst choiceOf = (answer: Answer | undefined): Option.Option<ChoiceAnswer> =>\n Option.fromUndefinedOr(answer).pipe(Option.filter(isChoice), Option.flatMap(decodeChoice));\n\nconst probabilityOfChoice = ({ choice, probabilities }: ChoiceAnswer): Option.Option<number> =>\n Option.fromUndefinedOr(probabilities).pipe(\n Option.flatMap((byLabel) => Option.fromUndefinedOr(byLabel[choice])),\n );\n\nconst 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\nconst 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\nconst 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\nexport {\n AnswerSchema,\n BOOLEAN_ANSWER,\n SEVERITY_ORDER,\n choiceOf,\n decodeRuleAnswer,\n isReported,\n noulOf,\n probabilityOfChoice,\n questionFor,\n verdictOf,\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\nconst 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\nconst 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\nconst 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\nconst optionsError = (message: string): Error =>\n OptionsError.make({ message: `${PREFIX}: ${message}` });\n\nconst 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\nconst 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\ntype Decode<Value> = (input: unknown) => Result.Result<Value, Schema.SchemaError>;\n\nconst 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\nconst 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\ninterface 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\nconst 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\nexport type { Decode, Sources };\nexport {\n checkRules,\n optionsError,\n PREFIX,\n ModelSpecSchema,\n STRICT,\n checked,\n modelIdsOf,\n resolveModel,\n resolveOptions,\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\nconst toJson = (value: unknown): string => Option.getOrElse(encodeJson(value), () => String(value));\n\nconst nowMs = (): number => DateTime.toEpochMillis(DateTime.nowUnsafe());\n\nconst 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\nconst 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\nconst 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\nconst failsInCi = (options: ResolvedOptions): boolean =>\n options.ci === \"fail\" && Option.isSome(envOf(\"CI\"));\n\nconst warned = new Set<string>();\n\nconst 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\nconst messageOf = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n};\n\nconst 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\nexport { captured, envNameOf, envOf, failsInCi, messageOf, nowMs, runOrElse, toJson, warnOnce };\n"],"mappings":";;AAEA,MAAM,OAAO;AACb,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB,OAAO,IAAI,MAAM,OAAO,uBAAuB,IAAI,CAAC;AAE3E,MAAM,cAAc,OAAO,OAAO,MAAM,OAAO,UAAU;CAAE,SAAS;CAAG,SAAS;AAAE,CAAC,CAAC;AAEpF,MAAM,YAAY;AAElB,MAAM,SAAS,OAAO,OAAO,MAC3B,OAAO,UACL;CAAE,SAAS;CAAW,SAAS;AAAE,GACjC,EAAE,SAAS,0BAA0B,UAAU,QAAQ,CACzD,CACF;AAEA,MAAM,eAAe,OAAO,SAAS;CAAC;CAAY;CAAQ;CAAO;AAAM,CAAC;AAExE,MAAM,mBAAmB,OAAO,SAAS,CAAC,QAAQ,MAAM,CAAC;AAEzD,MAAM,uBAAuB,OAAO,MAAM,CAAC,OAAO,SAAS,OAAO,SAAS,CAAC,QAAQ,MAAM,CAAC,CAAC,CAAC;AAE7F,MAAM,sBAAsB,OAAO,SAAS;CAAC;CAAY;CAAS;AAAO,CAAC;AAE1E,MAAM,oBAAoB,OAAO,MAAM;CACrC,OAAO,OAAO,EAAE,OAAO,OAAO,SAAS;EAAC;EAAQ;EAAQ;CAAS,CAAC,EAAE,CAAC;CACrE,OAAO,OAAO;EACZ,OAAO,OAAO,QAAQ,OAAO;EAC7B,QAAQ,OAAO,YAAY,cAAc;EACzC,OAAO,OAAO,YAAY,cAAc;CAC1C,CAAC;CACD,OAAO,OAAO;EAAE,OAAO,OAAO,QAAQ,WAAW;EAAG,MAAM;CAAoB,CAAC;AACjF,CAAC;AAED,MAAM,iBAAiB,OAAO,SAAS;CAAC;CAAQ;CAAQ;AAAO,CAAC;AAEhE,MAAM,QAAQ,OAAO;AAErB,MAAM,gBA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SAAI,KAAK,KAAK,CAAC,GACrC,OAAO,OAAOA,SAAI,UAAU,CAC9B;AAEF,MAAM,YAGFD,SAAG,KACL,mBACC,KAAuC,SAAyB,IAAI,SAAS,IAChF;AAEA,MAAM,aAAa,YACjB,QAAQ,OAAO,UAAU,OAAO,OAAO,MAAM,IAAI,CAAC;AAEpD,MAAM,yBAAS,IAAI,IAAY;AAE/B,MAAM,WAGFA,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,MAAM,aAAa,UAA2B;CAC5C,IAAI,iBAAiB,OACnB,OAAO,MAAM;CAEf,OAAO,OAAO,KAAK;AACrB;AAEA,MAAM,WAGFA,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"}
|
|
@@ -1,112 +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
|
-
const CACHE_DIR = [
|
|
15
|
-
"node_modules",
|
|
16
|
-
".cache",
|
|
17
|
-
"oxlint-plugin-decision"
|
|
18
|
-
];
|
|
19
|
-
const encodeJson = (value) => Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(value).pipe(Effect.orDie);
|
|
20
|
-
const cacheFile = Effect.fn("cacheFile")(function* cacheFile(endpoint, request) {
|
|
21
|
-
const digest = yield* Digest.Digest;
|
|
22
|
-
const path = yield* Path.Path;
|
|
23
|
-
const json = yield* encodeJson({
|
|
24
|
-
version: CACHE_VERSION,
|
|
25
|
-
endpoint,
|
|
26
|
-
request
|
|
27
|
-
});
|
|
28
|
-
const payload = new TextEncoder().encode(json);
|
|
29
|
-
const hash = yield* digest.digestHex(Digest.sha256, payload);
|
|
30
|
-
return path.resolve(...CACHE_DIR, `${hash}.json`);
|
|
31
|
-
});
|
|
32
|
-
const CachedResponse = Schema.Struct({
|
|
33
|
-
model: Schema.NonEmptyString,
|
|
34
|
-
answers: Schema.Record(Schema.String, AnswerSchema)
|
|
35
|
-
});
|
|
36
|
-
const decodeCached = Schema.decodeOption(Schema.fromJsonString(CachedResponse));
|
|
37
|
-
const isComplete = Function.dual(DATA_FIRST_ARITY, (response, request) => Option.liftThrowable(() => parseVerdicts(response, request).complete)().pipe(Option.getOrElse(() => false)));
|
|
38
|
-
const readCache = Effect.fn("readCache")(function* readCache(file, request) {
|
|
39
|
-
return (yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(Effect.option)).pipe(Option.flatMap((raw) => decodeCached(raw)), Option.filter((response) => isComplete(response, request)));
|
|
40
|
-
});
|
|
41
|
-
const writeCache = Effect.fn("writeCache")(function* writeCache(file, response) {
|
|
42
|
-
const fs = yield* FileSystem.FileSystem;
|
|
43
|
-
const path = yield* Path.Path;
|
|
44
|
-
const now = yield* Clock.currentTimeMillis;
|
|
45
|
-
const temp = `${file}.tmp-${String(now)}`;
|
|
46
|
-
const json = yield* encodeJson(response);
|
|
47
|
-
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
|
|
48
|
-
yield* fs.writeFileString(temp, json);
|
|
49
|
-
yield* fs.rename(temp, file);
|
|
50
|
-
});
|
|
51
|
-
// src/services.ts
|
|
52
|
-
const tracing = OtlpTracer.layerFromConfig({ resource: { serviceName: "oxlint-plugin-decision" } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
|
|
53
|
-
const workerServices = [
|
|
54
|
-
layer,
|
|
55
|
-
layer$1,
|
|
56
|
-
layerDigest,
|
|
57
|
-
FetchHttpClient.layer,
|
|
58
|
-
tracing
|
|
59
|
-
];
|
|
60
|
-
// src/serve-decisions.ts
|
|
61
|
-
const ask = Effect.fn("ask")(function* ask(transport, endpoint, { request, timeoutMs, env }) {
|
|
62
|
-
const responses = yield* Effect.forEach(transport.wires(request), (wire) => transport.send(endpoint, wire, { env }), { concurrency: "unbounded" }).pipe(Effect.timeoutOrElse({
|
|
63
|
-
duration: timeoutMs,
|
|
64
|
-
orElse: () => Effect.fail("timeout")
|
|
65
|
-
}));
|
|
66
|
-
return transport.combine(request, responses);
|
|
67
|
-
});
|
|
68
|
-
const askAndStore = Effect.fn("askAndStore")(function* askAndStore(transport, { endpoint, file }, input) {
|
|
69
|
-
const response = yield* ask(transport, endpoint, input);
|
|
70
|
-
if (isComplete(response, input.request)) yield* writeCache(file, response).pipe(Effect.ignore);
|
|
71
|
-
return response;
|
|
72
|
-
});
|
|
73
|
-
const decide = Effect.fn("decide")(function* decide(transport, input) {
|
|
74
|
-
yield* Effect.annotateCurrentSpan({ model: input.request.model });
|
|
75
|
-
const endpoint = yield* transport.endpoint(input.env);
|
|
76
|
-
const file = yield* cacheFile(endpoint, input.request);
|
|
77
|
-
const cached = yield* readCache(file, input.request);
|
|
78
|
-
yield* Effect.annotateCurrentSpan({ cached: Option.isSome(cached) });
|
|
79
|
-
if (Option.isSome(cached)) return {
|
|
80
|
-
response: cached.value,
|
|
81
|
-
cached: true
|
|
82
|
-
};
|
|
83
|
-
return {
|
|
84
|
-
response: yield* askAndStore(transport, {
|
|
85
|
-
endpoint,
|
|
86
|
-
file
|
|
87
|
-
}, input),
|
|
88
|
-
cached: false
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
const reasonOf = (error) => {
|
|
92
|
-
if (typeof error === "string") return error;
|
|
93
|
-
return messageOf(error);
|
|
94
|
-
};
|
|
95
|
-
const decideOne = (transport, input) => decide(transport, input).pipe(Effect.match({
|
|
96
|
-
onSuccess: ({ response, cached }) => ({
|
|
97
|
-
ok: true,
|
|
98
|
-
response,
|
|
99
|
-
cached
|
|
100
|
-
}),
|
|
101
|
-
onFailure: (error) => ({
|
|
102
|
-
ok: false,
|
|
103
|
-
reason: reasonOf(error)
|
|
104
|
-
})
|
|
105
|
-
}));
|
|
106
|
-
const decideEach = (transport, inputs) => Effect.all(pipe(inputs, Array.map((input) => decideOne(transport, input))), { concurrency: "unbounded" }).pipe(Effect.provide(workerServices));
|
|
107
|
-
const serveDecisions = (transport) => {
|
|
108
|
-
runAsWorker((inputs) => Effect.runPromise(decideEach(transport, inputs)));
|
|
109
|
-
};
|
|
110
|
-
export { serveDecisions as t };
|
|
111
|
-
|
|
112
|
-
//# sourceMappingURL=serve-decisions-cQpGj_Fq.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serve-decisions-cQpGj_Fq.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;\nconst 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\nconst 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\nconst 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\nconst 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\nconst 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\ntype CacheServices = Digest.Digest | FileSystem.FileSystem | Path.Path;\n\n/** @internal */\nexport { CACHE_DIR, cacheFile, isComplete, readCache, writeCache };\n/** @internal */\nexport type { CacheServices };\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\nconst 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\n/** @internal */\nexport { workerServices };\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\ntype Services = AppServices | CacheServices | HttpClient.HttpClient;\n\ntype Inputs = Arr.NonEmptyReadonlyArray<DecideInput>;\n\ninterface 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\nconst serveDecisions = (transport: Transport): void => {\n runAsWorker((inputs: Inputs): Promise<Arr.NonEmptyReadonlyArray<DecideResult>> =>\n Effect.runPromise(decideEach(transport, inputs)),\n );\n};\n\n/** @internal */\nexport { serveDecisions };\n/** @internal */\nexport type { Services, Transport };\n"],"mappings":";;;;;;;;;;;AAOA,MAAM,mBAAmB;AAEzB,MAAM,gBAAgB;AACtB,MAAM,YAAY;CAAC;CAAgB;CAAU;AAAwB;AAErE,MAAM,cAAc,UAClB,OAAO,oBAAoB,OAAO,eAAe,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK;AAE5F,MAAM,YAAY,OAAO,GAAG,WAAW,CAAC,CAAC,UAAU,UACjD,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;AAE9E,MAAM,aAGFA,SAAG,KAAK,mBAAmB,UAA4B,YACzD,OAAO,oBAAoB,cAAc,UAAU,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KACtE,OAAO,gBAAgB,KAAK,CAC9B,CACF;AAEA,MAAM,YAAY,OAAO,GAAG,WAAW,CAAC,CAAC,UAAU,UACjD,MACA,SACA;CAGA,QAAO,QADa,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