@r_masseater/oxlint-plugin-decision 0.7.0 → 0.8.1
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 +17 -3
- package/dist/{app-Bso1uwY5.mjs → app-D2bguKZ_.mjs} +182 -88
- package/dist/app-D2bguKZ_.mjs.map +1 -0
- package/dist/claim-rule-B0LCcxxc.mjs +36 -0
- package/dist/claim-rule-B0LCcxxc.mjs.map +1 -0
- package/dist/cloudflare-worker.mjs +111 -3
- package/dist/cloudflare-worker.mjs.map +1 -1
- package/dist/{index-BOrpK3Iv.d.mts → index-B4wX62VC.d.mts} +2 -2
- package/dist/{index-Cgg-w0hb.d.mts → index-CK88FBE5.d.mts} +691 -349
- package/dist/index.d.mts +2 -3
- package/dist/index.mjs +1 -1
- package/dist/{define-presets-clyqLZxo.mjs → preset-plugin-MKdvpXxa.mjs} +11 -214
- package/dist/preset-plugin-MKdvpXxa.mjs.map +1 -0
- package/dist/presets/ai-slop.d.mts +2 -3
- package/dist/presets/ai-slop.mjs +179 -2
- package/dist/presets/ai-slop.mjs.map +1 -1
- package/dist/presets/index.d.mts +1 -1
- package/dist/presets/index.mjs +1 -1
- package/dist/presets/recommended.d.mts +1 -2
- package/dist/presets/recommended.mjs +1 -2
- package/dist/presets/recommended.mjs.map +1 -1
- package/dist/presets/review-only.d.mts +1 -2
- package/dist/presets/review-only.mjs +1 -2
- package/dist/presets/review-only.mjs.map +1 -1
- package/dist/presets/strict.d.mts +1 -2
- package/dist/presets/strict.mjs +1 -2
- package/dist/presets/strict.mjs.map +1 -1
- package/dist/serve-decisions-D6M-l2uy.mjs +232 -0
- package/dist/serve-decisions-D6M-l2uy.mjs.map +1 -0
- package/dist/typesafe-worker.mjs +29 -0
- package/dist/typesafe-worker.mjs.map +1 -0
- package/dist/{decision-BtTZ52be.mjs → wire-CKpt_MBX.mjs} +56 -261
- package/dist/wire-CKpt_MBX.mjs.map +1 -0
- package/package.json +26 -29
- package/skills/write-decision-rules/SKILL.md +6 -7
- package/skills/write-decision-rules/references/tuning.md +3 -5
- package/dist/app-Bso1uwY5.mjs.map +0 -1
- package/dist/decision-BtTZ52be.mjs.map +0 -1
- package/dist/define-presets-clyqLZxo.mjs.map +0 -1
- package/dist/index-D7VrRpTx.d.mts +0 -6
- package/dist/openrouter-app.d.mts +0 -19
- package/dist/openrouter-app.mjs +0 -1
- package/dist/openrouter-worker.mjs +0 -15
- package/dist/openrouter-worker.mjs.map +0 -1
- package/dist/preset-plugin-AAwedMeS.mjs +0 -10
- package/dist/preset-plugin-AAwedMeS.mjs.map +0 -1
- package/dist/serve-decisions-CjlhvYm7.mjs +0 -290
- package/dist/serve-decisions-CjlhvYm7.mjs.map +0 -1
- package/skills/write-decision-rules/references/providers.md +0 -55
- /package/dist/{openrouter-worker.d.mts → typesafe-worker.d.mts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array, Boolean, Cause, Config, Console, DateTime, Effect, Exit, Function,
|
|
1
|
+
import { Array, Boolean, Cause, Config, Console, DateTime, Effect, Exit, Function, Number as Number$1, Option, Predicate, Record, Result, Schema, String as String$1, pipe } from "effect";
|
|
2
2
|
// src/entities/decision/model/schema.ts
|
|
3
3
|
const NONE = 0;
|
|
4
4
|
const MINIMUM_LABELS = 2;
|
|
@@ -63,7 +63,7 @@ const RuleAnswerSchema = Schema.Union([
|
|
|
63
63
|
SeverityAnswer
|
|
64
64
|
]);
|
|
65
65
|
// src/entities/decision/model/answer.ts
|
|
66
|
-
const DATA_FIRST_ARITY$
|
|
66
|
+
const DATA_FIRST_ARITY$4 = 2;
|
|
67
67
|
const YES = "yes";
|
|
68
68
|
const DEFAULT_MINIMUM = "warn";
|
|
69
69
|
const SEVERITY_CRITERIA = {
|
|
@@ -97,7 +97,7 @@ const isChoice = (answer) => answer.type === "choice";
|
|
|
97
97
|
const noulOf = (answer) => Option.fromUndefinedOr(answer).pipe(Option.filter(isNoul), Option.flatMap(decodeNoul));
|
|
98
98
|
const choiceOf = (answer) => Option.fromUndefinedOr(answer).pipe(Option.filter(isChoice), Option.flatMap(decodeChoice));
|
|
99
99
|
const probabilityOfChoice = ({ choice, probabilities }) => Option.fromUndefinedOr(probabilities).pipe(Option.flatMap((byLabel) => Option.fromUndefinedOr(byLabel[choice])));
|
|
100
|
-
const questionFor = Function.dual(DATA_FIRST_ARITY$
|
|
100
|
+
const questionFor = Function.dual(DATA_FIRST_ARITY$4, (answer, instructions) => {
|
|
101
101
|
switch (answer.kind) {
|
|
102
102
|
case "classify": return {
|
|
103
103
|
type: "choice",
|
|
@@ -123,7 +123,7 @@ const choiceVerdictOf = (criteria, answer) => choiceOf(answer).pipe(Option.filte
|
|
|
123
123
|
answer: chosen.choice,
|
|
124
124
|
probability
|
|
125
125
|
}))));
|
|
126
|
-
const verdictOf = Function.dual(DATA_FIRST_ARITY$
|
|
126
|
+
const verdictOf = Function.dual(DATA_FIRST_ARITY$4, (question, answer) => {
|
|
127
127
|
if (question.type === "choice") return choiceVerdictOf(question.criteria, answer);
|
|
128
128
|
return noulOf(answer).pipe(Option.map(({ noul }) => ({
|
|
129
129
|
answer: YES,
|
|
@@ -139,18 +139,18 @@ const answerMatches = (answer, label) => {
|
|
|
139
139
|
default: return false;
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
const isReported = Function.dual(DATA_FIRST_ARITY$
|
|
142
|
+
const isReported = Function.dual(DATA_FIRST_ARITY$4, (rule, verdict) => verdict.probability >= rule.cutoff && answerMatches(rule.answer, verdict.answer));
|
|
143
143
|
// src/entities/decision/model/location.ts
|
|
144
|
-
const DATA_FIRST_ARITY$
|
|
145
|
-
const DATA_FIRST_ARITY_3$
|
|
144
|
+
const DATA_FIRST_ARITY$3 = 2;
|
|
145
|
+
const DATA_FIRST_ARITY_3$1 = 3;
|
|
146
146
|
const CHOICE_OPTION_LIMIT = 254;
|
|
147
|
-
const FIRST_LINE$
|
|
147
|
+
const FIRST_LINE$1 = 1;
|
|
148
148
|
const MINIMUM_WIDTH = 1;
|
|
149
149
|
const UNKNOWN_CHOICE = "unknown";
|
|
150
150
|
const sourceLines = (text) => String$1.split(text, /\r\n|[\n\r\u2028\u2029]/u);
|
|
151
151
|
const locates = (match) => Predicate.isNotUndefined(match.rule.location) && !match.truncated;
|
|
152
152
|
const EVERY_LINE = {
|
|
153
|
-
start: FIRST_LINE$
|
|
153
|
+
start: FIRST_LINE$1,
|
|
154
154
|
end: Number.POSITIVE_INFINITY
|
|
155
155
|
};
|
|
156
156
|
const isWithin = (line, within) => Number$1.between(line, {
|
|
@@ -171,17 +171,17 @@ const rangeOf = (group) => ({
|
|
|
171
171
|
});
|
|
172
172
|
const numberedLines = (snippet) => pipe(sourceLines(snippet), Array.map((text, index) => ({
|
|
173
173
|
text,
|
|
174
|
-
line: Number$1.sum(index, FIRST_LINE$
|
|
174
|
+
line: Number$1.sum(index, FIRST_LINE$1)
|
|
175
175
|
})));
|
|
176
|
-
const locationCandidates = Function.dual(DATA_FIRST_ARITY$
|
|
177
|
-
const lines = pipe(numberedLines(snippet), Array.filter(({ text, line }) => String$1.trim(text).length >= FIRST_LINE$
|
|
176
|
+
const locationCandidates = Function.dual(DATA_FIRST_ARITY$3, (snippet, within) => {
|
|
177
|
+
const lines = pipe(numberedLines(snippet), Array.filter(({ text, line }) => String$1.trim(text).length >= FIRST_LINE$1 && isWithin(line, within)));
|
|
178
178
|
const width = Math.max(MINIMUM_WIDTH, Math.ceil(lines.length / CHOICE_OPTION_LIMIT));
|
|
179
179
|
return Record.fromEntries(pipe(Array.chunksOf(lines, width), Array.map((group) => {
|
|
180
180
|
const range = rangeOf(group);
|
|
181
181
|
return [rangeKey(range), range];
|
|
182
182
|
})));
|
|
183
183
|
});
|
|
184
|
-
const locationQuestion = Function.dual(DATA_FIRST_ARITY_3$
|
|
184
|
+
const locationQuestion = Function.dual(DATA_FIRST_ARITY_3$1, (match, ref, candidates) => ({
|
|
185
185
|
type: "choice",
|
|
186
186
|
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.`,
|
|
187
187
|
criteria: {
|
|
@@ -189,14 +189,14 @@ const locationQuestion = Function.dual(DATA_FIRST_ARITY_3$3, (match, ref, candid
|
|
|
189
189
|
[UNKNOWN_CHOICE]: "No clear source location for this violation"
|
|
190
190
|
}
|
|
191
191
|
}));
|
|
192
|
-
const validChoice = Function.dual(DATA_FIRST_ARITY$
|
|
193
|
-
const selectedLocation = Function.dual(DATA_FIRST_ARITY_3$
|
|
194
|
-
const locationOfLine = Function.dual(DATA_FIRST_ARITY$
|
|
192
|
+
const validChoice = Function.dual(DATA_FIRST_ARITY$3, (answer, criteria) => Option.exists(choiceOf(answer), (chosen) => Record.has(criteria, chosen.choice) && Option.isSome(probabilityOfChoice(chosen))));
|
|
193
|
+
const selectedLocation = Function.dual(DATA_FIRST_ARITY_3$1, (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]))));
|
|
194
|
+
const locationOfLine = Function.dual(DATA_FIRST_ARITY$3, (snippet, line) => {
|
|
195
195
|
const text = Option.getOrElse(Array.get(sourceLines(snippet), Number$1.decrement(line)), () => "");
|
|
196
196
|
return {
|
|
197
197
|
start: {
|
|
198
198
|
line,
|
|
199
|
-
column: Option.getOrElse(String$1.search(/\S/u)(text), () => Number$1.decrement(FIRST_LINE$
|
|
199
|
+
column: Option.getOrElse(String$1.search(/\S/u)(text), () => Number$1.decrement(FIRST_LINE$1))
|
|
200
200
|
},
|
|
201
201
|
end: {
|
|
202
202
|
line,
|
|
@@ -204,132 +204,15 @@ const locationOfLine = Function.dual(DATA_FIRST_ARITY$5, (snippet, line) => {
|
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
206
|
});
|
|
207
|
-
// src/entities/decision/model/
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
"FunctionExpression",
|
|
214
|
-
"ArrowFunctionExpression"
|
|
215
|
-
],
|
|
216
|
-
call: ["CallExpression"],
|
|
217
|
-
jsx: ["JSXElement"],
|
|
218
|
-
file: ["Program"]
|
|
219
|
-
};
|
|
220
|
-
const NAMED_PARENTS = {
|
|
221
|
-
VariableDeclarator: "init",
|
|
222
|
-
Property: "value",
|
|
223
|
-
MethodDefinition: "value",
|
|
224
|
-
PropertyDefinition: "value"
|
|
225
|
-
};
|
|
226
|
-
const NAMED_PARENT_TYPES = new Set(Record.keys(NAMED_PARENTS));
|
|
227
|
-
const isNamedParentType = (type) => NAMED_PARENT_TYPES.has(type);
|
|
228
|
-
const ANONYMOUS_FUNCTIONS = /* @__PURE__ */ new Set(["FunctionExpression", "ArrowFunctionExpression"]);
|
|
229
|
-
const holdsAsName = (parent, node) => {
|
|
230
|
-
if (!isNamedParentType(parent.type)) return false;
|
|
231
|
-
const field = NAMED_PARENTS[parent.type];
|
|
232
|
-
return ANONYMOUS_FUNCTIONS.has(node.type) && parent[field] === node;
|
|
233
|
-
};
|
|
234
|
-
const snippetNodeFor = (node) => Option.fromNullishOr(node.parent).pipe(Option.filter((parent) => holdsAsName(parent, node)), Option.getOrElse(() => node));
|
|
235
|
-
const headOf = (text, line, column) => {
|
|
236
|
-
const [first] = String$1.split(text, "\n");
|
|
237
|
-
return {
|
|
238
|
-
start: {
|
|
239
|
-
line,
|
|
240
|
-
column
|
|
241
|
-
},
|
|
242
|
-
end: {
|
|
243
|
-
line,
|
|
244
|
-
column: column + first.length
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
const REPORT_LOC = {
|
|
249
|
-
function: (node, text) => headOf(text, node.loc.start.line, node.loc.start.column),
|
|
250
|
-
call: (node) => node.loc,
|
|
251
|
-
jsx: (node) => Option.getOrElse(Option.fromNullishOr(node.openingElement), () => node).loc,
|
|
252
|
-
file: (_node, text) => headOf(text, FIRST_LINE$2, FIRST_COLUMN)
|
|
253
|
-
};
|
|
254
|
-
// src/entities/decision/model/context.ts
|
|
255
|
-
const DATA_FIRST_ARITY_3$2 = 3;
|
|
256
|
-
const DEFAULT_LINES = 5;
|
|
257
|
-
const FIRST_LINE$1 = 1;
|
|
258
|
-
const LAST = 1;
|
|
259
|
-
const END = 1;
|
|
260
|
-
const ENCLOSING_TYPES = {
|
|
261
|
-
function: [
|
|
262
|
-
"FunctionDeclaration",
|
|
263
|
-
"FunctionExpression",
|
|
264
|
-
"ArrowFunctionExpression"
|
|
265
|
-
],
|
|
266
|
-
class: ["ClassDeclaration", "ClassExpression"],
|
|
267
|
-
block: [
|
|
268
|
-
"BlockStatement",
|
|
269
|
-
"StaticBlock",
|
|
270
|
-
"Program"
|
|
271
|
-
]
|
|
272
|
-
};
|
|
273
|
-
const ancestorsOf = (node) => Array.unfold(Option.fromNullishOr(node.parent), (current) => current.pipe(Option.map((ancestor) => [ancestor, Option.fromNullishOr(ancestor.parent)])));
|
|
274
|
-
const enclosingText = (context, node, kind) => Array.findFirst(ancestorsOf(node), (ancestor) => ENCLOSING_TYPES[kind].includes(ancestor.type)).pipe(Option.match({
|
|
275
|
-
onNone: () => context.sourceCode.text,
|
|
276
|
-
onSome: (ancestor) => context.sourceCode.getText(ancestor)
|
|
277
|
-
}));
|
|
278
|
-
const linesAround = (context, node, { before = DEFAULT_LINES, after = DEFAULT_LINES }) => {
|
|
279
|
-
const lines = sourceLines(context.sourceCode.text);
|
|
280
|
-
const first = Math.max(FIRST_LINE$1, node.loc.start.line - before);
|
|
281
|
-
const last = Math.min(lines.length, node.loc.end.line + after);
|
|
282
|
-
return pipe(lines, Array.drop(first - FIRST_LINE$1), Array.take(last - first + FIRST_LINE$1), Array.map((text, index) => `L${String(first + index)}| ${text}`), Array.join("\n"));
|
|
283
|
-
};
|
|
284
|
-
const DECLARING_PARENTS = /* @__PURE__ */ new Set([
|
|
285
|
-
"VariableDeclaration",
|
|
286
|
-
"ExportNamedDeclaration",
|
|
287
|
-
"ExportDefaultDeclaration"
|
|
288
|
-
]);
|
|
289
|
-
const declarationOf = (node) => Option.fromNullishOr(node.parent).pipe(Option.filter((parent) => DECLARING_PARENTS.has(parent.type)), Option.match({
|
|
290
|
-
onNone: () => node,
|
|
291
|
-
onSome: declarationOf
|
|
292
|
-
}));
|
|
293
|
-
const leadingOf = (text, comments, until) => Option.match(Array.last(comments), {
|
|
294
|
-
onNone: () => [],
|
|
295
|
-
onSome: (last) => {
|
|
296
|
-
if (String$1.isNonEmpty(String$1.trim(String$1.slice(last.end, until)(text)))) return [];
|
|
297
|
-
return [...leadingOf(text, Array.dropRight(comments, LAST), last.start), last];
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
const commentedTextOf = (context, node) => {
|
|
301
|
-
const { text } = context.sourceCode;
|
|
302
|
-
const named = snippetNodeFor(node);
|
|
303
|
-
const [start] = declarationOf(named).range;
|
|
304
|
-
const before = pipe(context.sourceCode.getAllComments(), Array.filter((comment) => comment.type !== "Shebang" && comment.end <= start));
|
|
305
|
-
return Array.match(leadingOf(text, before, start), {
|
|
306
|
-
onEmpty: () => Option.none(),
|
|
307
|
-
onNonEmpty: ([first]) => Option.some(String$1.slice(first.start, named.range[END])(text))
|
|
308
|
-
});
|
|
309
|
-
};
|
|
310
|
-
const isCommented = ({ context: wanted }) => Predicate.isNotUndefined(wanted) && wanted.scope === "comment";
|
|
311
|
-
const commentedSnippetOf = Function.dual(DATA_FIRST_ARITY_3$2, (context, node, rule) => Option.flatMap(Option.liftPredicate(rule, isCommented), () => commentedTextOf(context, node)));
|
|
312
|
-
const lacksComment = Function.dual(DATA_FIRST_ARITY_3$2, (context, node, rule) => isCommented(rule) && Option.isNone(commentedTextOf(context, node)));
|
|
313
|
-
const contextOf = Function.dual(DATA_FIRST_ARITY_3$2, (context, node, rule) => {
|
|
314
|
-
if (rule.scope === "lines") return Option.some(linesAround(context, node, rule));
|
|
315
|
-
if (rule.scope === "enclosing") return Option.some(enclosingText(context, node, rule.kind));
|
|
316
|
-
return Option.liftPredicate(context.sourceCode.text, () => rule.scope === "file");
|
|
317
|
-
});
|
|
318
|
-
// src/entities/decision/model/name.ts
|
|
319
|
-
const DATA_FIRST_ARITY_3$1 = 3;
|
|
320
|
-
const heldName = (node) => Option.flatMap(Option.fromNullishOr(node.parent), (parent) => Match.value(parent).pipe(Match.when({ type: "VariableDeclarator" }, (holder) => Option.liftPredicate(holder.id, () => holder.init === node)), Match.when({ type: Match.is("Property", "MethodDefinition", "PropertyDefinition") }, (holder) => Option.liftPredicate(holder.key, () => holder.value === node)), Match.orElse(() => Option.none())));
|
|
321
|
-
const nameNodeOf = (node) => Match.value(node).pipe(Match.when({ type: Match.is("FunctionDeclaration", "FunctionExpression") }, (fn) => Option.orElse(Option.fromNullishOr(fn.id), () => heldName(fn))), Match.when({ type: "ArrowFunctionExpression" }, heldName), Match.when({ type: Match.is("CallExpression", "NewExpression") }, (call) => Option.some(call.callee)), Match.when({ type: "JSXElement" }, (element) => Option.some(element.openingElement.name)), Match.orElse(() => Option.none()));
|
|
322
|
-
const nameOf = (node, context) => Option.getOrUndefined(Option.map(nameNodeOf(node), (name) => String$1.slice(name.start, name.end)(context.sourceCode.text)));
|
|
323
|
-
const isSelected = Function.dual(DATA_FIRST_ARITY_3$1, (context, node, { select }) => Option.match(Option.fromUndefinedOr(select), {
|
|
324
|
-
onNone: () => true,
|
|
325
|
-
onSome: (selects) => selects(node, {
|
|
326
|
-
name: nameOf(node, context),
|
|
327
|
-
context
|
|
328
|
-
})
|
|
329
|
-
}));
|
|
207
|
+
// src/entities/decision/model/models.ts
|
|
208
|
+
const JEV_MODEL = /^jev-(?:latest|\d+\.\d+)$/u;
|
|
209
|
+
const CLEF_MODEL = /^@cf\/cloudflare\/clef(?:-flash|-omni)?$/u;
|
|
210
|
+
const DECISION_MODEL = /^(?:typesafe\/jev-(?:latest|\d+\.\d+)|cloudflare\/@cf\/cloudflare\/clef(?:-flash|-omni)?)$/u;
|
|
211
|
+
const isDecisionModel = (model) => DECISION_MODEL.test(model);
|
|
212
|
+
const DecisionModelSchema = Schema.String.pipe(Schema.refine(isDecisionModel, { message: "model must be a decision model: \"typesafe/jev-latest\", \"typesafe/jev-<major>.<minor>\", or \"cloudflare/@cf/cloudflare/clef\", \"clef-flash\" or \"clef-omni\"" }));
|
|
330
213
|
// src/entities/decision/model/options.ts
|
|
331
214
|
const DATA_FIRST_ARITY_3 = 3;
|
|
332
|
-
const DATA_FIRST_ARITY$
|
|
215
|
+
const DATA_FIRST_ARITY$2 = 2;
|
|
333
216
|
const PREFIX = "oxlint-plugin-decision";
|
|
334
217
|
const PROVIDER_SEPARATOR = "/";
|
|
335
218
|
const ONE_RULE = 1;
|
|
@@ -343,7 +226,7 @@ const DEFAULTS = {
|
|
|
343
226
|
};
|
|
344
227
|
const isSelector = (input) => Predicate.isFunction(input);
|
|
345
228
|
const RULE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
|
|
346
|
-
const ModelSpecSchema = Schema.Union([
|
|
229
|
+
const ModelSpecSchema = Schema.Union([DecisionModelSchema, Schema.NonEmptyArray(DecisionModelSchema)]);
|
|
347
230
|
const PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(1));
|
|
348
231
|
const RuleId = Schema.NonEmptyString.check(Schema.isPattern(RULE_ID, { message: "id must be lowercase words joined by hyphens" }));
|
|
349
232
|
const OptionsSchema = Schema.Struct({
|
|
@@ -383,10 +266,10 @@ const splitModelId = (id) => {
|
|
|
383
266
|
};
|
|
384
267
|
const acceptedModel = (ref) => {
|
|
385
268
|
const { models, name } = ref.provider;
|
|
386
|
-
if (
|
|
269
|
+
if (!models.test(ref.model)) throw optionsError(`model "${ref.id}" is not a decision model that the "${name}" provider accepts`);
|
|
387
270
|
return ref;
|
|
388
271
|
};
|
|
389
|
-
const resolveModel = Function.dual(DATA_FIRST_ARITY$
|
|
272
|
+
const resolveModel = Function.dual(DATA_FIRST_ARITY$2, (id, providers) => acceptedModel(splitModelId(id).pipe(Option.flatMap(([name, model]) => Option.map(Option.fromUndefinedOr(providers[name]), (provider) => ({
|
|
390
273
|
id,
|
|
391
274
|
provider,
|
|
392
275
|
model
|
|
@@ -436,7 +319,7 @@ const resolveOptions = Function.dual(DATA_FIRST_ARITY_3, ({ options, settings },
|
|
|
436
319
|
};
|
|
437
320
|
});
|
|
438
321
|
// src/entities/decision/model/request.ts
|
|
439
|
-
const DATA_FIRST_ARITY$
|
|
322
|
+
const DATA_FIRST_ARITY$1 = 2;
|
|
440
323
|
const FIRST_LINE = 1;
|
|
441
324
|
const LOCATION_SUFFIX = "_location";
|
|
442
325
|
const TRUNCATION_MARKER = "/* ...truncated */";
|
|
@@ -446,7 +329,7 @@ const snippetRefOf = (questionId) => Boolean.match(String$1.endsWith(LOCATION_SU
|
|
|
446
329
|
onTrue: () => String$1.slice(Number$1.decrement(FIRST_LINE), -9)(questionId),
|
|
447
330
|
onFalse: () => questionId
|
|
448
331
|
});
|
|
449
|
-
const truncateSnippet = Function.dual(DATA_FIRST_ARITY$
|
|
332
|
+
const truncateSnippet = Function.dual(DATA_FIRST_ARITY$1, (text, maxChars) => Boolean.match(text.length <= maxChars, {
|
|
450
333
|
onTrue: () => text,
|
|
451
334
|
onFalse: () => `${String$1.slice(Number$1.decrement(FIRST_LINE), maxChars)(text)}${TRUNCATION_MARKER}`
|
|
452
335
|
}));
|
|
@@ -469,7 +352,7 @@ const contextsOf = (matches) => {
|
|
|
469
352
|
if (Array.isReadonlyArrayEmpty(contexts)) return {};
|
|
470
353
|
return { contexts: Record.fromEntries(contexts) };
|
|
471
354
|
};
|
|
472
|
-
const buildRequest = Function.dual(DATA_FIRST_ARITY$
|
|
355
|
+
const buildRequest = Function.dual(DATA_FIRST_ARITY$1, (model, matches) => ({
|
|
473
356
|
model,
|
|
474
357
|
state: {
|
|
475
358
|
snippets: Record.fromEntries(pipe(matches, Array.map((match, index) => [refAt(index), snippetFor(match)]))),
|
|
@@ -477,35 +360,35 @@ const buildRequest = Function.dual(DATA_FIRST_ARITY$3, (model, matches) => ({
|
|
|
477
360
|
},
|
|
478
361
|
questions: Record.fromEntries(pipe(matches, Array.flatMap((match, index) => questionsFor(match, refAt(index)))))
|
|
479
362
|
}));
|
|
480
|
-
const choiceQuestionsOf
|
|
363
|
+
const choiceQuestionsOf = (request) => pipe(Record.toEntries(request.questions), Array.flatMap(([id, question]) => {
|
|
481
364
|
if (question.type === "choice") return [[id, question.criteria]];
|
|
482
365
|
return [];
|
|
483
366
|
}));
|
|
484
367
|
const mainQuestionsOf = (request) => pipe(Record.toEntries(request.questions), Array.filter(([id]) => !String$1.endsWith(LOCATION_SUFFIX)(id)));
|
|
485
368
|
const resultOf = (answers, [ref, question]) => [ref, Option.getOrThrowWith(verdictOf(question, answers[ref]), () => /* @__PURE__ */ new Error(`response has no valid answer for "${ref}"`))];
|
|
486
|
-
const parseVerdicts = Function.dual(DATA_FIRST_ARITY$
|
|
369
|
+
const parseVerdicts = Function.dual(DATA_FIRST_ARITY$1, (response, request) => {
|
|
487
370
|
const { model, answers } = Option.getOrThrowWith(Option.liftPredicate(response, ({ model: served }) => String$1.isNonEmpty(served)), () => /* @__PURE__ */ new Error("response has no model id"));
|
|
488
371
|
return {
|
|
489
372
|
model,
|
|
490
373
|
results: Record.fromEntries(pipe(mainQuestionsOf(request), Array.map((entry) => resultOf(answers, entry)))),
|
|
491
374
|
answers,
|
|
492
|
-
complete: pipe(choiceQuestionsOf
|
|
375
|
+
complete: pipe(choiceQuestionsOf(request), Array.every(([id, criteria]) => validChoice(answers[id], criteria)))
|
|
493
376
|
};
|
|
494
377
|
});
|
|
495
378
|
// src/entities/decision/model/runtime.ts
|
|
496
|
-
const DATA_FIRST_ARITY
|
|
379
|
+
const DATA_FIRST_ARITY = 2;
|
|
497
380
|
const encodeJson = Schema.encodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
498
381
|
const toJson = (value) => Option.getOrElse(encodeJson(value), () => String(value));
|
|
499
382
|
const nowMs = () => DateTime.toEpochMillis(DateTime.nowUnsafe());
|
|
500
|
-
const runOrElse = Function.dual(DATA_FIRST_ARITY
|
|
383
|
+
const runOrElse = Function.dual(DATA_FIRST_ARITY, (effect, fallback) => Exit.match(Effect.runSyncExit(effect), {
|
|
501
384
|
onSuccess: (value) => value,
|
|
502
385
|
onFailure: (cause) => fallback(Cause.squash(cause))
|
|
503
386
|
}));
|
|
504
387
|
const envOf = (name) => runOrElse(Config.option(Config.NonEmptyString(name)), () => Option.none()).pipe(Option.map((value) => String$1.trim(value)), Option.filter(String$1.isNonEmpty));
|
|
505
|
-
const envNameOf = Function.dual(DATA_FIRST_ARITY
|
|
388
|
+
const envNameOf = Function.dual(DATA_FIRST_ARITY, (env, name) => env[name] ?? name);
|
|
506
389
|
const failsInCi = (options) => options.ci === "fail" && Option.isSome(envOf("CI"));
|
|
507
390
|
const warned = /* @__PURE__ */ new Set();
|
|
508
|
-
const warnOnce = Function.dual(DATA_FIRST_ARITY
|
|
391
|
+
const warnOnce = Function.dual(DATA_FIRST_ARITY, (reason, message) => {
|
|
509
392
|
if (warned.has(reason)) return;
|
|
510
393
|
warned.add(reason);
|
|
511
394
|
Effect.runFork(Console.warn(`${PREFIX}: ${message}`));
|
|
@@ -514,74 +397,9 @@ const messageOf = (error) => {
|
|
|
514
397
|
if (error instanceof Error) return error.message;
|
|
515
398
|
return String(error);
|
|
516
399
|
};
|
|
517
|
-
const captured = Function.dual(DATA_FIRST_ARITY
|
|
518
|
-
// src/entities/decision/model/wire-choice.ts
|
|
519
|
-
const DATA_FIRST_ARITY$1 = 2;
|
|
520
|
-
const RESPAN_MODELS = ["respan/"];
|
|
521
|
-
const OPTION_SEPARATOR = "__";
|
|
522
|
-
const CERTAIN = 1;
|
|
523
|
-
const NO_SEVERITY = "none";
|
|
524
|
-
const isRespan = (model) => pipe(RESPAN_MODELS, Array.some((prefix) => String$1.startsWith(prefix)(model)));
|
|
525
|
-
const optionIdOf = Function.dual(DATA_FIRST_ARITY$1, (id, label) => `${id}${OPTION_SEPARATOR}${label}`);
|
|
526
|
-
const isSeverityScale = (criteria) => pipe(Record.keys(criteria), Array.join(",")) === pipe(SEVERITY_ORDER, Array.join(","));
|
|
527
|
-
const levelsAboveNone = (criteria) => pipe(Record.toEntries(criteria), Array.filter(([label]) => label !== NO_SEVERITY));
|
|
528
|
-
const byYes = Order.mapInput(Order.Number, ({ yes }) => yes);
|
|
529
|
-
const scoreOf = (answers, id, label) => Option.map(noulOf(answers[optionIdOf(id, label)]), ({ noul }) => ({
|
|
530
|
-
label,
|
|
531
|
-
yes: noul
|
|
532
|
-
}));
|
|
533
|
-
const scoresOf = (answers, id, labels) => pipe(labels, Array.map((label) => scoreOf(answers, id, label)), Option.all, Option.flatMap((scores) => Option.liftPredicate(scores, Array.isArrayNonEmpty)));
|
|
534
|
-
const probabilitiesOf = (scores) => Record.fromEntries(pipe(scores, Array.map(({ label, yes }) => [label, yes])));
|
|
535
|
-
const choiceAnswer = (choice, probabilities) => ({
|
|
536
|
-
type: "choice",
|
|
537
|
-
choice,
|
|
538
|
-
probabilities
|
|
539
|
-
});
|
|
540
|
-
const bestLabel = (scores) => choiceAnswer(Array.max(scores, byYes).label, probabilitiesOf(scores));
|
|
541
|
-
const atLeast = (scores) => pipe(scores, Array.map(({ label }, index) => ({
|
|
542
|
-
label,
|
|
543
|
-
yes: Math.max(...pipe(scores.slice(index), Array.map(({ yes }) => yes)))
|
|
544
|
-
})));
|
|
545
|
-
const severityLevel = (scores) => {
|
|
546
|
-
const cumulative = atLeast(scores);
|
|
547
|
-
const probabilities = {
|
|
548
|
-
[NO_SEVERITY]: Number$1.subtract(CERTAIN, Array.headNonEmpty(cumulative).yes),
|
|
549
|
-
...probabilitiesOf(cumulative)
|
|
550
|
-
};
|
|
551
|
-
const reached = pipe(cumulative, Array.findLast(({ yes }) => yes >= CONFIDENT));
|
|
552
|
-
return choiceAnswer(Option.match(reached, {
|
|
553
|
-
onNone: () => NO_SEVERITY,
|
|
554
|
-
onSome: ({ label }) => label
|
|
555
|
-
}), probabilities);
|
|
556
|
-
};
|
|
557
|
-
const labelsAsked = (criteria) => {
|
|
558
|
-
if (isSeverityScale(criteria)) return pipe(levelsAboveNone(criteria), Array.map(([label]) => label));
|
|
559
|
-
return Record.keys(criteria);
|
|
560
|
-
};
|
|
561
|
-
const choiceFromYesNo = (answers, [id, { criteria }]) => {
|
|
562
|
-
const collapse = Boolean.match(isSeverityScale(criteria), {
|
|
563
|
-
onTrue: () => severityLevel,
|
|
564
|
-
onFalse: () => bestLabel
|
|
565
|
-
});
|
|
566
|
-
return scoresOf(answers, id, labelsAsked(criteria)).pipe(Option.map((scores) => [id, collapse(scores)]), Option.toArray);
|
|
567
|
-
};
|
|
568
|
-
const choiceQuestionsOf = (request) => pipe(Record.toEntries(request.questions), Array.flatMap(([id, question]) => {
|
|
569
|
-
if (question.type === "choice") return [[id, question]];
|
|
570
|
-
return [];
|
|
571
|
-
}));
|
|
572
|
-
const collapseChoices = Function.dual(DATA_FIRST_ARITY$1, (request, answers) => ({
|
|
573
|
-
...answers,
|
|
574
|
-
...Record.fromEntries(pipe(choiceQuestionsOf(request), Array.flatMap((entry) => choiceFromYesNo(answers, entry))))
|
|
575
|
-
}));
|
|
576
|
-
const withChoices = Function.dual(DATA_FIRST_ARITY$1, (request, answers) => {
|
|
577
|
-
if (!isRespan(request.model)) return answers;
|
|
578
|
-
return collapseChoices(request, answers);
|
|
579
|
-
});
|
|
400
|
+
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]))));
|
|
580
401
|
// src/entities/decision/model/wire.ts
|
|
581
|
-
const DATA_FIRST_ARITY = 2;
|
|
582
402
|
const MAX_QUESTIONS = 64;
|
|
583
|
-
const sectionsOf = (name, entries) => pipe(Record.toEntries(entries), Array.map(([ref, text]) => `state.${name}.${ref}:\n${text}`));
|
|
584
|
-
const stateAsText = ({ snippets, contexts = {} }) => pipe([...sectionsOf("snippets", snippets), ...sectionsOf("contexts", contexts)], Array.join("\n\n"));
|
|
585
403
|
const only = (entries, ref) => Option.match(Option.fromUndefinedOr(entries[ref]), {
|
|
586
404
|
onNone: () => ({}),
|
|
587
405
|
onSome: (text) => ({ [ref]: text })
|
|
@@ -593,51 +411,28 @@ const stateOf = ({ snippets, contexts }, ref) => {
|
|
|
593
411
|
contexts: only(contexts, ref)
|
|
594
412
|
};
|
|
595
413
|
};
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
type: "noul",
|
|
602
|
-
instructions: `${instructions} Does the label ${optionText(label, description)} fit?`
|
|
603
|
-
});
|
|
604
|
-
const levelQuestion = (instructions, label, description) => ({
|
|
605
|
-
type: "noul",
|
|
606
|
-
instructions: `${instructions} Is it at least as serious as ${optionText(label, description)}?`
|
|
607
|
-
});
|
|
608
|
-
const yesNoQuestionsOf = (id, { instructions, criteria }) => {
|
|
609
|
-
if (isSeverityScale(criteria)) return pipe(levelsAboveNone(criteria), Array.map(([label, description]) => [optionIdOf(id, label), levelQuestion(instructions, label, description)]));
|
|
610
|
-
return pipe(Record.toEntries(criteria), Array.map(([label, description]) => [optionIdOf(id, label), labelQuestion(instructions, label, description)]));
|
|
611
|
-
};
|
|
612
|
-
const asYesNo = ([id, question]) => {
|
|
613
|
-
if (question.type === "choice") return yesNoQuestionsOf(id, question);
|
|
614
|
-
return [[id, question]];
|
|
615
|
-
};
|
|
616
|
-
const perSnippet = (wiresOf) => (request) => {
|
|
617
|
-
const bySnippet = Array.groupBy(Record.toEntries(request.questions), ([id]) => snippetRefOf(id));
|
|
618
|
-
const wires = pipe(Record.toEntries(bySnippet), Array.flatMap(([ref, questions]) => wiresOf(ref, questions)));
|
|
414
|
+
const fileRequestsFor = (request) => {
|
|
415
|
+
const wires = pipe(Array.chunksOf(Record.toEntries(request.questions), MAX_QUESTIONS), Array.map((chunk) => ({
|
|
416
|
+
...request,
|
|
417
|
+
questions: Record.fromEntries(chunk)
|
|
418
|
+
})));
|
|
619
419
|
if (Array.isReadonlyArrayNonEmpty(wires)) return wires;
|
|
620
420
|
return [request];
|
|
621
421
|
};
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
questions: Record.fromEntries(chunk)
|
|
631
|
-
}))))(request);
|
|
632
|
-
const wireRequestsFor = (request) => {
|
|
633
|
-
if (isRespan(request.model)) return yesNoRequestsFor(request);
|
|
422
|
+
const snippetRequestsFor = (request) => {
|
|
423
|
+
const bySnippet = Array.groupBy(Record.toEntries(request.questions), ([id]) => snippetRefOf(id));
|
|
424
|
+
const wires = pipe(Record.toEntries(bySnippet), Array.flatMap(([ref, questions]) => pipe(Array.chunksOf(questions, MAX_QUESTIONS), Array.map((chunk) => ({
|
|
425
|
+
model: request.model,
|
|
426
|
+
state: stateOf(request.state, ref),
|
|
427
|
+
questions: Record.fromEntries(chunk)
|
|
428
|
+
})))));
|
|
429
|
+
if (Array.isReadonlyArrayNonEmpty(wires)) return wires;
|
|
634
430
|
return [request];
|
|
635
431
|
};
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
answers:
|
|
432
|
+
const mergeResponses = (responses) => ({
|
|
433
|
+
model: Array.headNonEmpty(responses).model,
|
|
434
|
+
answers: pipe(responses, Array.flatMap(({ answers }) => Record.toEntries(answers)), Record.fromEntries)
|
|
639
435
|
});
|
|
640
|
-
|
|
641
|
-
export { contextOf as A, selectedLocation as B, checked as C, resolveOptions as D, resolveModel as E, EVERY_LINE as F, isReported as H, locates as I, locationCandidates as L, REPORT_LOC as M, TARGET_NODE_TYPES as N, isSelected as O, snippetNodeFor as P, locationOfLine as R, checkRules as S, optionsError as T, AnswerSchema as V, refAt as _, captured as a, PREFIX as b, failsInCi as c, runOrElse as d, toJson as f, parseVerdicts as g, locationRefOf as h, yesNoRequestsFor as i, lacksComment as j, commentedSnippetOf as k, messageOf as l, buildRequest as m, snippetRequestsFor as n, envNameOf as o, warnOnce as p, wireRequestsFor as r, envOf as s, mergeResponses as t, nowMs as u, truncateSnippet as v, modelIdsOf as w, STRICT as x, ModelSpecSchema as y, locationQuestion as z };
|
|
436
|
+
export { EVERY_LINE as A, checked as C, resolveOptions as D, resolveModel as E, selectedLocation as F, sourceLines as I, AnswerSchema as L, locationCandidates as M, locationOfLine as N, CLEF_MODEL as O, locationQuestion as P, isReported as R, checkRules as S, optionsError as T, snippetRefOf as _, envNameOf as a, PREFIX as b, messageOf as c, toJson as d, warnOnce as f, refAt as g, parseVerdicts as h, captured as i, locates as j, JEV_MODEL as k, nowMs as l, locationRefOf as m, mergeResponses as n, envOf as o, buildRequest as p, snippetRequestsFor as r, failsInCi as s, fileRequestsFor as t, runOrElse as u, truncateSnippet as v, modelIdsOf as w, STRICT as x, ModelSpecSchema as y };
|
|
642
437
|
|
|
643
|
-
//# sourceMappingURL=
|
|
438
|
+
//# sourceMappingURL=wire-CKpt_MBX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wire-CKpt_MBX.mjs","names":["Arr","Rec","DATA_FIRST_ARITY","Rec","Fn","DATA_FIRST_ARITY","DATA_FIRST_ARITY_3","FIRST_LINE","Str","Num","Bool","Arr","Fn","Rec","DATA_FIRST_ARITY","Arr","Str","Fn","Rec","DATA_FIRST_ARITY","Bool","Str","Num","Fn","Arr","Rec","Fn","Str","Arr","Rec"],"sources":["../src/entities/decision/model/schema.ts","../src/entities/decision/model/answer.ts","../src/entities/decision/model/location.ts","../src/entities/decision/model/models.ts","../src/entities/decision/model/options.ts","../src/entities/decision/model/request.ts","../src/entities/decision/model/runtime.ts","../src/entities/decision/model/wire.ts"],"sourcesContent":["import { Schema, Array as Arr, Record as Rec, pipe } from \"effect\";\n\nconst NONE = 0;\nconst MINIMUM_LABELS = 2;\n\nconst NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(NONE));\n\nexport const Probability = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 1 }));\n\nexport const CONFIDENT = 0.8;\n\nexport const Cutoff = Schema.Finite.check(\n Schema.isBetween(\n { minimum: CONFIDENT, maximum: 1 },\n { message: `cutoff must be between ${CONFIDENT} and 1` },\n ),\n);\n\nexport const TargetSchema = Schema.Literals([\"function\", \"call\", \"jsx\", \"file\"]);\n\nexport const CiBehaviorSchema = Schema.Literals([\"skip\", \"fail\"]);\n\nexport const ExplainSettingSchema = Schema.Union([\n Schema.Boolean,\n Schema.Literals([\"text\", \"json\"]),\n]);\n\nexport const EnclosingKindSchema = Schema.Literals([\"function\", \"class\", \"block\"]);\n\nexport const RuleContextSchema = Schema.Union([\n Schema.Struct({ scope: Schema.Literals([\"node\", \"file\", \"comment\"]) }),\n Schema.Struct({\n scope: Schema.Literal(\"lines\"),\n before: Schema.optionalKey(NonNegativeInt),\n after: Schema.optionalKey(NonNegativeInt),\n }),\n Schema.Struct({ scope: Schema.Literal(\"enclosing\"), kind: EnclosingKindSchema }),\n]);\n\nexport const SeveritySchema = Schema.Literals([\"info\", \"warn\", \"error\"]);\n\nconst Label = Schema.NonEmptyString;\n\nconst BooleanAnswer = Schema.Struct({ kind: Schema.Literal(\"boolean\") });\n\nconst ClassifyAnswer = Schema.Struct({\n kind: Schema.Literal(\"classify\"),\n labels: Schema.Record(Label, Schema.String).check(Schema.isMinProperties(MINIMUM_LABELS)),\n report: Schema.NonEmptyArray(Label),\n}).check(\n Schema.makeFilter(\n ({ labels, report }) =>\n pipe(\n report,\n Arr.every((label) => Rec.has(labels, label)),\n ),\n {\n message: \"every label in report must be one of labels\",\n },\n ),\n);\n\nconst SeverityAnswer = Schema.Struct({\n kind: Schema.Literal(\"severity\"),\n minimum: Schema.optionalKey(SeveritySchema),\n});\n\nexport const RuleAnswerSchema = Schema.Union([BooleanAnswer, ClassifyAnswer, SeverityAnswer]);\n","import { Option, Result, Schema, Record as Rec, Function as Fn } from \"effect\";\n\nimport { Probability, RuleAnswerSchema } from \"./schema.ts\";\nimport type {\n Answer,\n ChoiceAnswer,\n NoulAnswer,\n Question,\n RuleAnswer,\n Severity,\n Verdict,\n} from \"./types.ts\";\n\nconst DATA_FIRST_ARITY = 2;\n\nconst YES = \"yes\";\nconst DEFAULT_MINIMUM: Severity = \"warn\";\n\nconst SEVERITY_CRITERIA = {\n none: \"No problem\",\n info: \"Worth noting, but not a problem\",\n warn: \"Likely a problem\",\n error: \"Clearly a problem\",\n} as const;\n\nexport const SEVERITY_ORDER: readonly string[] = Rec.keys(SEVERITY_CRITERIA);\n\nexport const BOOLEAN_ANSWER: RuleAnswer = { kind: \"boolean\" };\n\nconst decodeAnswer = Schema.decodeUnknownResult(RuleAnswerSchema);\n\nexport const decodeRuleAnswer = (answer: unknown): Result.Result<RuleAnswer, string> => {\n const decoded = decodeAnswer(answer);\n if (Result.isSuccess(decoded)) {\n return Result.succeed(decoded.success);\n }\n return Result.fail(decoded.failure.message);\n};\n\nconst NoulAnswerSchema = Schema.Struct({ type: Schema.Literal(\"noul\"), noul: Probability });\n\nconst ChoiceAnswerSchema = Schema.Struct({\n type: Schema.Literal(\"choice\"),\n choice: Schema.String,\n probabilities: Schema.optional(Schema.Record(Schema.String, Probability)),\n} satisfies Partial<Record<keyof ChoiceAnswer, Schema.Top>>);\n\nexport const AnswerSchema = Schema.Union([NoulAnswerSchema, ChoiceAnswerSchema]);\n\nconst decodeNoul = Schema.decodeOption(NoulAnswerSchema);\n\nconst decodeChoice = Schema.decodeOption(ChoiceAnswerSchema);\n\nconst isNoul = (answer: Answer): answer is NoulAnswer => answer.type === \"noul\";\n\nconst isChoice = (answer: Answer): answer is ChoiceAnswer => answer.type === \"choice\";\n\nexport const noulOf = (answer: Answer | undefined): Option.Option<NoulAnswer> =>\n Option.fromUndefinedOr(answer).pipe(Option.filter(isNoul), Option.flatMap(decodeNoul));\n\nexport const choiceOf = (answer: Answer | undefined): Option.Option<ChoiceAnswer> =>\n Option.fromUndefinedOr(answer).pipe(Option.filter(isChoice), Option.flatMap(decodeChoice));\n\nexport const probabilityOfChoice = ({\n choice,\n probabilities,\n}: ChoiceAnswer): Option.Option<number> =>\n Option.fromUndefinedOr(probabilities).pipe(\n Option.flatMap((byLabel) => Option.fromUndefinedOr(byLabel[choice])),\n );\n\nexport const questionFor: {\n (instructions: string): (answer: RuleAnswer) => Question;\n (answer: RuleAnswer, instructions: string): Question;\n} = Fn.dual(DATA_FIRST_ARITY, (answer: RuleAnswer, instructions: string): Question => {\n switch (answer.kind) {\n case \"classify\": {\n return {\n type: \"choice\",\n instructions: `${instructions} Select the label that fits best.`,\n criteria: answer.labels,\n };\n }\n case \"severity\": {\n return {\n type: \"choice\",\n instructions: `${instructions} Rate how serious the problem is, and select none if there is no problem.`,\n criteria: SEVERITY_CRITERIA,\n };\n }\n case \"boolean\": {\n return { type: \"noul\", instructions };\n }\n default: {\n return { type: \"noul\", instructions };\n }\n }\n});\n\nconst choiceVerdictOf = (\n criteria: Readonly<Record<string, unknown>>,\n answer: Answer | undefined,\n): Option.Option<Verdict> =>\n choiceOf(answer).pipe(\n Option.filter(({ choice }) => Rec.has(criteria, choice)),\n Option.flatMap((chosen) =>\n Option.map(probabilityOfChoice(chosen), (probability) => ({\n answer: chosen.choice,\n probability,\n })),\n ),\n );\n\nexport const verdictOf: {\n (answer: Answer | undefined): (question: Question) => Option.Option<Verdict>;\n (question: Question, answer: Answer | undefined): Option.Option<Verdict>;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (question: Question, answer: Answer | undefined): Option.Option<Verdict> => {\n if (question.type === \"choice\") {\n return choiceVerdictOf(question.criteria, answer);\n }\n return noulOf(answer).pipe(Option.map(({ noul }) => ({ answer: YES, probability: noul })));\n },\n);\n\nconst severityMatches = (\n { minimum = DEFAULT_MINIMUM }: { readonly minimum?: Severity },\n label: string,\n): boolean => SEVERITY_ORDER.indexOf(label) >= SEVERITY_ORDER.indexOf(minimum);\n\nconst answerMatches = (answer: RuleAnswer, label: string): boolean => {\n switch (answer.kind) {\n case \"classify\": {\n return answer.report.includes(label);\n }\n case \"severity\": {\n return severityMatches(answer, label);\n }\n case \"boolean\": {\n return label === YES;\n }\n default: {\n return false;\n }\n }\n};\n\nexport const isReported: {\n (verdict: Verdict): (rule: { readonly answer: RuleAnswer; readonly cutoff: number }) => boolean;\n (rule: { readonly answer: RuleAnswer; readonly cutoff: number }, verdict: Verdict): boolean;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (rule: { readonly answer: RuleAnswer; readonly cutoff: number }, verdict: Verdict): boolean =>\n verdict.probability >= rule.cutoff && answerMatches(rule.answer, verdict.answer),\n);\n","import 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 Record as Rec,\n pipe,\n Function as Fn,\n} from \"effect\";\n\nimport { choiceOf, probabilityOfChoice } from \"./answer.ts\";\nimport type { Answer, ChoiceQuestion, LineRange, RequestMatch, RuleLocation } from \"./types.ts\";\n\nconst DATA_FIRST_ARITY = 2;\nconst DATA_FIRST_ARITY_3 = 3;\nconst CHOICE_OPTION_LIMIT = 254;\nconst FIRST_LINE = 1;\nconst MINIMUM_WIDTH = 1;\nconst UNKNOWN_CHOICE = \"unknown\";\n\nexport const sourceLines = (text: string): readonly string[] =>\n Str.split(text, /\\r\\n|[\\n\\r\\u2028\\u2029]/u);\n\nexport type LocatedMatch = RequestMatch & {\n readonly rule: { readonly question: string; readonly location: RuleLocation };\n};\n\nexport const locates = (match: RequestMatch): match is LocatedMatch =>\n Predicate.isNotUndefined(match.rule.location) && !match.truncated;\n\nexport interface NumberedLine {\n readonly text: string;\n readonly line: number;\n}\n\nexport const 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\nexport const numberedLines = (snippet: string): readonly NumberedLine[] =>\n pipe(\n sourceLines(snippet),\n Arr.map((text, index) => ({ text, line: Num.sum(index, FIRST_LINE) })),\n );\n\nexport const locationCandidates: {\n (within: LineRange): (snippet: string) => Readonly<Record<string, LineRange>>;\n (snippet: string, within: LineRange): Readonly<Record<string, LineRange>>;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (snippet: string, within: LineRange): Readonly<Record<string, LineRange>> => {\n const lines = pipe(\n numberedLines(snippet),\n Arr.filter(({ text, line }) => Str.trim(text).length >= FIRST_LINE && isWithin(line, within)),\n );\n const width = Math.max(MINIMUM_WIDTH, Math.ceil(lines.length / CHOICE_OPTION_LIMIT));\n return Rec.fromEntries(\n pipe(\n Arr.chunksOf(lines, width),\n Arr.map((group) => {\n const range = rangeOf(group);\n return [rangeKey(range), range];\n }),\n ),\n );\n },\n);\n\nexport const locationQuestion: {\n (\n ref: string,\n candidates: Readonly<Record<string, LineRange>>,\n ): (match: LocatedMatch) => ChoiceQuestion;\n (\n match: LocatedMatch,\n ref: string,\n candidates: Readonly<Record<string, LineRange>>,\n ): ChoiceQuestion;\n} = Fn.dual(\n DATA_FIRST_ARITY_3,\n (\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 ...Rec.fromEntries(\n pipe(\n Rec.toEntries(candidates),\n Arr.map(([key, range]) => [key, rangeLabel(range)]),\n ),\n ),\n [UNKNOWN_CHOICE]: \"No clear source location for this violation\",\n },\n }),\n);\n\nexport type ChoiceCriteria = ChoiceQuestion[\"criteria\"];\n\nexport const validChoice: {\n (criteria: ChoiceCriteria): (answer: Answer | undefined) => boolean;\n (answer: Answer | undefined, criteria: ChoiceCriteria): boolean;\n} = Fn.dual(DATA_FIRST_ARITY, (answer: Answer | undefined, criteria: ChoiceCriteria): boolean =>\n Option.exists(\n choiceOf(answer),\n (chosen) => Rec.has(criteria, chosen.choice) && Option.isSome(probabilityOfChoice(chosen)),\n ),\n);\n\nexport const selectedLocation: {\n (\n candidates: Readonly<Record<string, LineRange>>,\n cutoff: number,\n ): (answer: Answer | undefined) => Option.Option<LineRange>;\n (\n answer: Answer | undefined,\n candidates: Readonly<Record<string, LineRange>>,\n cutoff: number,\n ): Option.Option<LineRange>;\n} = Fn.dual(\n DATA_FIRST_ARITY_3,\n (\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);\n\nexport const locationOfLine: {\n (line: number): (snippet: string) => Location;\n (snippet: string, line: number): Location;\n} = Fn.dual(DATA_FIRST_ARITY, (snippet: string, line: number): Location => {\n const text = Option.getOrElse(Arr.get(sourceLines(snippet), Num.decrement(line)), () => \"\");\n return {\n start: {\n line,\n column: Option.getOrElse(Str.search(/\\S/u)(text), () => Num.decrement(FIRST_LINE)),\n },\n end: { line, column: Str.trimEnd(text).length },\n };\n});\n","import { Schema } from \"effect\";\n\nexport type DecisionModel =\n | \"typesafe/jev-latest\"\n | `typesafe/jev-${number}.${number}`\n | \"cloudflare/@cf/cloudflare/clef\"\n | \"cloudflare/@cf/cloudflare/clef-flash\"\n | \"cloudflare/@cf/cloudflare/clef-omni\";\n\nexport const JEV_MODEL = /^jev-(?:latest|\\d+\\.\\d+)$/u;\n\nexport const CLEF_MODEL = /^@cf\\/cloudflare\\/clef(?:-flash|-omni)?$/u;\n\nconst DECISION_MODEL =\n /^(?:typesafe\\/jev-(?:latest|\\d+\\.\\d+)|cloudflare\\/@cf\\/cloudflare\\/clef(?:-flash|-omni)?)$/u;\n\nconst isDecisionModel = (model: string): model is DecisionModel => DECISION_MODEL.test(model);\n\nexport const DecisionModelSchema = Schema.String.pipe(\n Schema.refine(isDecisionModel, {\n message:\n 'model must be a decision model: \"typesafe/jev-latest\", \"typesafe/jev-<major>.<minor>\", or \"cloudflare/@cf/cloudflare/clef\", \"clef-flash\" or \"clef-omni\"',\n }),\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 { DecisionModelSchema } from \"./models.ts\";\nimport type { DecisionModel } from \"./models.ts\";\nimport {\n CiBehaviorSchema,\n Cutoff,\n ExplainSettingSchema,\n RuleContextSchema,\n TargetSchema,\n} from \"./schema.ts\";\nimport type {\n DecisionOptions,\n DecisionProvider,\n DecisionRule,\n ModelRef,\n ModelSpec,\n ResolvedOptions,\n ResolvedRule,\n RuleAnswer,\n} from \"./types.ts\";\n\nconst DATA_FIRST_ARITY_3 = 3;\n\nconst DATA_FIRST_ARITY = 2;\n\nexport const PREFIX = \"oxlint-plugin-decision\";\nconst PROVIDER_SEPARATOR = \"/\";\nconst ONE_RULE = 1;\n\nconst DEFAULTS = {\n ci: \"fail\",\n timeoutMs: 10_000,\n maxSnippetChars: 4000,\n model: \"cloudflare/@cf/cloudflare/clef-flash\",\n env: {},\n explain: false,\n} as const satisfies Required<DecisionOptions>;\n\nconst isSelector = (input: unknown): input is DecisionRule[\"select\"] => Predicate.isFunction(input);\n\nconst RULE_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;\n\nexport const ModelSpecSchema = Schema.Union([\n DecisionModelSchema,\n Schema.NonEmptyArray(DecisionModelSchema),\n]);\n\nconst ONE = 1;\n\nconst PositiveInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(ONE));\n\nconst RuleId = Schema.NonEmptyString.check(\n Schema.isPattern(RULE_ID, { message: \"id must be lowercase words joined by hyphens\" }),\n);\n\nconst OptionsSchema = Schema.Struct({\n ci: Schema.optionalKey(CiBehaviorSchema),\n timeoutMs: Schema.optionalKey(PositiveInt),\n maxSnippetChars: Schema.optionalKey(PositiveInt),\n model: Schema.optionalKey(ModelSpecSchema),\n env: Schema.optionalKey(Schema.Record(Schema.NonEmptyString, Schema.NonEmptyString)),\n explain: Schema.optionalKey(ExplainSettingSchema),\n});\n\nconst RuleSchema = Schema.Struct({\n id: RuleId,\n target: TargetSchema,\n question: Schema.NonEmptyString,\n cutoff: Cutoff,\n message: Schema.optionalKey(Schema.NonEmptyString),\n select: Schema.optionalKey(Schema.declare(isSelector)),\n location: Schema.optionalKey(Schema.Struct({ question: Schema.NonEmptyString, cutoff: Cutoff })),\n model: Schema.optionalKey(ModelSpecSchema),\n context: Schema.optionalKey(RuleContextSchema),\n answer: Schema.optionalKey(Schema.Unknown),\n});\n\nexport const STRICT = { onExcessProperty: \"error\" } as const;\n\nconst decodeOptions = Schema.decodeUnknownResult(OptionsSchema, STRICT);\nconst decodeRule = Schema.decodeUnknownResult(RuleSchema, STRICT);\n\nconst taggedError = Schema.TaggedError;\n\nclass OptionsError extends taggedError<OptionsError, { readonly brand: unique symbol }>()(\n \"OptionsError\",\n { message: Schema.String },\n) {}\n\nexport const optionsError = (message: string): Error =>\n OptionsError.make({ message: `${PREFIX}: ${message}` });\n\nexport const modelIdsOf = (spec: ModelSpec): readonly DecisionModel[] =>\n 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 acceptedModel = (ref: ModelRef): ModelRef => {\n const { models, name } = ref.provider;\n if (!models.test(ref.model)) {\n throw optionsError(\n `model \"${ref.id}\" is not a decision model that the \"${name}\" provider accepts`,\n );\n }\n return ref;\n};\n\nexport const resolveModel: {\n (providers: Readonly<Record<string, DecisionProvider>>): (id: string) => ModelRef;\n (id: string, providers: Readonly<Record<string, DecisionProvider>>): ModelRef;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (id: string, providers: Readonly<Record<string, DecisionProvider>>): ModelRef =>\n acceptedModel(\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\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);\n\nconst duplicateIdOf = (rules: readonly DecisionRule[]): Option.Option<string> =>\n Arr.findFirst(\n Rec.toEntries(Arr.groupBy(rules, ({ id }) => id)),\n ([, same]) => same.length > ONE_RULE,\n ).pipe(Option.map(([id]) => id));\n\nconst answerOf = (rule: DecisionRule): RuleAnswer => {\n if (Predicate.isUndefined(rule.answer)) {\n return BOOLEAN_ANSWER;\n }\n return Result.getOrThrowWith(decodeRuleAnswer(rule.answer), (issue) =>\n optionsError(`rule \"${rule.id}\" has an invalid answer: ${issue}`),\n );\n};\n\nexport type Decode<Value> = (input: unknown) => Result.Result<Value, Schema.SchemaError>;\n\nexport const checked: {\n (input: unknown, what: string): <Value>(decode: Decode<Value>) => Value;\n <Value>(decode: Decode<Value>, input: unknown, what: string): Value;\n} = Fn.dual(\n DATA_FIRST_ARITY_3,\n <Value>(decode: Decode<Value>, input: unknown, what: string): Value =>\n Result.getOrThrowWith(decode(input), (issue) =>\n optionsError(`invalid ${what}: ${issue.message}`),\n ),\n);\n\nconst checkRule = (rule: DecisionRule): DecisionRule => {\n checked(decodeRule, rule, `rule \"${rule.id}\"`);\n if (Predicate.isNotUndefined(rule.location) && rule.target !== \"file\") {\n throw optionsError(\"location is supported only for file rules\");\n }\n answerOf(rule);\n return rule;\n};\n\nexport const checkRules = (rules: readonly DecisionRule[]): readonly DecisionRule[] => {\n if (!Arr.isReadonlyArrayNonEmpty(rules)) {\n throw optionsError(\"rules must list at least one rule\");\n }\n Option.map(duplicateIdOf(rules), (duplicate) => {\n throw optionsError(`rule id \"${duplicate}\" is used more than once`);\n });\n return pipe(\n rules,\n Arr.map((rule) => checkRule(rule)),\n );\n};\n\nconst resolveRule =\n (fallback: ModelSpec, providers: Readonly<Record<string, DecisionProvider>>) =>\n (rule: DecisionRule): ResolvedRule => ({\n ...rule,\n answer: answerOf(rule),\n models: pipe(\n modelIdsOf(rule.model ?? fallback),\n Arr.map((id) => resolveModel(id, providers)),\n ),\n });\n\nexport interface Sources {\n readonly options: DecisionOptions;\n readonly settings?: unknown;\n}\n\nconst settingsFrom = (settings: unknown): DecisionOptions => {\n if (Predicate.isUndefined(settings)) {\n return {};\n }\n return checked(decodeOptions, settings, \"settings\");\n};\n\nexport const resolveOptions: {\n (\n rules: readonly DecisionRule[],\n providers: Readonly<Record<string, DecisionProvider>>,\n ): (sources: Sources) => ResolvedOptions;\n (\n sources: Sources,\n rules: readonly DecisionRule[],\n providers: Readonly<Record<string, DecisionProvider>>,\n ): ResolvedOptions;\n} = Fn.dual(\n DATA_FIRST_ARITY_3,\n (\n { options, settings }: Sources,\n rules: readonly DecisionRule[],\n providers: Readonly<Record<string, DecisionProvider>>,\n ): ResolvedOptions => {\n const fromCode = checked(decodeOptions, options, \"createDecisionPlugin options\");\n const { model, ...merged } = { ...DEFAULTS, ...fromCode, ...settingsFrom(settings) };\n return {\n ci: merged.ci,\n timeoutMs: merged.timeoutMs,\n maxSnippetChars: merged.maxSnippetChars,\n env: merged.env,\n explain: merged.explain,\n rules: pipe(\n checkRules(rules),\n Arr.map((rule) => resolveRule(model, providers)(rule)),\n ),\n };\n },\n);\n","import {\n Array as Arr,\n Boolean as Bool,\n Number as Num,\n Option,\n Predicate,\n String as Str,\n Record as Rec,\n pipe,\n Function as Fn,\n} from \"effect\";\n\nimport { questionFor, verdictOf } from \"./answer.ts\";\nimport {\n EVERY_LINE,\n locates,\n locationCandidates,\n locationQuestion,\n numberedLines,\n validChoice,\n} from \"./location.ts\";\nimport type { ChoiceCriteria } from \"./location.ts\";\nimport type {\n Answers,\n DecisionRequest,\n DecisionResponse,\n Question,\n RequestMatch,\n Verdict,\n Verdicts,\n} from \"./types.ts\";\n\nconst DATA_FIRST_ARITY = 2;\n\nconst FIRST_LINE = 1;\nconst LOCATION_SUFFIX = \"_location\";\nconst TRUNCATION_MARKER = \"/* ...truncated */\";\n\nexport const refAt = (index: number): string => `s${String(index)}`;\n\nexport const locationRefOf = (ref: string): string => `${ref}${LOCATION_SUFFIX}`;\n\nexport const snippetRefOf = (questionId: string): string =>\n Bool.match(Str.endsWith(LOCATION_SUFFIX)(questionId), {\n onTrue: () => Str.slice(Num.decrement(FIRST_LINE), -LOCATION_SUFFIX.length)(questionId),\n onFalse: () => questionId,\n });\n\nexport const truncateSnippet: {\n (maxChars: number): (text: string) => string;\n (text: string, maxChars: number): string;\n} = Fn.dual(DATA_FIRST_ARITY, (text: string, maxChars: number): string =>\n Bool.match(text.length <= maxChars, {\n onTrue: () => text,\n onFalse: () => `${Str.slice(Num.decrement(FIRST_LINE), maxChars)(text)}${TRUNCATION_MARKER}`,\n }),\n);\n\nconst numbered = (snippet: string): string =>\n pipe(\n numberedLines(snippet),\n Arr.map(({ text, line }) => `L${String(line)}| ${text}`),\n Arr.join(\"\\n\"),\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 [\n locationRefOf(ref),\n locationQuestion(match, ref, locationCandidates(match.snippet, EVERY_LINE)),\n ],\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 = pipe(\n matches,\n Arr.flatMap((match, index) =>\n Option.toArray(\n Option.map(Option.fromUndefinedOr(match.context), (text) => [refAt(index), text] as const),\n ),\n ),\n );\n if (Arr.isReadonlyArrayEmpty(contexts)) {\n return {};\n }\n return { contexts: Rec.fromEntries(contexts) };\n};\n\nexport const buildRequest: {\n (matches: readonly RequestMatch[]): (model: string) => DecisionRequest;\n (model: string, matches: readonly RequestMatch[]): DecisionRequest;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (model: string, matches: readonly RequestMatch[]): DecisionRequest => ({\n model,\n state: {\n snippets: Rec.fromEntries(\n pipe(\n matches,\n Arr.map((match, index) => [refAt(index), snippetFor(match)]),\n ),\n ),\n ...contextsOf(matches),\n },\n questions: Rec.fromEntries(\n pipe(\n matches,\n Arr.flatMap((match, index) => questionsFor(match, refAt(index))),\n ),\n ),\n }),\n);\n\nconst choiceQuestionsOf = (\n request: DecisionRequest,\n): readonly (readonly [string, ChoiceCriteria])[] =>\n pipe(\n Rec.toEntries(request.questions),\n Arr.flatMap(([id, question]) => {\n if (question.type === \"choice\") {\n return [[id, question.criteria] as const];\n }\n return [];\n }),\n );\n\nconst mainQuestionsOf = (request: DecisionRequest): readonly (readonly [string, Question])[] =>\n pipe(\n Rec.toEntries(request.questions),\n Arr.filter(([id]) => !Str.endsWith(LOCATION_SUFFIX)(id)),\n );\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\nexport const parseVerdicts: {\n (request: DecisionRequest): (response: DecisionResponse) => Verdicts;\n (response: DecisionResponse, request: DecisionRequest): Verdicts;\n} = Fn.dual(DATA_FIRST_ARITY, (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 = Rec.fromEntries(\n pipe(\n mainQuestionsOf(request),\n Arr.map((entry) => resultOf(answers, entry)),\n ),\n );\n const complete = pipe(\n choiceQuestionsOf(request),\n Arr.every(([id, criteria]) => validChoice(answers[id], criteria)),\n );\n return { model, results, answers, complete };\n});\n","import {\n Cause,\n DateTime,\n Config,\n Console,\n Effect,\n Exit,\n Option,\n Schema,\n String as Str,\n Function as Fn,\n} from \"effect\";\n\nimport { PREFIX } from \"./options.ts\";\nimport type { ResolvedOptions } from \"./types.ts\";\n\nconst DATA_FIRST_ARITY = 2;\n\nconst encodeJson = Schema.encodeUnknownOption(Schema.fromJsonString(Schema.Unknown));\n\nexport const toJson = (value: unknown): string =>\n Option.getOrElse(encodeJson(value), () => String(value));\n\nexport const nowMs = (): number => DateTime.toEpochMillis(DateTime.nowUnsafe());\n\nexport const runOrElse: {\n <Value>(\n fallback: (error: unknown) => Value,\n ): <Failure>(effect: Effect.Effect<Value, Failure>) => Value;\n <Value, Failure>(\n effect: Effect.Effect<Value, Failure>,\n fallback: (error: unknown) => Value,\n ): Value;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n <Value, Failure>(\n effect: Effect.Effect<Value, Failure>,\n fallback: (error: unknown) => Value,\n ): Value =>\n Exit.match(Effect.runSyncExit(effect), {\n onSuccess: (value) => value,\n onFailure: (cause) => fallback(Cause.squash(cause)),\n }),\n);\n\nexport const envOf = (name: string): Option.Option<string> =>\n runOrElse(Config.option(Config.NonEmptyString(name)), () => Option.none()).pipe(\n Option.map((value) => Str.trim(value)),\n Option.filter(Str.isNonEmpty),\n );\n\nexport const envNameOf: {\n (name: string): (env: Readonly<Record<string, string>>) => string;\n (env: Readonly<Record<string, string>>, name: string): string;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (env: Readonly<Record<string, string>>, name: string): string => env[name] ?? name,\n);\n\nexport const failsInCi = (options: ResolvedOptions): boolean =>\n options.ci === \"fail\" && Option.isSome(envOf(\"CI\"));\n\nconst warned = new Set<string>();\n\nexport const warnOnce: {\n (message: string): (reason: string) => void;\n (reason: string, message: string): void;\n} = Fn.dual(DATA_FIRST_ARITY, (reason: string, message: string): void => {\n if (warned.has(reason)) {\n return;\n }\n warned.add(reason);\n Effect.runFork(Console.warn(`${PREFIX}: ${message}`));\n});\n\nexport const messageOf = (error: unknown): string => {\n if (error instanceof Error) {\n return error.message;\n }\n return String(error);\n};\n\nexport const captured: {\n (name: string): (match: Option.Option<RegExpMatchArray>) => Option.Option<string>;\n (match: Option.Option<RegExpMatchArray>, name: string): Option.Option<string>;\n} = Fn.dual(\n DATA_FIRST_ARITY,\n (match: Option.Option<RegExpMatchArray>, name: string): Option.Option<string> =>\n match.pipe(\n Option.flatMap((found) => Option.fromNullishOr(found.groups)),\n Option.flatMap((groups) => Option.fromNullishOr(groups[name])),\n ),\n);\n","import { Array as Arr, Option, Predicate, pipe, Record as Rec } from \"effect\";\n\nimport { snippetRefOf } from \"./request.ts\";\nimport type { DecisionRequest, DecisionResponse, Question } from \"./types.ts\";\n\nconst MAX_QUESTIONS = 64;\n\ntype State = DecisionRequest[\"state\"];\n\nexport interface WireRequest extends Readonly<Pick<DecisionRequest, \"model\" | \"state\">> {\n readonly questions: Readonly<Record<string, Question>>;\n}\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\nexport const fileRequestsFor = (\n request: DecisionRequest,\n): Arr.NonEmptyReadonlyArray<WireRequest> => {\n const wires = pipe(\n Arr.chunksOf(Rec.toEntries(request.questions), MAX_QUESTIONS),\n Arr.map((chunk): WireRequest => ({ ...request, questions: Rec.fromEntries(chunk) })),\n );\n if (Arr.isReadonlyArrayNonEmpty(wires)) {\n return wires;\n }\n return [request];\n};\n\nexport const snippetRequestsFor = (\n request: DecisionRequest,\n): Arr.NonEmptyReadonlyArray<WireRequest> => {\n const bySnippet = Arr.groupBy(Rec.toEntries(request.questions), ([id]) => snippetRefOf(id));\n const wires = pipe(\n Rec.toEntries(bySnippet),\n Arr.flatMap(([ref, questions]) =>\n pipe(\n Arr.chunksOf(questions, MAX_QUESTIONS),\n Arr.map((chunk): WireRequest => ({\n model: request.model,\n state: stateOf(request.state, ref),\n questions: Rec.fromEntries(chunk),\n })),\n ),\n ),\n );\n if (Arr.isReadonlyArrayNonEmpty(wires)) {\n return wires;\n }\n return [request];\n};\n\nexport const mergeResponses = (\n responses: Arr.NonEmptyReadonlyArray<DecisionResponse>,\n): DecisionResponse => ({\n model: Arr.headNonEmpty(responses).model,\n answers: pipe(\n responses,\n Arr.flatMap(({ answers }) => Rec.toEntries(answers)),\n Rec.fromEntries,\n ),\n});\n"],"mappings":";;AAEA,MAAM,OAAO;AACb,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB,OAAO,IAAI,MAAM,OAAO,uBAAuB,IAAI,CAAC;AAE3E,MAAa,cAAc,OAAO,OAAO,MAAM,OAAO,UAAU;CAAE,SAAS;CAAG,SAAS;AAAE,CAAC,CAAC;AAE3F,MAAa,YAAY;AAEzB,MAAa,SAAS,OAAO,OAAO,MAClC,OAAO,UACL;CAAE,SAAS;CAAW,SAAS;AAAE,GACjC,EAAE,SAAS,0BAA0B,UAAU,QAAQ,CACzD,CACF;AAEA,MAAa,eAAe,OAAO,SAAS;CAAC;CAAY;CAAQ;CAAO;AAAM,CAAC;AAE/E,MAAa,mBAAmB,OAAO,SAAS,CAAC,QAAQ,MAAM,CAAC;AAEhE,MAAa,uBAAuB,OAAO,MAAM,CAC/C,OAAO,SACP,OAAO,SAAS,CAAC,QAAQ,MAAM,CAAC,CAClC,CAAC;AAED,MAAa,sBAAsB,OAAO,SAAS;CAAC;CAAY;CAAS;AAAO,CAAC;AAEjF,MAAa,oBAAoB,OAAO,MAAM;CAC5C,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,MAAa,iBAAiB,OAAO,SAAS;CAAC;CAAQ;CAAQ;AAAO,CAAC;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