@r_masseater/oxlint-plugin-decision 0.3.0 → 0.5.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 +69 -39
- package/dist/cloudflare-worker.d.mts +1 -0
- package/dist/cloudflare-worker.mjs +185 -0
- package/dist/cloudflare-worker.mjs.map +1 -0
- package/dist/index.d.mts +8 -6
- package/dist/index.mjs +202 -115
- package/dist/index.mjs.map +1 -1
- package/dist/openrouter-app.d.mts +11 -0
- package/dist/openrouter-app.mjs +87 -0
- package/dist/openrouter-app.mjs.map +1 -0
- package/dist/openrouter-worker.mjs +36 -208
- package/dist/openrouter-worker.mjs.map +1 -1
- package/dist/runtime-CICpEidL.mjs +271 -0
- package/dist/runtime-CICpEidL.mjs.map +1 -0
- package/dist/serve-decisions-pOSYU_8a.mjs +112 -0
- package/dist/serve-decisions-pOSYU_8a.mjs.map +1 -0
- package/dist/wire-BbVK3Q_K.mjs +246 -0
- package/dist/wire-BbVK3Q_K.mjs.map +1 -0
- package/package.json +22 -14
- package/skills/write-decision-rules/SKILL.md +37 -32
- package/skills/write-decision-rules/references/providers.md +14 -10
- package/skills/write-decision-rules/references/tuning.md +7 -7
- package/dist/wire-XOgoBBuu.mjs +0 -540
- package/dist/wire-XOgoBBuu.mjs.map +0 -1
package/dist/wire-XOgoBBuu.mjs
DELETED
|
@@ -1,540 +0,0 @@
|
|
|
1
|
-
import { Array, Boolean, Cause, Config, Console, Effect, Exit, Number as Number$1, Option, Order, Predicate, 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.Number.check(Schema.isBetween({
|
|
7
|
-
minimum: 0,
|
|
8
|
-
maximum: 1
|
|
9
|
-
}));
|
|
10
|
-
const CONFIDENT = .8;
|
|
11
|
-
const Cutoff = Schema.Number.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 }) => report.every((label) => Object.hasOwn(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 YES = "yes";
|
|
67
|
-
const DEFAULT_MINIMUM = "warn";
|
|
68
|
-
const SEVERITY_CRITERIA = {
|
|
69
|
-
none: "No problem",
|
|
70
|
-
info: "Worth noting, but not a problem",
|
|
71
|
-
warn: "Likely a problem",
|
|
72
|
-
error: "Clearly a problem"
|
|
73
|
-
};
|
|
74
|
-
const SEVERITY_ORDER = Object.keys(SEVERITY_CRITERIA);
|
|
75
|
-
const BOOLEAN_ANSWER = { kind: "boolean" };
|
|
76
|
-
const decodeAnswer = Schema.decodeUnknownResult(RuleAnswerSchema);
|
|
77
|
-
const decodeRuleAnswer = (answer) => {
|
|
78
|
-
const decoded = decodeAnswer(answer);
|
|
79
|
-
if (Result.isSuccess(decoded)) return Result.succeed(decoded.success);
|
|
80
|
-
return Result.fail(decoded.failure.message);
|
|
81
|
-
};
|
|
82
|
-
const NoulAnswerSchema = Schema.Struct({
|
|
83
|
-
type: Schema.Literal("noul"),
|
|
84
|
-
noul: Probability
|
|
85
|
-
});
|
|
86
|
-
const ChoiceAnswerSchema = Schema.Struct({
|
|
87
|
-
type: Schema.Literal("choice"),
|
|
88
|
-
choice: Schema.String,
|
|
89
|
-
probabilities: Schema.optional(Schema.Record(Schema.String, Probability))
|
|
90
|
-
});
|
|
91
|
-
const AnswerSchema = Schema.Union([NoulAnswerSchema, ChoiceAnswerSchema]);
|
|
92
|
-
const decodeNoul = Schema.decodeOption(NoulAnswerSchema);
|
|
93
|
-
const decodeChoice = Schema.decodeOption(ChoiceAnswerSchema);
|
|
94
|
-
const isNoul = (answer) => answer.type === "noul";
|
|
95
|
-
const isChoice = (answer) => answer.type === "choice";
|
|
96
|
-
const noulOf = (answer) => Option.fromUndefinedOr(answer).pipe(Option.filter(isNoul), Option.flatMap(decodeNoul));
|
|
97
|
-
const choiceOf = (answer) => Option.fromUndefinedOr(answer).pipe(Option.filter(isChoice), Option.flatMap(decodeChoice));
|
|
98
|
-
const probabilityOfChoice = ({ choice, probabilities }) => Option.fromUndefinedOr(probabilities).pipe(Option.flatMap((byLabel) => Option.fromUndefinedOr(byLabel[choice])));
|
|
99
|
-
const questionFor = (answer, instructions) => {
|
|
100
|
-
switch (answer.kind) {
|
|
101
|
-
case "classify": return {
|
|
102
|
-
type: "choice",
|
|
103
|
-
instructions: `${instructions} Select the label that fits best.`,
|
|
104
|
-
criteria: answer.labels
|
|
105
|
-
};
|
|
106
|
-
case "severity": return {
|
|
107
|
-
type: "choice",
|
|
108
|
-
instructions: `${instructions} Rate how serious the problem is, and select none if there is no problem.`,
|
|
109
|
-
criteria: SEVERITY_CRITERIA
|
|
110
|
-
};
|
|
111
|
-
case "boolean": return {
|
|
112
|
-
type: "noul",
|
|
113
|
-
instructions
|
|
114
|
-
};
|
|
115
|
-
default: return {
|
|
116
|
-
type: "noul",
|
|
117
|
-
instructions
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
const choiceVerdictOf = (criteria, answer) => choiceOf(answer).pipe(Option.filter(({ choice }) => Object.hasOwn(criteria, choice)), Option.flatMap((chosen) => Option.map(probabilityOfChoice(chosen), (probability) => ({
|
|
122
|
-
answer: chosen.choice,
|
|
123
|
-
probability
|
|
124
|
-
}))));
|
|
125
|
-
const verdictOf = (question, answer) => {
|
|
126
|
-
if (question.type === "choice") return choiceVerdictOf(question.criteria, answer);
|
|
127
|
-
return noulOf(answer).pipe(Option.map(({ noul }) => ({
|
|
128
|
-
answer: YES,
|
|
129
|
-
probability: noul
|
|
130
|
-
})));
|
|
131
|
-
};
|
|
132
|
-
const severityMatches = ({ minimum = DEFAULT_MINIMUM }, label) => SEVERITY_ORDER.indexOf(label) >= SEVERITY_ORDER.indexOf(minimum);
|
|
133
|
-
const answerMatches = (answer, label) => {
|
|
134
|
-
switch (answer.kind) {
|
|
135
|
-
case "classify": return answer.report.includes(label);
|
|
136
|
-
case "severity": return severityMatches(answer, label);
|
|
137
|
-
case "boolean": return label === YES;
|
|
138
|
-
default: return false;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const isReported = (rule, verdict) => verdict.probability >= rule.cutoff && answerMatches(rule.answer, verdict.answer);
|
|
142
|
-
// src/options.ts
|
|
143
|
-
const PREFIX = "oxlint-plugin-decision";
|
|
144
|
-
const PROVIDER_SEPARATOR = "/";
|
|
145
|
-
const FIRST_LINE$1 = 1;
|
|
146
|
-
const ONE_RULE = 1;
|
|
147
|
-
const FIRST_COLUMN = 0;
|
|
148
|
-
const TARGET_NODE_TYPES = {
|
|
149
|
-
function: [
|
|
150
|
-
"FunctionDeclaration",
|
|
151
|
-
"FunctionExpression",
|
|
152
|
-
"ArrowFunctionExpression"
|
|
153
|
-
],
|
|
154
|
-
call: ["CallExpression"],
|
|
155
|
-
jsx: ["JSXElement"],
|
|
156
|
-
file: ["Program"]
|
|
157
|
-
};
|
|
158
|
-
const NAMED_PARENTS = {
|
|
159
|
-
VariableDeclarator: "init",
|
|
160
|
-
Property: "value",
|
|
161
|
-
MethodDefinition: "value",
|
|
162
|
-
PropertyDefinition: "value"
|
|
163
|
-
};
|
|
164
|
-
const isNamedParentType = (type) => Object.hasOwn(NAMED_PARENTS, type);
|
|
165
|
-
const ANONYMOUS_FUNCTIONS = /* @__PURE__ */ new Set(["FunctionExpression", "ArrowFunctionExpression"]);
|
|
166
|
-
const holdsAsName = (parent, node) => {
|
|
167
|
-
if (!isNamedParentType(parent.type)) return false;
|
|
168
|
-
const field = NAMED_PARENTS[parent.type];
|
|
169
|
-
return ANONYMOUS_FUNCTIONS.has(node.type) && parent[field] === node;
|
|
170
|
-
};
|
|
171
|
-
const snippetNodeFor = (node) => Option.fromNullishOr(node.parent).pipe(Option.filter((parent) => holdsAsName(parent, node)), Option.getOrElse(() => node));
|
|
172
|
-
const DEFAULTS = {
|
|
173
|
-
ci: "fail",
|
|
174
|
-
timeoutMs: 1e4,
|
|
175
|
-
maxSnippetChars: 4e3,
|
|
176
|
-
model: "openrouter/~typesafe/jev-latest",
|
|
177
|
-
env: {},
|
|
178
|
-
explain: false
|
|
179
|
-
};
|
|
180
|
-
const isSelector = (input) => Predicate.isFunction(input);
|
|
181
|
-
const RULE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
182
|
-
const ModelSpecSchema = Schema.Union([Schema.NonEmptyString, Schema.NonEmptyArray(Schema.NonEmptyString)]);
|
|
183
|
-
const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
|
|
184
|
-
const RuleId = Schema.NonEmptyString.check(Schema.isPattern(RULE_ID, { message: "id must be lowercase words joined by hyphens" }));
|
|
185
|
-
const OptionsSchema = Schema.Struct({
|
|
186
|
-
ci: Schema.optionalKey(CiBehaviorSchema),
|
|
187
|
-
timeoutMs: Schema.optionalKey(PositiveInt),
|
|
188
|
-
maxSnippetChars: Schema.optionalKey(PositiveInt),
|
|
189
|
-
model: Schema.optionalKey(ModelSpecSchema),
|
|
190
|
-
env: Schema.optionalKey(Schema.Record(Schema.NonEmptyString, Schema.NonEmptyString)),
|
|
191
|
-
explain: Schema.optionalKey(ExplainSettingSchema)
|
|
192
|
-
});
|
|
193
|
-
const RuleSchema = Schema.Struct({
|
|
194
|
-
id: RuleId,
|
|
195
|
-
target: TargetSchema,
|
|
196
|
-
question: Schema.NonEmptyString,
|
|
197
|
-
cutoff: Cutoff,
|
|
198
|
-
message: Schema.optionalKey(Schema.NonEmptyString),
|
|
199
|
-
select: Schema.optionalKey(Schema.declare(isSelector)),
|
|
200
|
-
location: Schema.optionalKey(Schema.Struct({
|
|
201
|
-
question: Schema.NonEmptyString,
|
|
202
|
-
cutoff: Cutoff
|
|
203
|
-
})),
|
|
204
|
-
model: Schema.optionalKey(ModelSpecSchema),
|
|
205
|
-
context: Schema.optionalKey(RuleContextSchema),
|
|
206
|
-
answer: Schema.optionalKey(Schema.Unknown)
|
|
207
|
-
});
|
|
208
|
-
const STRICT = { onExcessProperty: "error" };
|
|
209
|
-
const decodeOptions = Schema.decodeUnknownResult(OptionsSchema, STRICT);
|
|
210
|
-
const decodeRule = Schema.decodeUnknownResult(RuleSchema, STRICT);
|
|
211
|
-
var OptionsError = class extends Error {
|
|
212
|
-
constructor(message) {
|
|
213
|
-
super(`${PREFIX}: ${message}`);
|
|
214
|
-
this.name = "OptionsError";
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
const modelIdsOf = (spec) => Array.dedupe(Array.ensure(spec));
|
|
218
|
-
const splitModelId = (id) => {
|
|
219
|
-
const [provider, ...rest] = String$1.split(id, PROVIDER_SEPARATOR);
|
|
220
|
-
const model = rest.join(PROVIDER_SEPARATOR);
|
|
221
|
-
return Option.liftPredicate([provider, model], ([left, right]) => String$1.isNonEmpty(left) && String$1.isNonEmpty(right));
|
|
222
|
-
};
|
|
223
|
-
const resolveModel = (id, providers) => splitModelId(id).pipe(Option.flatMap(([name, model]) => Option.map(Option.fromUndefinedOr(providers[name]), (provider) => ({
|
|
224
|
-
id,
|
|
225
|
-
provider,
|
|
226
|
-
model
|
|
227
|
-
}))), Option.getOrThrowWith(() => new OptionsError(`model "${id}" must be "<provider>/<model>" with a provider from: ${Object.keys(providers).join(", ")}`)));
|
|
228
|
-
const duplicateIdOf = (rules) => Array.findFirst(Object.entries(Array.groupBy(rules, ({ id }) => id)), ([, same]) => same.length > ONE_RULE).pipe(Option.map(([id]) => id));
|
|
229
|
-
const answerOf = (rule) => {
|
|
230
|
-
if (Predicate.isUndefined(rule.answer)) return BOOLEAN_ANSWER;
|
|
231
|
-
return Result.getOrThrowWith(decodeRuleAnswer(rule.answer), (issue) => new OptionsError(`rule "${rule.id}" has an invalid answer: ${issue}`));
|
|
232
|
-
};
|
|
233
|
-
const checked = (decode, input, what) => Result.getOrThrowWith(decode(input), (issue) => new OptionsError(`invalid ${what}: ${issue.message}`));
|
|
234
|
-
const checkRule = (rule) => {
|
|
235
|
-
checked(decodeRule, rule, `rule "${rule.id}"`);
|
|
236
|
-
if (Predicate.isNotUndefined(rule.location) && rule.target !== "file") throw new OptionsError("location is supported only for file rules");
|
|
237
|
-
answerOf(rule);
|
|
238
|
-
return rule;
|
|
239
|
-
};
|
|
240
|
-
const checkRules = (rules) => {
|
|
241
|
-
if (!Array.isReadonlyArrayNonEmpty(rules)) throw new OptionsError("rules must list at least one rule");
|
|
242
|
-
Option.map(duplicateIdOf(rules), (duplicate) => {
|
|
243
|
-
throw new OptionsError(`rule id "${duplicate}" is used more than once`);
|
|
244
|
-
});
|
|
245
|
-
return rules.map((rule) => checkRule(rule));
|
|
246
|
-
};
|
|
247
|
-
const resolveRule = (fallback, providers) => (rule) => ({
|
|
248
|
-
...rule,
|
|
249
|
-
answer: answerOf(rule),
|
|
250
|
-
models: modelIdsOf(rule.model ?? fallback).map((id) => resolveModel(id, providers))
|
|
251
|
-
});
|
|
252
|
-
const settingsFrom = (settings) => {
|
|
253
|
-
if (Predicate.isUndefined(settings)) return {};
|
|
254
|
-
return checked(decodeOptions, settings, "settings");
|
|
255
|
-
};
|
|
256
|
-
const resolveOptions = ({ options, settings }, rules, providers) => {
|
|
257
|
-
const fromCode = checked(decodeOptions, options, "createDecisionPlugin options");
|
|
258
|
-
const { model, ...merged } = {
|
|
259
|
-
...DEFAULTS,
|
|
260
|
-
...fromCode,
|
|
261
|
-
...settingsFrom(settings)
|
|
262
|
-
};
|
|
263
|
-
return {
|
|
264
|
-
ci: merged.ci,
|
|
265
|
-
timeoutMs: merged.timeoutMs,
|
|
266
|
-
maxSnippetChars: merged.maxSnippetChars,
|
|
267
|
-
env: merged.env,
|
|
268
|
-
explain: merged.explain,
|
|
269
|
-
rules: checkRules(rules).map((rule) => resolveRule(model, providers)(rule))
|
|
270
|
-
};
|
|
271
|
-
};
|
|
272
|
-
const headOf = (text, line, column) => {
|
|
273
|
-
const [first] = String$1.split(text, "\n");
|
|
274
|
-
return {
|
|
275
|
-
start: {
|
|
276
|
-
line,
|
|
277
|
-
column
|
|
278
|
-
},
|
|
279
|
-
end: {
|
|
280
|
-
line,
|
|
281
|
-
column: column + first.length
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
};
|
|
285
|
-
const REPORT_LOC = {
|
|
286
|
-
function: (node, text) => headOf(text, node.loc.start.line, node.loc.start.column),
|
|
287
|
-
call: (node) => node.loc,
|
|
288
|
-
jsx: (node) => Option.getOrElse(Option.fromNullishOr(node.openingElement), () => node).loc,
|
|
289
|
-
file: (_node, text) => headOf(text, FIRST_LINE$1, FIRST_COLUMN)
|
|
290
|
-
};
|
|
291
|
-
// src/runtime.ts
|
|
292
|
-
const runOrElse = (effect, fallback) => Exit.match(Effect.runSyncExit(effect), {
|
|
293
|
-
onSuccess: (value) => value,
|
|
294
|
-
onFailure: (cause) => fallback(Cause.squash(cause))
|
|
295
|
-
});
|
|
296
|
-
const envOf = (name) => runOrElse(Config.option(Config.NonEmptyString(name)), () => Option.none()).pipe(Option.map((value) => value.trim()), Option.filter(String$1.isNonEmpty));
|
|
297
|
-
const envNameOf = (env, name) => env[name] ?? name;
|
|
298
|
-
const failsInCi = (options) => options.ci === "fail" && Option.isSome(envOf("CI"));
|
|
299
|
-
const warned = /* @__PURE__ */ new Set();
|
|
300
|
-
const warnOnce = (reason, message) => {
|
|
301
|
-
if (warned.has(reason)) return;
|
|
302
|
-
warned.add(reason);
|
|
303
|
-
Effect.runFork(Console.warn(`${PREFIX}: ${message}`));
|
|
304
|
-
};
|
|
305
|
-
const messageOf = (error) => {
|
|
306
|
-
if (error instanceof Error) return error.message;
|
|
307
|
-
return String(error);
|
|
308
|
-
};
|
|
309
|
-
// src/request.ts
|
|
310
|
-
const CHOICE_OPTION_LIMIT = 254;
|
|
311
|
-
const FIRST_LINE = 1;
|
|
312
|
-
const MINIMUM_WIDTH = 1;
|
|
313
|
-
const UNKNOWN_CHOICE = "unknown";
|
|
314
|
-
const LOCATION_SUFFIX = "_location";
|
|
315
|
-
const TRUNCATION_MARKER = "/* ...truncated */";
|
|
316
|
-
const refAt = (index) => `s${String(index)}`;
|
|
317
|
-
const locationRefOf = (ref) => `${ref}${LOCATION_SUFFIX}`;
|
|
318
|
-
const snippetRefOf = (questionId) => Boolean.match(questionId.endsWith(LOCATION_SUFFIX), {
|
|
319
|
-
onTrue: () => questionId.slice(Number$1.decrement(FIRST_LINE), -9),
|
|
320
|
-
onFalse: () => questionId
|
|
321
|
-
});
|
|
322
|
-
const truncateSnippet = (text, maxChars) => Boolean.match(text.length <= maxChars, {
|
|
323
|
-
onTrue: () => text,
|
|
324
|
-
onFalse: () => `${text.slice(Number$1.decrement(FIRST_LINE), maxChars)}${TRUNCATION_MARKER}`
|
|
325
|
-
});
|
|
326
|
-
const sourceLines = (text) => text.split(/\r\n|[\n\r\u2028\u2029]/u);
|
|
327
|
-
const locates = (match) => Predicate.isNotUndefined(match.rule.location) && !match.truncated;
|
|
328
|
-
const EVERY_LINE = {
|
|
329
|
-
start: FIRST_LINE,
|
|
330
|
-
end: Number.POSITIVE_INFINITY
|
|
331
|
-
};
|
|
332
|
-
const isWithin = (line, within) => Number$1.between(line, {
|
|
333
|
-
minimum: within.start,
|
|
334
|
-
maximum: within.end
|
|
335
|
-
});
|
|
336
|
-
const rangeKey = ({ start, end }) => Boolean.match(start === end, {
|
|
337
|
-
onTrue: () => `L${String(start)}`,
|
|
338
|
-
onFalse: () => `L${String(start)}-L${String(end)}`
|
|
339
|
-
});
|
|
340
|
-
const rangeLabel = ({ start, end }) => Boolean.match(start === end, {
|
|
341
|
-
onTrue: () => `Line ${String(start)}`,
|
|
342
|
-
onFalse: () => `Lines ${String(start)} to ${String(end)}`
|
|
343
|
-
});
|
|
344
|
-
const rangeOf = (group) => ({
|
|
345
|
-
start: Array.headNonEmpty(group).line,
|
|
346
|
-
end: Array.lastNonEmpty(group).line
|
|
347
|
-
});
|
|
348
|
-
const numberedLines = (snippet) => sourceLines(snippet).map((text, index) => ({
|
|
349
|
-
text,
|
|
350
|
-
line: Number$1.sum(index, FIRST_LINE)
|
|
351
|
-
}));
|
|
352
|
-
const locationCandidates = (snippet, within = EVERY_LINE) => {
|
|
353
|
-
const lines = numberedLines(snippet).filter(({ text, line }) => text.trim().length >= FIRST_LINE && isWithin(line, within));
|
|
354
|
-
const width = Math.max(MINIMUM_WIDTH, Math.ceil(lines.length / CHOICE_OPTION_LIMIT));
|
|
355
|
-
return Object.fromEntries(Array.chunksOf(lines, width).map((group) => {
|
|
356
|
-
const range = rangeOf(group);
|
|
357
|
-
return [rangeKey(range), range];
|
|
358
|
-
}));
|
|
359
|
-
};
|
|
360
|
-
const locationQuestion = (match, ref, candidates) => ({
|
|
361
|
-
type: "choice",
|
|
362
|
-
instructions: `Consider only the numbered source in state.snippets.${ref}. If it violates this rule, select the line (or range containing that line) to annotate. Rule: ${match.rule.question} Location: ${match.rule.location.question} If multiple violations exist, select the earliest one. Select ${UNKNOWN_CHOICE} if no violation exists or its location is unclear.`,
|
|
363
|
-
criteria: {
|
|
364
|
-
...Object.fromEntries(Object.entries(candidates).map(([key, range]) => [key, rangeLabel(range)])),
|
|
365
|
-
[UNKNOWN_CHOICE]: "No clear source location for this violation"
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
const validChoice = (answer, criteria) => Option.exists(choiceOf(answer), (chosen) => Object.hasOwn(criteria, chosen.choice) && Option.isSome(probabilityOfChoice(chosen)));
|
|
369
|
-
const selectedLocation = (answer, candidates, cutoff) => choiceOf(answer).pipe(Option.filter((chosen) => Option.exists(probabilityOfChoice(chosen), (probability) => Number$1.isGreaterThanOrEqualTo(probability, cutoff))), Option.flatMap(({ choice }) => Option.fromUndefinedOr(candidates[choice])));
|
|
370
|
-
const locationOfLine = (snippet, line) => {
|
|
371
|
-
const text = Option.getOrElse(Array.get(sourceLines(snippet), Number$1.decrement(line)), () => "");
|
|
372
|
-
return {
|
|
373
|
-
start: {
|
|
374
|
-
line,
|
|
375
|
-
column: Math.max(Number$1.decrement(FIRST_LINE), text.search(/\S/u))
|
|
376
|
-
},
|
|
377
|
-
end: {
|
|
378
|
-
line,
|
|
379
|
-
column: text.trimEnd().length
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
};
|
|
383
|
-
const numbered = (snippet) => numberedLines(snippet).map(({ text, line }) => `L${String(line)}| ${text}`).join("\n");
|
|
384
|
-
const contextNote = (match, ref) => {
|
|
385
|
-
if (Predicate.isUndefined(match.context)) return "";
|
|
386
|
-
return ` state.contexts.${ref} shows the source around it; use it only to understand the snippet.`;
|
|
387
|
-
};
|
|
388
|
-
const mainQuestionFor = (match, ref) => [ref, questionFor(match.rule.answer, `Consider only snippet "${ref}" in state.snippets.${contextNote(match, ref)} ${match.rule.question}`)];
|
|
389
|
-
const questionsFor = (match, ref) => {
|
|
390
|
-
if (!locates(match)) return [mainQuestionFor(match, ref)];
|
|
391
|
-
return [mainQuestionFor(match, ref), [locationRefOf(ref), locationQuestion(match, ref, locationCandidates(match.snippet))]];
|
|
392
|
-
};
|
|
393
|
-
const snippetFor = (match) => {
|
|
394
|
-
if (locates(match)) return numbered(match.snippet);
|
|
395
|
-
return match.snippet;
|
|
396
|
-
};
|
|
397
|
-
const contextsOf = (matches) => {
|
|
398
|
-
const contexts = matches.flatMap((match, index) => Option.toArray(Option.map(Option.fromUndefinedOr(match.context), (text) => [refAt(index), text])));
|
|
399
|
-
if (Array.isReadonlyArrayEmpty(contexts)) return {};
|
|
400
|
-
return { contexts: Object.fromEntries(contexts) };
|
|
401
|
-
};
|
|
402
|
-
const buildRequest = (model, matches) => ({
|
|
403
|
-
model,
|
|
404
|
-
state: {
|
|
405
|
-
snippets: Object.fromEntries(matches.map((match, index) => [refAt(index), snippetFor(match)])),
|
|
406
|
-
...contextsOf(matches)
|
|
407
|
-
},
|
|
408
|
-
questions: Object.fromEntries(matches.flatMap((match, index) => questionsFor(match, refAt(index))))
|
|
409
|
-
});
|
|
410
|
-
const choiceQuestionsOf$1 = (request) => Object.entries(request.questions).flatMap(([id, question]) => {
|
|
411
|
-
if (question.type === "choice") return [[id, question.criteria]];
|
|
412
|
-
return [];
|
|
413
|
-
});
|
|
414
|
-
const mainQuestionsOf = (request) => Object.entries(request.questions).filter(([id]) => !id.endsWith(LOCATION_SUFFIX));
|
|
415
|
-
const resultOf = (answers, [ref, question]) => [ref, Option.getOrThrowWith(verdictOf(question, answers[ref]), () => /* @__PURE__ */ new Error(`response has no valid answer for "${ref}"`))];
|
|
416
|
-
const parseVerdicts = (response, request) => {
|
|
417
|
-
const { model, answers } = Option.getOrThrowWith(Option.liftPredicate(response, ({ model: served }) => String$1.isNonEmpty(served)), () => /* @__PURE__ */ new Error("response has no model id"));
|
|
418
|
-
return {
|
|
419
|
-
model,
|
|
420
|
-
results: Object.fromEntries(mainQuestionsOf(request).map((entry) => resultOf(answers, entry))),
|
|
421
|
-
answers,
|
|
422
|
-
complete: choiceQuestionsOf$1(request).every(([id, criteria]) => validChoice(answers[id], criteria))
|
|
423
|
-
};
|
|
424
|
-
};
|
|
425
|
-
// src/wire.ts
|
|
426
|
-
const RESPAN_MODELS = ["respan/"];
|
|
427
|
-
const OPTION_SEPARATOR = "__";
|
|
428
|
-
const CERTAIN = 1;
|
|
429
|
-
const NO_SEVERITY = "none";
|
|
430
|
-
const sectionsOf = (name, entries) => Object.entries(entries).map(([ref, text]) => `state.${name}.${ref}:\n${text}`);
|
|
431
|
-
const stateAsText = ({ snippets, contexts = {} }) => [...sectionsOf("snippets", snippets), ...sectionsOf("contexts", contexts)].join("\n\n");
|
|
432
|
-
const isRespan = (model) => RESPAN_MODELS.some((prefix) => model.startsWith(prefix));
|
|
433
|
-
const only = (entries, ref) => Option.match(Option.fromUndefinedOr(entries[ref]), {
|
|
434
|
-
onNone: () => ({}),
|
|
435
|
-
onSome: (text) => ({ [ref]: text })
|
|
436
|
-
});
|
|
437
|
-
const stateOf = ({ snippets, contexts }, ref) => {
|
|
438
|
-
if (Predicate.isUndefined(contexts)) return { snippets: only(snippets, ref) };
|
|
439
|
-
return {
|
|
440
|
-
snippets: only(snippets, ref),
|
|
441
|
-
contexts: only(contexts, ref)
|
|
442
|
-
};
|
|
443
|
-
};
|
|
444
|
-
const optionIdOf = (id, label) => `${id}${OPTION_SEPARATOR}${label}`;
|
|
445
|
-
const isSeverityScale = (criteria) => Object.keys(criteria).join(",") === SEVERITY_ORDER.join(",");
|
|
446
|
-
const optionText = (label, description) => Option.match(Option.fromNullishOr(description), {
|
|
447
|
-
onNone: () => `"${label}"`,
|
|
448
|
-
onSome: (text) => `"${label}" (${text})`
|
|
449
|
-
});
|
|
450
|
-
const labelQuestion = (instructions, label, description) => ({
|
|
451
|
-
type: "noul",
|
|
452
|
-
instructions: `${instructions} Does the label ${optionText(label, description)} fit?`
|
|
453
|
-
});
|
|
454
|
-
const levelQuestion = (instructions, label, description) => ({
|
|
455
|
-
type: "noul",
|
|
456
|
-
instructions: `${instructions} Is it at least as serious as ${optionText(label, description)}?`
|
|
457
|
-
});
|
|
458
|
-
const levelsAboveNone = (criteria) => Object.entries(criteria).filter(([label]) => label !== NO_SEVERITY);
|
|
459
|
-
const yesNoQuestionsOf = (id, { instructions, criteria }) => {
|
|
460
|
-
if (isSeverityScale(criteria)) return levelsAboveNone(criteria).map(([label, description]) => [optionIdOf(id, label), levelQuestion(instructions, label, description)]);
|
|
461
|
-
return Object.entries(criteria).map(([label, description]) => [optionIdOf(id, label), labelQuestion(instructions, label, description)]);
|
|
462
|
-
};
|
|
463
|
-
const asYesNo = ([id, question]) => {
|
|
464
|
-
if (question.type === "choice") return yesNoQuestionsOf(id, question);
|
|
465
|
-
return [[id, question]];
|
|
466
|
-
};
|
|
467
|
-
const perSnippet = (request) => {
|
|
468
|
-
const wires = Object.values(Array.groupBy(Object.entries(request.questions), ([id]) => snippetRefOf(id))).map((questions) => {
|
|
469
|
-
const [[id]] = questions;
|
|
470
|
-
return {
|
|
471
|
-
model: request.model,
|
|
472
|
-
state: stateAsText(stateOf(request.state, snippetRefOf(id))),
|
|
473
|
-
questions: Object.fromEntries(questions.flatMap((entry) => asYesNo(entry)))
|
|
474
|
-
};
|
|
475
|
-
});
|
|
476
|
-
if (Array.isReadonlyArrayNonEmpty(wires)) return wires;
|
|
477
|
-
return [request];
|
|
478
|
-
};
|
|
479
|
-
const wireRequestsFor = (request) => {
|
|
480
|
-
if (isRespan(request.model)) return perSnippet(request);
|
|
481
|
-
return [request];
|
|
482
|
-
};
|
|
483
|
-
const byYes = Order.mapInput(Order.Number, ({ yes }) => yes);
|
|
484
|
-
const scoreOf = (answers, id, label) => Option.map(noulOf(answers[optionIdOf(id, label)]), ({ noul }) => ({
|
|
485
|
-
label,
|
|
486
|
-
yes: noul
|
|
487
|
-
}));
|
|
488
|
-
const scoresOf = (answers, id, labels) => Option.flatMap(Option.all(labels.map((label) => scoreOf(answers, id, label))), (scores) => Option.liftPredicate(scores, Array.isArrayNonEmpty));
|
|
489
|
-
const probabilitiesOf = (scores) => Object.fromEntries(scores.map(({ label, yes }) => [label, yes]));
|
|
490
|
-
const choiceAnswer = (choice, probabilities) => ({
|
|
491
|
-
type: "choice",
|
|
492
|
-
choice,
|
|
493
|
-
probabilities
|
|
494
|
-
});
|
|
495
|
-
const bestLabel = (scores) => choiceAnswer(Array.max(scores, byYes).label, probabilitiesOf(scores));
|
|
496
|
-
const atLeast = (scores) => pipe(scores, Array.map(({ label }, index) => ({
|
|
497
|
-
label,
|
|
498
|
-
yes: Math.max(...scores.slice(index).map(({ yes }) => yes))
|
|
499
|
-
})));
|
|
500
|
-
const severityLevel = (scores) => {
|
|
501
|
-
const cumulative = atLeast(scores);
|
|
502
|
-
const probabilities = {
|
|
503
|
-
[NO_SEVERITY]: Number$1.subtract(CERTAIN, Array.headNonEmpty(cumulative).yes),
|
|
504
|
-
...probabilitiesOf(cumulative)
|
|
505
|
-
};
|
|
506
|
-
const reached = pipe(cumulative, Array.findLast(({ yes }) => yes >= CONFIDENT));
|
|
507
|
-
return choiceAnswer(Option.match(reached, {
|
|
508
|
-
onNone: () => NO_SEVERITY,
|
|
509
|
-
onSome: ({ label }) => label
|
|
510
|
-
}), probabilities);
|
|
511
|
-
};
|
|
512
|
-
const labelsAsked = (criteria) => {
|
|
513
|
-
if (isSeverityScale(criteria)) return levelsAboveNone(criteria).map(([label]) => label);
|
|
514
|
-
return Object.keys(criteria);
|
|
515
|
-
};
|
|
516
|
-
const choiceFromYesNo = (answers, [id, { criteria }]) => {
|
|
517
|
-
const collapse = Boolean.match(isSeverityScale(criteria), {
|
|
518
|
-
onTrue: () => severityLevel,
|
|
519
|
-
onFalse: () => bestLabel
|
|
520
|
-
});
|
|
521
|
-
return scoresOf(answers, id, labelsAsked(criteria)).pipe(Option.map((scores) => [id, collapse(scores)]), Option.toArray);
|
|
522
|
-
};
|
|
523
|
-
const choiceQuestionsOf = (request) => Object.entries(request.questions).flatMap(([id, question]) => {
|
|
524
|
-
if (question.type === "choice") return [[id, question]];
|
|
525
|
-
return [];
|
|
526
|
-
});
|
|
527
|
-
const withChoices = (request, answers) => {
|
|
528
|
-
if (!isRespan(request.model)) return answers;
|
|
529
|
-
return {
|
|
530
|
-
...answers,
|
|
531
|
-
...Object.fromEntries(choiceQuestionsOf(request).flatMap((entry) => choiceFromYesNo(answers, entry)))
|
|
532
|
-
};
|
|
533
|
-
};
|
|
534
|
-
const mergeResponses = (request, responses) => ({
|
|
535
|
-
...Array.headNonEmpty(responses),
|
|
536
|
-
answers: withChoices(request, Object.fromEntries(responses.flatMap(({ answers }) => Object.entries(answers))))
|
|
537
|
-
});
|
|
538
|
-
export { resolveOptions as A, REPORT_LOC as C, checked as D, checkRules as E, AnswerSchema as M, isReported as N, modelIdsOf as O, PREFIX as S, TARGET_NODE_TYPES as T, messageOf as _, locationCandidates as a, ModelSpecSchema as b, locationRefOf as c, selectedLocation as d, sourceLines as f, failsInCi as g, envOf as h, locates as i, snippetNodeFor as j, resolveModel as k, parseVerdicts as l, envNameOf as m, wireRequestsFor as n, locationOfLine as o, truncateSnippet as p, buildRequest as r, locationQuestion as s, mergeResponses as t, refAt as u, runOrElse as v, STRICT as w, OptionsError as x, warnOnce as y };
|
|
539
|
-
|
|
540
|
-
//# sourceMappingURL=wire-XOgoBBuu.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wire-XOgoBBuu.mjs","names":["FIRST_LINE","Arr","Str","Str","Bool","Num","Arr","choiceQuestionsOf","Str","Arr","Num","Bool"],"sources":["../src/schema.ts","../src/answer.ts","../src/options.ts","../src/runtime.ts","../src/request.ts","../src/wire.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nconst NONE = 0;\nconst MINIMUM_LABELS = 2;\n\nconst NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(NONE));\n\nconst Probability = Schema.Number.check(Schema.isBetween({ minimum: 0, maximum: 1 }));\n\nconst CONFIDENT = 0.8;\n\nconst Cutoff = Schema.Number.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(({ labels, report }) => report.every((label) => Object.hasOwn(labels, label)), {\n message: \"every label in report must be one of labels\",\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 } 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 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[] = Object.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});\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 = (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 }) => Object.hasOwn(criteria, choice)),\n Option.flatMap((chosen) =>\n Option.map(probabilityOfChoice(chosen), (probability) => ({\n answer: chosen.choice,\n probability,\n })),\n ),\n );\n\nconst verdictOf = (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\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 rule: { readonly answer: RuleAnswer; readonly cutoff: number },\n verdict: Verdict,\n): boolean => verdict.probability >= rule.cutoff && answerMatches(rule.answer, verdict.answer);\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 type { Location } from \"@oxlint/plugins\";\nimport { Array as Arr, Option, Predicate, Result, Schema, String as Str } 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 AstNode,\n DecisionOptions,\n DecisionProvider,\n DecisionRule,\n ModelRef,\n ModelSpec,\n ResolvedOptions,\n ResolvedRule,\n RuleAnswer,\n Target,\n} from \"./types.ts\";\n\nconst PREFIX = \"oxlint-plugin-decision\";\nconst PROVIDER_SEPARATOR = \"/\";\nconst FIRST_LINE = 1;\nconst ONE_RULE = 1;\nconst FIRST_COLUMN = 0;\n\nconst TARGET_NODE_TYPES = {\n function: [\"FunctionDeclaration\", \"FunctionExpression\", \"ArrowFunctionExpression\"],\n call: [\"CallExpression\"],\n jsx: [\"JSXElement\"],\n file: [\"Program\"],\n} as const satisfies Readonly<Record<Target, readonly string[]>>;\n\nconst NAMED_PARENTS = {\n VariableDeclarator: \"init\",\n Property: \"value\",\n MethodDefinition: \"value\",\n PropertyDefinition: \"value\",\n} as const;\n\ntype NamedField = (typeof NAMED_PARENTS)[keyof typeof NAMED_PARENTS];\n\nconst isNamedParentType = (type: string): type is keyof typeof NAMED_PARENTS =>\n Object.hasOwn(NAMED_PARENTS, type);\n\nconst ANONYMOUS_FUNCTIONS: ReadonlySet<string> = new Set([\n \"FunctionExpression\",\n \"ArrowFunctionExpression\",\n]);\n\nconst holdsAsName = (parent: AstNode, node: AstNode): boolean => {\n if (!isNamedParentType(parent.type)) {\n return false;\n }\n const field: NamedField = NAMED_PARENTS[parent.type];\n return ANONYMOUS_FUNCTIONS.has(node.type) && parent[field] === node;\n};\n\nconst snippetNodeFor = (node: AstNode): AstNode =>\n Option.fromNullishOr(node.parent).pipe(\n Option.filter((parent) => holdsAsName(parent, node)),\n Option.getOrElse((): AstNode => node),\n );\n\nconst DEFAULTS = {\n ci: \"fail\",\n timeoutMs: 10_000,\n maxSnippetChars: 4000,\n model: \"openrouter/~typesafe/jev-latest\",\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\nclass OptionsError extends Error {\n public constructor(message: string) {\n super(`${PREFIX}: ${message}`);\n this.name = \"OptionsError\";\n }\n}\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 = rest.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 id: string,\n providers: Readonly<Record<string, DecisionProvider>>,\n): 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 () =>\n new OptionsError(\n `model \"${id}\" must be \"<provider>/<model>\" with a provider from: ${Object.keys(providers).join(\", \")}`,\n ),\n ),\n );\n\nconst duplicateIdOf = (rules: readonly DecisionRule[]): Option.Option<string> =>\n Arr.findFirst(\n Object.entries(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(\n decodeRuleAnswer(rule.answer),\n (issue) => new 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 = <Value>(decode: Decode<Value>, input: unknown, what: string): Value =>\n Result.getOrThrowWith(\n decode(input),\n (issue) => new OptionsError(`invalid ${what}: ${issue.message}`),\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 new 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 new OptionsError(\"rules must list at least one rule\");\n }\n Option.map(duplicateIdOf(rules), (duplicate) => {\n throw new OptionsError(`rule id \"${duplicate}\" is used more than once`);\n });\n return rules.map((rule) => checkRule(rule));\n};\n\nconst resolveRule =\n (fallback: ModelSpec, providers: Readonly<Record<string, DecisionProvider>>) =>\n (rule: DecisionRule): ResolvedRule => ({\n ...rule,\n answer: answerOf(rule),\n models: modelIdsOf(rule.model ?? fallback).map((id) => resolveModel(id, providers)),\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 { 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: checkRules(rules).map((rule) => resolveRule(model, providers)(rule)),\n };\n};\n\nconst headOf = (text: string, line: number, column: number): Location => {\n const [first] = Str.split(text, \"\\n\");\n return { start: { line, column }, end: { line, column: column + first.length } };\n};\n\nconst REPORT_LOC = {\n function: (node: AstNode, text: string): Location =>\n headOf(text, node.loc.start.line, node.loc.start.column),\n call: (node: AstNode): Location => node.loc,\n jsx: (node: AstNode): Location =>\n Option.getOrElse(Option.fromNullishOr(node.openingElement), () => node).loc,\n file: (_node: AstNode, text: string): Location => headOf(text, FIRST_LINE, FIRST_COLUMN),\n} as const satisfies Readonly<Record<Target, (node: AstNode, text: string) => Location>>;\n\nexport type { Decode, Sources };\nexport {\n checkRules,\n OptionsError,\n PREFIX,\n REPORT_LOC,\n ModelSpecSchema,\n STRICT,\n TARGET_NODE_TYPES,\n checked,\n modelIdsOf,\n resolveModel,\n resolveOptions,\n snippetNodeFor,\n};\n","import { Cause, Config, Console, Effect, Exit, Option, String as Str } from \"effect\";\n\nimport { PREFIX } from \"./options.ts\";\nimport type { ResolvedOptions } from \"./types.ts\";\n\nconst runOrElse = <Value>(\n effect: Effect.Effect<Value, unknown>,\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\nconst envOf = (name: string): Option.Option<string> =>\n runOrElse(Config.option(Config.NonEmptyString(name)), () => Option.none()).pipe(\n Option.map((value) => value.trim()),\n Option.filter(Str.isNonEmpty),\n );\n\nconst envNameOf = (env: Readonly<Record<string, string>>, name: string): string =>\n env[name] ?? name;\n\nconst failsInCi = (options: ResolvedOptions): boolean =>\n options.ci === \"fail\" && Option.isSome(envOf(\"CI\"));\n\nconst warned = new Set<string>();\n\nconst warnOnce = (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\nexport { envNameOf, envOf, failsInCi, messageOf, runOrElse, warnOnce };\n","import type { Location } from \"@oxlint/plugins\";\nimport {\n Array as Arr,\n Boolean as Bool,\n Number as Num,\n Option,\n Predicate,\n String as Str,\n} from \"effect\";\n\nimport { choiceOf, probabilityOfChoice, questionFor, verdictOf } from \"./answer.ts\";\nimport type {\n Answer,\n Answers,\n ChoiceQuestion,\n DecisionRequest,\n DecisionResponse,\n LineRange,\n Question,\n RequestMatch,\n RuleLocation,\n Verdict,\n Verdicts,\n} from \"./types.ts\";\n\nconst CHOICE_OPTION_LIMIT = 254;\nconst FIRST_LINE = 1;\nconst MINIMUM_WIDTH = 1;\nconst UNKNOWN_CHOICE = \"unknown\";\nconst LOCATION_SUFFIX = \"_location\";\nconst TRUNCATION_MARKER = \"/* ...truncated */\";\n\nconst refAt = (index: number): string => `s${String(index)}`;\n\nconst locationRefOf = (ref: string): string => `${ref}${LOCATION_SUFFIX}`;\n\nconst snippetRefOf = (questionId: string): string =>\n Bool.match(questionId.endsWith(LOCATION_SUFFIX), {\n onTrue: () => questionId.slice(Num.decrement(FIRST_LINE), -LOCATION_SUFFIX.length),\n onFalse: () => questionId,\n });\n\nconst truncateSnippet = (text: string, maxChars: number): string =>\n Bool.match(text.length <= maxChars, {\n onTrue: () => text,\n onFalse: () => `${text.slice(Num.decrement(FIRST_LINE), maxChars)}${TRUNCATION_MARKER}`,\n });\n\nconst sourceLines = (text: string): readonly string[] => text.split(/\\r\\n|[\\n\\r\\u2028\\u2029]/u);\n\ntype LocatedMatch = RequestMatch & {\n readonly rule: { readonly question: string; readonly location: RuleLocation };\n};\n\nconst locates = (match: RequestMatch): match is LocatedMatch =>\n Predicate.isNotUndefined(match.rule.location) && !match.truncated;\n\ninterface NumberedLine {\n readonly text: string;\n readonly line: number;\n}\n\nconst EVERY_LINE: LineRange = { start: FIRST_LINE, end: Number.POSITIVE_INFINITY };\n\nconst isWithin = (line: number, within: LineRange): boolean =>\n Num.between(line, { minimum: within.start, maximum: within.end });\n\nconst rangeKey = ({ start, end }: LineRange): string =>\n Bool.match(start === end, {\n onTrue: () => `L${String(start)}`,\n onFalse: () => `L${String(start)}-L${String(end)}`,\n });\n\nconst rangeLabel = ({ start, end }: LineRange): string =>\n Bool.match(start === end, {\n onTrue: () => `Line ${String(start)}`,\n onFalse: () => `Lines ${String(start)} to ${String(end)}`,\n });\n\nconst rangeOf = (group: Arr.NonEmptyReadonlyArray<NumberedLine>): LineRange => ({\n start: Arr.headNonEmpty(group).line,\n end: Arr.lastNonEmpty(group).line,\n});\n\nconst numberedLines = (snippet: string): readonly NumberedLine[] =>\n sourceLines(snippet).map((text, index) => ({ text, line: Num.sum(index, FIRST_LINE) }));\n\nconst locationCandidates = (\n snippet: string,\n within: LineRange = EVERY_LINE,\n): Readonly<Record<string, LineRange>> => {\n const lines = numberedLines(snippet).filter(\n ({ text, line }) => text.trim().length >= FIRST_LINE && isWithin(line, within),\n );\n const width = Math.max(MINIMUM_WIDTH, Math.ceil(lines.length / CHOICE_OPTION_LIMIT));\n return Object.fromEntries(\n Arr.chunksOf(lines, width).map((group) => {\n const range = rangeOf(group);\n return [rangeKey(range), range];\n }),\n );\n};\n\nconst locationQuestion = (\n match: LocatedMatch,\n ref: string,\n candidates: Readonly<Record<string, LineRange>>,\n): ChoiceQuestion => ({\n type: \"choice\",\n instructions: `Consider only the numbered source in state.snippets.${ref}. If it violates this rule, select the line (or range containing that line) to annotate. Rule: ${match.rule.question} Location: ${match.rule.location.question} If multiple violations exist, select the earliest one. Select ${UNKNOWN_CHOICE} if no violation exists or its location is unclear.`,\n criteria: {\n ...Object.fromEntries(\n Object.entries(candidates).map(([key, range]) => [key, rangeLabel(range)]),\n ),\n [UNKNOWN_CHOICE]: \"No clear source location for this violation\",\n },\n});\n\ntype ChoiceCriteria = ChoiceQuestion[\"criteria\"];\n\nconst validChoice = (answer: Answer | undefined, criteria: ChoiceCriteria): boolean =>\n Option.exists(\n choiceOf(answer),\n (chosen) =>\n Object.hasOwn(criteria, chosen.choice) && Option.isSome(probabilityOfChoice(chosen)),\n );\n\nconst selectedLocation = (\n answer: Answer | undefined,\n candidates: Readonly<Record<string, LineRange>>,\n cutoff: number,\n): Option.Option<LineRange> =>\n choiceOf(answer).pipe(\n Option.filter((chosen) =>\n Option.exists(probabilityOfChoice(chosen), (probability) =>\n Num.isGreaterThanOrEqualTo(probability, cutoff),\n ),\n ),\n Option.flatMap(({ choice }) => Option.fromUndefinedOr(candidates[choice])),\n );\n\nconst locationOfLine = (snippet: string, line: number): Location => {\n const text = Option.getOrElse(Arr.get(sourceLines(snippet), Num.decrement(line)), () => \"\");\n return {\n start: { line, column: Math.max(Num.decrement(FIRST_LINE), text.search(/\\S/u)) },\n end: { line, column: text.trimEnd().length },\n };\n};\n\nconst numbered = (snippet: string): string =>\n numberedLines(snippet)\n .map(({ text, line }) => `L${String(line)}| ${text}`)\n .join(\"\\n\");\n\nconst contextNote = (match: RequestMatch, ref: string): string => {\n if (Predicate.isUndefined(match.context)) {\n return \"\";\n }\n return ` state.contexts.${ref} shows the source around it; use it only to understand the snippet.`;\n};\n\nconst mainQuestionFor = (match: RequestMatch, ref: string): readonly [string, Question] => [\n ref,\n questionFor(\n match.rule.answer,\n `Consider only snippet \"${ref}\" in state.snippets.${contextNote(match, ref)} ${match.rule.question}`,\n ),\n];\n\nconst questionsFor = (\n match: RequestMatch,\n ref: string,\n): readonly (readonly [string, Question])[] => {\n if (!locates(match)) {\n return [mainQuestionFor(match, ref)];\n }\n return [\n mainQuestionFor(match, ref),\n [locationRefOf(ref), locationQuestion(match, ref, locationCandidates(match.snippet))],\n ];\n};\n\nconst snippetFor = (match: RequestMatch): string => {\n if (locates(match)) {\n return numbered(match.snippet);\n }\n return match.snippet;\n};\n\nconst contextsOf = (\n matches: readonly RequestMatch[],\n): Readonly<{ contexts?: Readonly<Record<string, string>> }> => {\n const contexts = matches.flatMap((match, index) =>\n Option.toArray(\n Option.map(Option.fromUndefinedOr(match.context), (text) => [refAt(index), text] as const),\n ),\n );\n if (Arr.isReadonlyArrayEmpty(contexts)) {\n return {};\n }\n return { contexts: Object.fromEntries(contexts) };\n};\n\nconst buildRequest = (model: string, matches: readonly RequestMatch[]): DecisionRequest => ({\n model,\n state: {\n snippets: Object.fromEntries(matches.map((match, index) => [refAt(index), snippetFor(match)])),\n ...contextsOf(matches),\n },\n questions: Object.fromEntries(\n matches.flatMap((match, index) => questionsFor(match, refAt(index))),\n ),\n});\n\nconst choiceQuestionsOf = (\n request: DecisionRequest,\n): readonly (readonly [string, ChoiceCriteria])[] =>\n Object.entries(request.questions).flatMap(([id, question]) => {\n if (question.type === \"choice\") {\n return [[id, question.criteria] as const];\n }\n return [];\n });\n\nconst mainQuestionsOf = (request: DecisionRequest): readonly (readonly [string, Question])[] =>\n Object.entries(request.questions).filter(([id]) => !id.endsWith(LOCATION_SUFFIX));\n\nconst resultOf = (\n answers: Answers,\n [ref, question]: readonly [string, Question],\n): readonly [string, Verdict] => [\n ref,\n Option.getOrThrowWith(\n verdictOf(question, answers[ref]),\n () => new Error(`response has no valid answer for \"${ref}\"`),\n ),\n];\n\nconst parseVerdicts = (response: DecisionResponse, request: DecisionRequest): Verdicts => {\n const { model, answers } = Option.getOrThrowWith(\n Option.liftPredicate(response, ({ model: served }) => Str.isNonEmpty(served)),\n () => new Error(\"response has no model id\"),\n );\n const results = Object.fromEntries(\n mainQuestionsOf(request).map((entry) => resultOf(answers, entry)),\n );\n const complete = choiceQuestionsOf(request).every(([id, criteria]) =>\n validChoice(answers[id], criteria),\n );\n return { model, results, answers, complete };\n};\n\nexport {\n buildRequest,\n locates,\n locationCandidates,\n locationOfLine,\n locationQuestion,\n locationRefOf,\n parseVerdicts,\n refAt,\n selectedLocation,\n snippetRefOf,\n sourceLines,\n truncateSnippet,\n};\nexport type { LocatedMatch };\n","import type { DecisionsRequest } from \"@openrouter/sdk/models\";\nimport {\n Array as Arr,\n Boolean as Bool,\n Number as Num,\n Option,\n Order,\n Predicate,\n pipe,\n} from \"effect\";\n\nimport { SEVERITY_ORDER, noulOf } from \"./answer.ts\";\nimport { snippetRefOf } from \"./request.ts\";\nimport { CONFIDENT } from \"./schema.ts\";\nimport type {\n Answers,\n ChoiceAnswer,\n ChoiceQuestion,\n DecisionRequest,\n DecisionResponse,\n NoulQuestion,\n Question,\n} from \"./types.ts\";\n\ntype State = DecisionRequest[\"state\"];\n\ntype ChoiceCriteria = ChoiceQuestion[\"criteria\"];\n\ninterface WireRequest extends Readonly<Pick<DecisionsRequest, \"model\" | \"state\" | \"questions\">> {\n readonly state: DecisionRequest[\"state\"] | string;\n readonly questions: Readonly<Record<string, Question>>;\n}\n\nconst RESPAN_MODELS = [\"respan/\"] as const;\nconst OPTION_SEPARATOR = \"__\";\nconst CERTAIN = 1;\nconst NO_SEVERITY = \"none\";\n\nconst sectionsOf = (name: string, entries: Readonly<Record<string, string>>): readonly string[] =>\n Object.entries(entries).map(([ref, text]) => `state.${name}.${ref}:\\n${text}`);\n\nconst stateAsText = ({ snippets, contexts = {} }: State): string =>\n [...sectionsOf(\"snippets\", snippets), ...sectionsOf(\"contexts\", contexts)].join(\"\\n\\n\");\n\nconst isRespan = (model: string): boolean =>\n RESPAN_MODELS.some((prefix) => model.startsWith(prefix));\n\nconst only = (\n entries: Readonly<Record<string, string>>,\n ref: string,\n): Readonly<Record<string, string>> =>\n Option.match(Option.fromUndefinedOr(entries[ref]), {\n onNone: () => ({}),\n onSome: (text) => ({ [ref]: text }),\n });\n\nconst stateOf = ({ snippets, contexts }: State, ref: string): State => {\n if (Predicate.isUndefined(contexts)) {\n return { snippets: only(snippets, ref) };\n }\n return { snippets: only(snippets, ref), contexts: only(contexts, ref) };\n};\n\nconst optionIdOf = (id: string, label: string): string => `${id}${OPTION_SEPARATOR}${label}`;\n\nconst isSeverityScale = (criteria: ChoiceCriteria): boolean =>\n Object.keys(criteria).join(\",\") === SEVERITY_ORDER.join(\",\");\n\nconst optionText = (label: string, description: string | null): string =>\n Option.match(Option.fromNullishOr(description), {\n onNone: () => `\"${label}\"`,\n onSome: (text) => `\"${label}\" (${text})`,\n });\n\nconst labelQuestion = (\n instructions: string,\n label: string,\n description: string | null,\n): NoulQuestion => ({\n type: \"noul\",\n instructions: `${instructions} Does the label ${optionText(label, description)} fit?`,\n});\n\nconst levelQuestion = (\n instructions: string,\n label: string,\n description: string | null,\n): NoulQuestion => ({\n type: \"noul\",\n instructions: `${instructions} Is it at least as serious as ${optionText(label, description)}?`,\n});\n\nconst levelsAboveNone = (criteria: ChoiceCriteria): readonly (readonly [string, string | null])[] =>\n Object.entries(criteria).filter(([label]) => label !== NO_SEVERITY);\n\nconst yesNoQuestionsOf = (\n id: string,\n { instructions, criteria }: ChoiceQuestion,\n): readonly (readonly [string, NoulQuestion])[] => {\n if (isSeverityScale(criteria)) {\n return levelsAboveNone(criteria).map(([label, description]) => [\n optionIdOf(id, label),\n levelQuestion(instructions, label, description),\n ]);\n }\n return Object.entries(criteria).map(([label, description]) => [\n optionIdOf(id, label),\n labelQuestion(instructions, label, description),\n ]);\n};\n\nconst asYesNo = ([id, question]: readonly [string, Question]): readonly (readonly [\n string,\n Question,\n])[] => {\n if (question.type === \"choice\") {\n return yesNoQuestionsOf(id, question);\n }\n return [[id, question]];\n};\n\nconst perSnippet = (request: DecisionRequest): Arr.NonEmptyReadonlyArray<WireRequest> => {\n const wires = Object.values(\n Arr.groupBy(Object.entries(request.questions), ([id]) => snippetRefOf(id)),\n ).map((questions): WireRequest => {\n const [[id]] = questions;\n return {\n model: request.model,\n state: stateAsText(stateOf(request.state, snippetRefOf(id))),\n questions: Object.fromEntries(questions.flatMap((entry) => asYesNo(entry))),\n };\n });\n if (Arr.isReadonlyArrayNonEmpty(wires)) {\n return wires;\n }\n return [request];\n};\n\nconst wireRequestsFor = (request: DecisionRequest): Arr.NonEmptyReadonlyArray<WireRequest> => {\n if (isRespan(request.model)) {\n return perSnippet(request);\n }\n return [request];\n};\n\ninterface Score {\n readonly label: string;\n readonly yes: number;\n}\n\nconst byYes = Order.mapInput(Order.Number, ({ yes }: Score) => yes);\n\nconst scoreOf = (answers: Answers, id: string, label: string): Option.Option<Score> =>\n Option.map(noulOf(answers[optionIdOf(id, label)]), ({ noul }) => ({ label, yes: noul }));\n\nconst scoresOf = (\n answers: Answers,\n id: string,\n labels: readonly string[],\n): Option.Option<Arr.NonEmptyReadonlyArray<Score>> =>\n Option.flatMap(Option.all(labels.map((label) => scoreOf(answers, id, label))), (scores) =>\n Option.liftPredicate(scores, Arr.isArrayNonEmpty),\n );\n\nconst probabilitiesOf = (scores: readonly Score[]): Readonly<Record<string, number>> =>\n Object.fromEntries(scores.map(({ label, yes }) => [label, yes]));\n\nconst choiceAnswer = (\n choice: string,\n probabilities: Readonly<Record<string, number>>,\n): ChoiceAnswer => ({\n type: \"choice\",\n choice,\n probabilities,\n});\n\nconst bestLabel = (scores: Arr.NonEmptyReadonlyArray<Score>): ChoiceAnswer =>\n choiceAnswer(Arr.max(scores, byYes).label, probabilitiesOf(scores));\n\nconst atLeast = (scores: Arr.NonEmptyReadonlyArray<Score>): Arr.NonEmptyReadonlyArray<Score> =>\n pipe(\n scores,\n Arr.map(({ label }, index) => ({\n label,\n yes: Math.max(...scores.slice(index).map(({ yes }) => yes)),\n })),\n );\n\nconst severityLevel = (scores: Arr.NonEmptyReadonlyArray<Score>): ChoiceAnswer => {\n const cumulative = atLeast(scores);\n const probabilities = {\n [NO_SEVERITY]: Num.subtract(CERTAIN, Arr.headNonEmpty(cumulative).yes),\n ...probabilitiesOf(cumulative),\n };\n const reached = pipe(\n cumulative,\n Arr.findLast(({ yes }) => yes >= CONFIDENT),\n );\n return choiceAnswer(\n Option.match(reached, { onNone: () => NO_SEVERITY, onSome: ({ label }) => label }),\n probabilities,\n );\n};\n\nconst labelsAsked = (criteria: ChoiceCriteria): readonly string[] => {\n if (isSeverityScale(criteria)) {\n return levelsAboveNone(criteria).map(([label]) => label);\n }\n return Object.keys(criteria);\n};\n\nconst choiceFromYesNo = (\n answers: Answers,\n [id, { criteria }]: readonly [string, ChoiceQuestion],\n): readonly (readonly [string, ChoiceAnswer])[] => {\n const collapse = Bool.match(isSeverityScale(criteria), {\n onTrue: () => severityLevel,\n onFalse: () => bestLabel,\n });\n return scoresOf(answers, id, labelsAsked(criteria)).pipe(\n Option.map((scores) => [id, collapse(scores)] as const),\n Option.toArray,\n );\n};\n\nconst choiceQuestionsOf = (\n request: DecisionRequest,\n): readonly (readonly [string, ChoiceQuestion])[] =>\n Object.entries(request.questions).flatMap(([id, question]) => {\n if (question.type === \"choice\") {\n return [[id, question] as const];\n }\n return [];\n });\n\nconst withChoices = (request: DecisionRequest, answers: Answers): Answers => {\n if (!isRespan(request.model)) {\n return answers;\n }\n return {\n ...answers,\n ...Object.fromEntries(\n choiceQuestionsOf(request).flatMap((entry) => choiceFromYesNo(answers, entry)),\n ),\n };\n};\n\nconst mergeResponses = (\n request: DecisionRequest,\n responses: Arr.NonEmptyReadonlyArray<DecisionResponse>,\n): DecisionResponse => ({\n ...Arr.headNonEmpty(responses),\n answers: withChoices(\n request,\n Object.fromEntries(responses.flatMap(({ answers }) => Object.entries(answers))),\n ),\n});\n\nexport { mergeResponses, wireRequestsFor };\nexport type { WireRequest };\n"],"mappings":";;AAEA,MAAM,OAAO;AACb,MAA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