@r_masseater/oxlint-plugin-decision 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +23 -395
  2. package/dist/app-Bso1uwY5.mjs +662 -0
  3. package/dist/app-Bso1uwY5.mjs.map +1 -0
  4. package/dist/cloudflare-worker.mjs +6 -179
  5. package/dist/cloudflare-worker.mjs.map +1 -1
  6. package/dist/decision-BtTZ52be.mjs +643 -0
  7. package/dist/decision-BtTZ52be.mjs.map +1 -0
  8. package/dist/define-presets-clyqLZxo.mjs +550 -0
  9. package/dist/define-presets-clyqLZxo.mjs.map +1 -0
  10. package/dist/index-BOrpK3Iv.d.mts +89 -0
  11. package/dist/index-Cgg-w0hb.d.mts +3370 -0
  12. package/dist/index-D7VrRpTx.d.mts +6 -0
  13. package/dist/index.d.mts +3 -3372
  14. package/dist/index.mjs +1 -786
  15. package/dist/openrouter-app.d.mts +12 -4
  16. package/dist/openrouter-app.mjs +1 -87
  17. package/dist/openrouter-worker.mjs +5 -35
  18. package/dist/openrouter-worker.mjs.map +1 -1
  19. package/dist/preset-plugin-AAwedMeS.mjs +10 -0
  20. package/dist/preset-plugin-AAwedMeS.mjs.map +1 -0
  21. package/dist/presets/ai-slop.d.mts +6 -0
  22. package/dist/presets/ai-slop.mjs +10 -0
  23. package/dist/presets/ai-slop.mjs.map +1 -0
  24. package/dist/presets/index.d.mts +3 -0
  25. package/dist/presets/index.mjs +3 -0
  26. package/dist/presets/recommended.d.mts +5 -0
  27. package/dist/presets/recommended.mjs +7 -0
  28. package/dist/presets/recommended.mjs.map +1 -0
  29. package/dist/presets/review-only.d.mts +5 -0
  30. package/dist/presets/review-only.mjs +7 -0
  31. package/dist/presets/review-only.mjs.map +1 -0
  32. package/dist/presets/strict.d.mts +5 -0
  33. package/dist/presets/strict.mjs +7 -0
  34. package/dist/presets/strict.mjs.map +1 -0
  35. package/dist/serve-decisions-CjlhvYm7.mjs +290 -0
  36. package/dist/serve-decisions-CjlhvYm7.mjs.map +1 -0
  37. package/package.json +25 -3
  38. package/skills/write-decision-rules/SKILL.md +18 -17
  39. package/skills/write-decision-rules/references/tuning.md +1 -1
  40. package/dist/index.mjs.map +0 -1
  41. package/dist/openrouter-app.mjs.map +0 -1
  42. package/dist/runtime-CICpEidL.mjs +0 -271
  43. package/dist/runtime-CICpEidL.mjs.map +0 -1
  44. package/dist/serve-decisions-cQpGj_Fq.mjs +0 -112
  45. package/dist/serve-decisions-cQpGj_Fq.mjs.map +0 -1
  46. package/dist/wire-CRD1mSAo.mjs +0 -251
  47. package/dist/wire-CRD1mSAo.mjs.map +0 -1
@@ -1,11 +1,19 @@
1
- import { Effect, FileSystem, Path } from "effect";
1
+ import "./index-Cgg-w0hb.mjs";
2
+ import { Array, Config, Effect, FileSystem, Option, Path, Schema } from "effect";
3
+ import { HttpClient } from "effect/http";
4
+ import { Digest } from "effect/crypto";
5
+ /** @internal */
2
6
  type AppServices = FileSystem.FileSystem | Path.Path;
7
+ /** @internal */
3
8
  interface AppContext {
4
9
  readonly repo: string;
5
10
  readonly context: string;
6
11
  }
7
- declare const appContext: Effect.Effect<AppContext, never, AppServices>;
12
+ /** @internal */
13
+ export declare const appContext: Effect.Effect<AppContext, never, AppServices>;
14
+ /** @internal */
8
15
  type OpenRouterApp = Readonly<Record<"HTTP-Referer" | "X-OpenRouter-Title" | "X-OpenRouter-App-Visibility", string>>;
9
- declare const openRouterApp: (tool: string) => Effect.Effect<OpenRouterApp, never, AppServices>;
10
- export { type AppContext, type AppServices, type OpenRouterApp, appContext, openRouterApp };
16
+ /** @internal */
17
+ export declare const openRouterApp: (tool: string) => Effect.Effect<OpenRouterApp, never, AppServices>;
18
+ export type { AppContext, AppServices, OpenRouterApp };
11
19
  //# sourceMappingURL=openrouter-app.d.mts.map
@@ -1,87 +1 @@
1
- import { t as captured } from "./runtime-CICpEidL.mjs";
2
- import { Array, Config, Effect, FileSystem, Option, Path, String, pipe } from "effect";
3
- // src/openrouter-app.ts
4
- const GITHUB = "https://github.com";
5
- const SELF = "masseater/masseater.dev";
6
- const GIT_SUFFIX = /\.git\/?$/u;
7
- const SEPARATORS = /[/:]/u;
8
- const SLUG_PARTS = 2;
9
- const GITDIR = /^gitdir:\s*(?<dir>.+)$/mu;
10
- const ORIGIN_URL = /\[remote "origin"\][^[]*?\burl\s*=\s*(?<url>\S+)/u;
11
- const isSet = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.map(Option.isSome), Effect.orElseSucceed(() => false));
12
- const contextOf = Effect.gen(function* contextOf() {
13
- if (yield* isSet("GITHUB_ACTIONS")) return "github-actions";
14
- if (yield* isSet("CLAUDE_CODE_REMOTE")) return "claude-code-cloud";
15
- if (yield* isSet("CLAUDECODE")) return "claude-code";
16
- return "local";
17
- });
18
- const slugOf = (url) => {
19
- const parts = pipe(url, String.trim, String.replace(GIT_SUFFIX, ""), String.split(SEPARATORS), Array.filter((part) => String.isNonEmpty(part)));
20
- if (parts.length < SLUG_PARTS) return Option.none();
21
- return Option.some(pipe(Array.takeRight(parts, SLUG_PARTS), Array.join("/")));
22
- };
23
- const linkedGitDir = Effect.fn("linkedGitDir")(function* linkedGitDir(dir, dotGit) {
24
- const fs = yield* FileSystem.FileSystem;
25
- const path = yield* Path.Path;
26
- const text = yield* fs.readFileString(dotGit);
27
- return captured(String.match(GITDIR)(text), "dir").pipe(Option.map((found) => path.resolve(dir, String.trim(found))));
28
- });
29
- const gitDirAt = Effect.fn("gitDirAt")(function* gitDirAt(dir) {
30
- const fs = yield* FileSystem.FileSystem;
31
- const dotGit = (yield* Path.Path).join(dir, ".git");
32
- const info = yield* fs.stat(dotGit).pipe(Effect.option);
33
- if (Option.isNone(info)) return Option.none();
34
- if (info.value.type === "Directory") return Option.some(dotGit);
35
- return yield* linkedGitDir(dir, dotGit);
36
- });
37
- const gitDirFrom = (dir) => Effect.gen(function* walk() {
38
- const path = yield* Path.Path;
39
- const here = yield* gitDirAt(dir);
40
- const parent = path.dirname(dir);
41
- if (Option.isSome(here) || parent === dir) return here;
42
- return yield* gitDirFrom(parent);
43
- });
44
- const commonDirOf = Effect.fn("commonDirOf")(function* commonDirOf(gitDir) {
45
- const fs = yield* FileSystem.FileSystem;
46
- const path = yield* Path.Path;
47
- const common = yield* fs.readFileString(path.join(gitDir, "commondir")).pipe(Effect.option);
48
- return Option.match(common, {
49
- onNone: () => gitDir,
50
- onSome: (relative) => path.resolve(gitDir, String.trim(relative))
51
- });
52
- });
53
- const remoteSlug = Effect.gen(function* remoteSlug() {
54
- const fs = yield* FileSystem.FileSystem;
55
- const path = yield* Path.Path;
56
- const gitDir = yield* gitDirFrom(path.resolve("."));
57
- if (Option.isNone(gitDir)) return Option.none();
58
- const commonDir = yield* commonDirOf(gitDir.value);
59
- const config = yield* fs.readFileString(path.join(commonDir, "config"));
60
- return captured(String.match(ORIGIN_URL)(config), "url").pipe(Option.flatMap(slugOf));
61
- }).pipe(Effect.orElseSucceed(() => Option.none()));
62
- const repoOf = Effect.gen(function* repoOf() {
63
- const fromActions = yield* Config.option(Config.NonEmptyString("GITHUB_REPOSITORY")).pipe(Effect.orElseSucceed(() => Option.none()));
64
- if (Option.isSome(fromActions)) return fromActions;
65
- return yield* remoteSlug;
66
- });
67
- const appContext = Effect.gen(function* app() {
68
- const context = yield* contextOf;
69
- const repo = yield* repoOf;
70
- return {
71
- repo: Option.getOrElse(repo, () => SELF),
72
- context
73
- };
74
- });
75
- const openRouterApp = (tool) => Effect.gen(function* attribution() {
76
- const context = yield* contextOf;
77
- const repo = yield* repoOf;
78
- const slug = Option.getOrElse(repo, () => SELF);
79
- return {
80
- "HTTP-Referer": `${GITHUB}/${slug}/${tool}/${context}`,
81
- "X-OpenRouter-Title": `${Option.getOrElse(repo, () => "unknown")} ${context} ${tool}`,
82
- "X-OpenRouter-App-Visibility": "hidden"
83
- };
84
- });
85
- export { appContext, openRouterApp };
86
-
87
- //# sourceMappingURL=openrouter-app.mjs.map
1
+ export { a as appContext, o as openRouterApp } from "./serve-decisions-CjlhvYm7.mjs";
@@ -1,41 +1,11 @@
1
- import { openRouterApp } from "./openrouter-app.mjs";
2
- import { n as envNameOf } from "./runtime-CICpEidL.mjs";
3
- import { t as serveDecisions } from "./serve-decisions-cQpGj_Fq.mjs";
4
- import { r as wireRequestsFor, t as mergeResponses } from "./wire-CRD1mSAo.mjs";
5
- import { Config, Effect, Option, Schedule, Schema, String as String$1 } from "effect";
6
- import { make } from "@effect/ai-openrouter/OpenRouterClient";
7
- import { HttpClient, HttpClientRequest } from "effect/http";
8
- // src/decisions.ts
9
- const TOOL = "oxlint-plugin-decision";
10
- const API_PATH = "/api/v1";
11
- const RETRY_INITIAL_MS = 10;
12
- const RETRY_EXPONENT = 2;
13
- const attribution = openRouterApp(TOOL).pipe(Effect.cached, Effect.runSync);
14
- const ErrorBody = Schema.Struct({ error: Schema.Struct({ message: Schema.String }) });
15
- const decodeErrorBody = Schema.decodeOption(Schema.fromJsonString(ErrorBody));
16
- const serverMessageOf = (body, fallback) => Option.fromUndefinedOr(body).pipe(Option.flatMap(decodeErrorBody), Option.match({
17
- onNone: () => fallback,
18
- onSome: ({ error }) => error.message
19
- }));
20
- const reasonFor = ({ _tag, message, http }) => Option.fromUndefinedOr(http).pipe(Option.flatMap(({ response, body }) => Option.map(Option.fromUndefinedOr(response), ({ status }) => `http ${String(status)}: ${serverMessageOf(body, _tag)}`)), Option.getOrElse(() => `network: ${message}`));
21
- const send = Effect.fn("send")(function* send(endpoint, decisionsRequest, { env }) {
22
- const apiKey = yield* Config.Redacted(envNameOf(env, "OPENROUTER_API_KEY"));
23
- const headers = yield* attribution;
24
- const [body] = yield* (yield* make({
25
- apiKey,
26
- apiUrl: `${endpoint}${API_PATH}`,
27
- transformClient: (http) => http.pipe(HttpClient.mapRequest(HttpClientRequest.setHeaders(headers)), HttpClient.retryTransient({
28
- retryOn: "response-only",
29
- schedule: Schedule.exponential(RETRY_INITIAL_MS, RETRY_EXPONENT)
30
- }))
31
- })).createDecisions(decisionsRequest).pipe(Effect.mapError(({ reason }) => reasonFor(reason)));
32
- return body;
33
- });
34
- // src/openrouter-worker.ts
1
+ import { o as envNameOf, r as wireRequestsFor, t as mergeResponses } from "./decision-BtTZ52be.mjs";
2
+ import { n as send, t as serveDecisions } from "./serve-decisions-CjlhvYm7.mjs";
3
+ import { Config, String } from "effect";
4
+ // src/app/openrouter-worker.ts
35
5
  const DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
36
6
  const API_SUFFIX = /\/api\/v1\/*$|\/+$/u;
37
7
  serveDecisions({
38
- endpoint: (env) => Config.String(envNameOf(env, "OPENROUTER_BASE_URL")).pipe(Config.withDefault(DEFAULT_BASE_URL), Config.map((url) => String$1.replace(API_SUFFIX, "")(String$1.trim(url)))),
8
+ endpoint: (env) => Config.String(envNameOf(env, "OPENROUTER_BASE_URL")).pipe(Config.withDefault(DEFAULT_BASE_URL), Config.map((url) => String.replace(API_SUFFIX, "")(String.trim(url)))),
39
9
  wires: wireRequestsFor,
40
10
  combine: mergeResponses,
41
11
  send
@@ -1 +1 @@
1
- {"version":3,"file":"openrouter-worker.mjs","names":["makeOpenRouter","Str"],"sources":["../src/decisions.ts","../src/openrouter-worker.ts"],"sourcesContent":["import { make as makeOpenRouter } from \"@effect/ai-openrouter/OpenRouterClient\";\nimport { Config, Effect, Option, Schedule, Schema } from \"effect\";\nimport { HttpClient, HttpClientRequest } from \"effect/http\";\n\nimport { openRouterApp } from \"./openrouter-app.ts\";\nimport { envNameOf } from \"./runtime.ts\";\nimport type { DecideInput } from \"./types.ts\";\nimport type { WireRequest } from \"./wire.ts\";\n\nconst TOOL = \"oxlint-plugin-decision\";\nconst API_PATH = \"/api/v1\";\nconst RETRY_INITIAL_MS = 10;\nconst RETRY_EXPONENT = 2;\n\nconst attribution = openRouterApp(TOOL).pipe(Effect.cached, Effect.runSync);\n\nconst ErrorBody = Schema.Struct({ error: Schema.Struct({ message: Schema.String }) });\n\nconst decodeErrorBody = Schema.decodeOption(Schema.fromJsonString(ErrorBody));\n\ninterface HttpFailure {\n readonly response?: { readonly status: number } | undefined;\n readonly body?: string | undefined;\n}\n\ninterface FailureReason {\n readonly _tag: string;\n readonly message: string;\n readonly http?: HttpFailure | undefined;\n}\n\nconst serverMessageOf = (body: string | undefined, fallback: string): string =>\n Option.fromUndefinedOr(body).pipe(\n Option.flatMap(decodeErrorBody),\n Option.match({ onNone: () => fallback, onSome: ({ error }) => error.message }),\n );\n\nconst reasonFor = ({ _tag, message, http }: FailureReason): string =>\n Option.fromUndefinedOr(http).pipe(\n Option.flatMap(({ response, body }) =>\n Option.map(\n Option.fromUndefinedOr(response),\n ({ status }) => `http ${String(status)}: ${serverMessageOf(body, _tag)}`,\n ),\n ),\n Option.getOrElse(() => `network: ${message}`),\n );\n\nconst send = Effect.fn(\"send\")(function* send(\n endpoint: string,\n decisionsRequest: WireRequest,\n { env }: Pick<DecideInput, \"env\">,\n) {\n const apiKey = yield* Config.Redacted(envNameOf(env, \"OPENROUTER_API_KEY\"));\n const headers = yield* attribution;\n const client = yield* makeOpenRouter({\n apiKey,\n apiUrl: `${endpoint}${API_PATH}`,\n transformClient: (http) =>\n http.pipe(\n HttpClient.mapRequest(HttpClientRequest.setHeaders(headers)),\n HttpClient.retryTransient({\n retryOn: \"response-only\",\n schedule: Schedule.exponential(RETRY_INITIAL_MS, RETRY_EXPONENT),\n }),\n ),\n });\n const [body] = yield* client\n .createDecisions(decisionsRequest)\n .pipe(Effect.mapError(({ reason }) => reasonFor(reason)));\n return body;\n});\n\n/** @internal */\nexport { send };\n","import { Config, String as Str } from \"effect\";\n\nimport { send } from \"./decisions.ts\";\nimport { envNameOf } from \"./runtime.ts\";\nimport { serveDecisions } from \"./serve-decisions.ts\";\nimport { mergeResponses, wireRequestsFor } from \"./wire.ts\";\n\nconst DEFAULT_BASE_URL = \"https://openrouter.ai/api/v1\";\nconst API_SUFFIX = /\\/api\\/v1\\/*$|\\/+$/u;\n\nserveDecisions({\n endpoint: (env) =>\n Config.String(envNameOf(env, \"OPENROUTER_BASE_URL\")).pipe(\n Config.withDefault(DEFAULT_BASE_URL),\n Config.map((url) => Str.replace(API_SUFFIX, \"\")(Str.trim(url))),\n ),\n wires: wireRequestsFor,\n combine: mergeResponses,\n send,\n});\n"],"mappings":";;;;;;;;AASA,MAAM,OAAO;AACb,MAAM,WAAW;AACjB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB;AAEvB,MAAM,cAAc,cAAc,IAAI,CAAC,CAAC,KAAK,OAAO,QAAQ,OAAO,OAAO;AAE1E,MAAM,YAAY,OAAO,OAAO,EAAE,OAAO,OAAO,OAAO,EAAE,SAAS,OAAO,OAAO,CAAC,EAAE,CAAC;AAEpF,MAAM,kBAAkB,OAAO,aAAa,OAAO,eAAe,SAAS,CAAC;AAa5E,MAAM,mBAAmB,MAA0B,aACjD,OAAO,gBAAgB,IAAI,CAAC,CAAC,KAC3B,OAAO,QAAQ,eAAe,GAC9B,OAAO,MAAM;CAAE,cAAc;CAAU,SAAS,EAAE,YAAY,MAAM;AAAQ,CAAC,CAC/E;AAEF,MAAM,aAAa,EAAE,MAAM,SAAS,WAClC,OAAO,gBAAgB,IAAI,CAAC,CAAC,KAC3B,OAAO,SAAS,EAAE,UAAU,WAC1B,OAAO,IACL,OAAO,gBAAgB,QAAQ,IAC9B,EAAE,aAAa,QAAQ,OAAO,MAAM,EAAE,IAAI,gBAAgB,MAAM,IAAI,GACvE,CACF,GACA,OAAO,gBAAgB,YAAY,SAAS,CAC9C;AAEF,MAAM,OAAO,OAAO,GAAG,MAAM,CAAC,CAAC,UAAU,KACvC,UACA,kBACA,EAAE,OACF;CACA,MAAM,SAAS,OAAO,OAAO,SAAS,UAAU,KAAK,oBAAoB,CAAC;CAC1E,MAAM,UAAU,OAAO;CAavB,MAAM,CAAC,QAAQ,QAAO,OAZAA,KAAe;EACnC;EACA,QAAQ,GAAG,WAAW;EACtB,kBAAkB,SAChB,KAAK,KACH,WAAW,WAAW,kBAAkB,WAAW,OAAO,CAAC,GAC3D,WAAW,eAAe;GACxB,SAAS;GACT,UAAU,SAAS,YAAY,kBAAkB,cAAc;EACjE,CAAC,CACH;CACJ,CAAC,EAAA,CAEE,gBAAgB,gBAAgB,CAAC,CACjC,KAAK,OAAO,UAAU,EAAE,aAAa,UAAU,MAAM,CAAC,CAAC;CAC1D,OAAO;AACT,CAAC;;AChED,MAAM,mBAAmB;AACzB,MAAM,aAAa;AAEnB,eAAe;CACb,WAAW,QACT,OAAO,OAAO,UAAU,KAAK,qBAAqB,CAAC,CAAC,CAAC,KACnD,OAAO,YAAY,gBAAgB,GACnC,OAAO,KAAK,QAAQC,SAAI,QAAQ,YAAY,EAAE,CAAC,CAACA,SAAI,KAAK,GAAG,CAAC,CAAC,CAChE;CACF,OAAO;CACP,SAAS;CACT;AACF,CAAC"}
1
+ {"version":3,"file":"openrouter-worker.mjs","names":["Str"],"sources":["../src/app/openrouter-worker.ts"],"sourcesContent":["import { Config, String as Str } from \"effect\";\n\nimport { envNameOf, mergeResponses, wireRequestsFor } from \"#/entities/decision/index.ts\";\nimport { send, serveDecisions } from \"#/features/serve-decisions/index.ts\";\n\nconst DEFAULT_BASE_URL = \"https://openrouter.ai/api/v1\";\nconst API_SUFFIX = /\\/api\\/v1\\/*$|\\/+$/u;\n\nserveDecisions({\n endpoint: (env) =>\n Config.String(envNameOf(env, \"OPENROUTER_BASE_URL\")).pipe(\n Config.withDefault(DEFAULT_BASE_URL),\n Config.map((url) => Str.replace(API_SUFFIX, \"\")(Str.trim(url))),\n ),\n wires: wireRequestsFor,\n combine: mergeResponses,\n send,\n});\n"],"mappings":";;;;AAKA,MAAM,mBAAmB;AACzB,MAAM,aAAa;AAEnB,eAAe;CACb,WAAW,QACT,OAAO,OAAO,UAAU,KAAK,qBAAqB,CAAC,CAAC,CAAC,KACnD,OAAO,YAAY,gBAAgB,GACnC,OAAO,KAAK,QAAQA,OAAI,QAAQ,YAAY,EAAE,CAAC,CAACA,OAAI,KAAK,GAAG,CAAC,CAAC,CAChE;CACF,OAAO;CACP,SAAS;CACT;AACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { t as createDecisionPlugin } from "./app-Bso1uwY5.mjs";
2
+ // src/app/preset-plugin.ts
3
+ const PLUGIN_NAME = "decision-presets";
4
+ const presetPlugin = (rules) => createDecisionPlugin({
5
+ name: PLUGIN_NAME,
6
+ rules
7
+ });
8
+ export { presetPlugin as t };
9
+
10
+ //# sourceMappingURL=preset-plugin-AAwedMeS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-plugin-AAwedMeS.mjs","names":[],"sources":["../src/app/preset-plugin.ts"],"sourcesContent":["import { createDecisionPlugin } from \"@r_masseater/oxlint-plugin-decision\";\nimport type { DecisionPlugin } from \"@r_masseater/oxlint-plugin-decision\";\n\nimport type { Preset } from \"#/features/define-presets/index.ts\";\n\nconst PLUGIN_NAME = \"decision-presets\";\n\nexport const presetPlugin = (rules: Preset): DecisionPlugin =>\n createDecisionPlugin({ name: PLUGIN_NAME, rules });\n"],"mappings":";;AAKA,MAAM,cAAc;AAEpB,MAAa,gBAAgB,UAC3B,qBAAqB;CAAE,MAAM;CAAa;AAAM,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { c as DecisionPlugin } from "../index-Cgg-w0hb.mjs";
2
+ import "../index-D7VrRpTx.mjs";
3
+ import { B as redundantGuard, F as commentRestatesCode, H as suppressionInsteadOfFix, I as defaultMasksMissingValue, L as docRestatesSignature, M as aiSlopRules, N as castInsteadOfNarrowing, P as commentNarratesHistory, R as passThroughWrapper, V as reinventsBuiltin, z as placeholderImplementation } from "../index-BOrpK3Iv.mjs";
4
+ declare const plugin: DecisionPlugin;
5
+ export { aiSlopRules, castInsteadOfNarrowing, commentNarratesHistory, commentRestatesCode, plugin as default, defaultMasksMissingValue, docRestatesSignature, passThroughWrapper, placeholderImplementation, redundantGuard, reinventsBuiltin, suppressionInsteadOfFix };
6
+ //# sourceMappingURL=ai-slop.d.mts.map
@@ -0,0 +1,10 @@
1
+ import { t as createDecisionPlugin } from "../app-Bso1uwY5.mjs";
2
+ import { B as reinventsBuiltin, F as defaultMasksMissingValue, I as docRestatesSignature, L as passThroughWrapper, M as castInsteadOfNarrowing, N as commentNarratesHistory, P as commentRestatesCode, R as placeholderImplementation, V as suppressionInsteadOfFix, j as aiSlopRules, z as redundantGuard } from "../define-presets-clyqLZxo.mjs";
3
+ // src/app/ai-slop.ts
4
+ const plugin = createDecisionPlugin({
5
+ name: "decision-ai-slop",
6
+ rules: aiSlopRules
7
+ });
8
+ export { aiSlopRules, castInsteadOfNarrowing, commentNarratesHistory, commentRestatesCode, plugin as default, defaultMasksMissingValue, docRestatesSignature, passThroughWrapper, placeholderImplementation, redundantGuard, reinventsBuiltin, suppressionInsteadOfFix };
9
+
10
+ //# sourceMappingURL=ai-slop.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-slop.mjs","names":[],"sources":["../../src/app/ai-slop.ts"],"sourcesContent":["import { createDecisionPlugin } from \"@r_masseater/oxlint-plugin-decision\";\nimport type { DecisionPlugin } from \"@r_masseater/oxlint-plugin-decision\";\n\nimport { aiSlopRules } from \"#/features/define-presets/index.ts\";\n\nconst plugin: DecisionPlugin = createDecisionPlugin({\n name: \"decision-ai-slop\",\n rules: aiSlopRules,\n});\n\nexport default plugin;\nexport {\n aiSlopRules,\n castInsteadOfNarrowing,\n commentNarratesHistory,\n commentRestatesCode,\n defaultMasksMissingValue,\n docRestatesSignature,\n passThroughWrapper,\n placeholderImplementation,\n redundantGuard,\n reinventsBuiltin,\n suppressionInsteadOfFix,\n} from \"#/features/define-presets/index.ts\";\n"],"mappings":";;;AAKA,MAAM,SAAyB,qBAAqB;CAClD,MAAM;CACN,OAAO;AACT,CAAC"}
@@ -0,0 +1,3 @@
1
+ import plugin from "./recommended.mjs";
2
+ import { A as safeNameIsSafe, C as docErrorsMatchBody, D as logLevelMatchesEvent, E as idempotentName, O as logMessageMatchesEvent, S as commentDescribesDeclaration, T as fnNamePromises, _ as reviewOnly, a as testNameDescribesCode, b as codeClaims, c as nameMatchesBehavior, d as noPromptInjection, f as preferSchemaValidation, g as recommended, h as presets, i as testMocksSubject, j as varNameDescribesValue, k as pureNameIsPure, l as noHardcodedSecrets, m as Preset, n as snapshotOnlyBehaviourClaim, o as testNameVerifiesClaim, p as untrustedInputRisk, r as testClaims, s as domainNaming, t as describeNamesSubject, u as noPiiInLogs, v as strict, w as errorMessageMatchesCondition, x as commentDescribesBlock, y as catchHidesFailure } from "../index-BOrpK3Iv.mjs";
3
+ export { type Preset, catchHidesFailure, codeClaims, commentDescribesBlock, commentDescribesDeclaration, plugin as default, describeNamesSubject, docErrorsMatchBody, domainNaming, errorMessageMatchesCondition, fnNamePromises, idempotentName, logLevelMatchesEvent, logMessageMatchesEvent, nameMatchesBehavior, noHardcodedSecrets, noPiiInLogs, noPromptInjection, preferSchemaValidation, presets, pureNameIsPure, recommended, reviewOnly, safeNameIsSafe, snapshotOnlyBehaviourClaim, strict, testClaims, testMocksSubject, testNameDescribesCode, testNameVerifiesClaim, untrustedInputRisk, varNameDescribesValue };
@@ -0,0 +1,3 @@
1
+ import plugin from "./recommended.mjs";
2
+ import { A as varNameDescribesValue, C as errorMessageMatchesCondition, D as logMessageMatchesEvent, E as logLevelMatchesEvent, O as pureNameIsPure, S as docErrorsMatchBody, T as idempotentName, _ as untrustedInputRisk, a as describeNamesSubject, b as commentDescribesBlock, c as testMocksSubject, d as domainNaming, f as nameMatchesBehavior, g as preferSchemaValidation, h as noPromptInjection, i as strict, k as safeNameIsSafe, l as testNameDescribesCode, m as noPiiInLogs, n as recommended, o as snapshotOnlyBehaviourClaim, p as noHardcodedSecrets, r as reviewOnly, s as testClaims, t as presets, u as testNameVerifiesClaim, v as catchHidesFailure, w as fnNamePromises, x as commentDescribesDeclaration, y as codeClaims } from "../define-presets-clyqLZxo.mjs";
3
+ export { catchHidesFailure, codeClaims, commentDescribesBlock, commentDescribesDeclaration, plugin as default, describeNamesSubject, docErrorsMatchBody, domainNaming, errorMessageMatchesCondition, fnNamePromises, idempotentName, logLevelMatchesEvent, logMessageMatchesEvent, nameMatchesBehavior, noHardcodedSecrets, noPiiInLogs, noPromptInjection, preferSchemaValidation, presets, pureNameIsPure, recommended, reviewOnly, safeNameIsSafe, snapshotOnlyBehaviourClaim, strict, testClaims, testMocksSubject, testNameDescribesCode, testNameVerifiesClaim, untrustedInputRisk, varNameDescribesValue };
@@ -0,0 +1,5 @@
1
+ import { c as DecisionPlugin } from "../index-Cgg-w0hb.mjs";
2
+ import "../index-D7VrRpTx.mjs";
3
+ declare const plugin: DecisionPlugin;
4
+ export { plugin as default };
5
+ //# sourceMappingURL=recommended.d.mts.map
@@ -0,0 +1,7 @@
1
+ import { n as recommended } from "../define-presets-clyqLZxo.mjs";
2
+ import { t as presetPlugin } from "../preset-plugin-AAwedMeS.mjs";
3
+ // src/app/recommended.ts
4
+ const plugin = presetPlugin(recommended);
5
+ export { plugin as default };
6
+
7
+ //# sourceMappingURL=recommended.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recommended.mjs","names":[],"sources":["../../src/app/recommended.ts"],"sourcesContent":["import type { DecisionPlugin } from \"@r_masseater/oxlint-plugin-decision\";\n\nimport { recommended } from \"#/features/define-presets/index.ts\";\n\nimport { presetPlugin } from \"./preset-plugin.ts\";\n\nconst plugin: DecisionPlugin = presetPlugin(recommended);\n\nexport default plugin;\n"],"mappings":";;;AAMA,MAAM,SAAyB,aAAa,WAAW"}
@@ -0,0 +1,5 @@
1
+ import { c as DecisionPlugin } from "../index-Cgg-w0hb.mjs";
2
+ import "../index-D7VrRpTx.mjs";
3
+ declare const plugin: DecisionPlugin;
4
+ export { plugin as default };
5
+ //# sourceMappingURL=review-only.d.mts.map
@@ -0,0 +1,7 @@
1
+ import { r as reviewOnly } from "../define-presets-clyqLZxo.mjs";
2
+ import { t as presetPlugin } from "../preset-plugin-AAwedMeS.mjs";
3
+ // src/app/review-only.ts
4
+ const plugin = presetPlugin(reviewOnly);
5
+ export { plugin as default };
6
+
7
+ //# sourceMappingURL=review-only.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review-only.mjs","names":[],"sources":["../../src/app/review-only.ts"],"sourcesContent":["import type { DecisionPlugin } from \"@r_masseater/oxlint-plugin-decision\";\n\nimport { reviewOnly } from \"#/features/define-presets/index.ts\";\n\nimport { presetPlugin } from \"./preset-plugin.ts\";\n\nconst plugin: DecisionPlugin = presetPlugin(reviewOnly);\n\nexport default plugin;\n"],"mappings":";;;AAMA,MAAM,SAAyB,aAAa,UAAU"}
@@ -0,0 +1,5 @@
1
+ import { c as DecisionPlugin } from "../index-Cgg-w0hb.mjs";
2
+ import "../index-D7VrRpTx.mjs";
3
+ declare const plugin: DecisionPlugin;
4
+ export { plugin as default };
5
+ //# sourceMappingURL=strict.d.mts.map
@@ -0,0 +1,7 @@
1
+ import { i as strict } from "../define-presets-clyqLZxo.mjs";
2
+ import { t as presetPlugin } from "../preset-plugin-AAwedMeS.mjs";
3
+ // src/app/strict.ts
4
+ const plugin = presetPlugin(strict);
5
+ export { plugin as default };
6
+
7
+ //# sourceMappingURL=strict.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strict.mjs","names":[],"sources":["../../src/app/strict.ts"],"sourcesContent":["import type { DecisionPlugin } from \"@r_masseater/oxlint-plugin-decision\";\n\nimport { strict } from \"#/features/define-presets/index.ts\";\n\nimport { presetPlugin } from \"./preset-plugin.ts\";\n\nconst plugin: DecisionPlugin = presetPlugin(strict);\n\nexport default plugin;\n"],"mappings":";;;AAMA,MAAM,SAAyB,aAAa,MAAM"}
@@ -0,0 +1,290 @@
1
+ import { V as AnswerSchema, a as captured, f as toJson, g as parseVerdicts, l as messageOf, o as envNameOf } from "./decision-BtTZ52be.mjs";
2
+ import { Array, Clock, Config, Effect, FileSystem, Function, Layer, Option, Path, Schedule, Schema, String as String$1, pipe } from "effect";
3
+ import { runAsWorker } from "synckit";
4
+ import { Answer } from "@effect/ai-openrouter/OpenRouterSchema";
5
+ import { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
6
+ import { make } from "@effect/ai-openrouter/OpenRouterClient";
7
+ import { Digest } from "effect/crypto";
8
+ import { layerDigest } from "@effect/platform-node-shared/NodeCrypto";
9
+ import { layer } from "@effect/platform-node-shared/NodeFileSystem";
10
+ import { layer as layer$1 } from "@effect/platform-node-shared/NodePath";
11
+ import { OtlpSerialization, OtlpTracer } from "effect/observability";
12
+ // src/features/serve-decisions/model/openrouter-app.ts
13
+ const GITHUB = "https://github.com";
14
+ const SELF = "masseater/masseater.dev";
15
+ const GIT_SUFFIX = /\.git\/?$/u;
16
+ const SEPARATORS = /[/:]/u;
17
+ const SLUG_PARTS = 2;
18
+ const GITDIR = /^gitdir:\s*(?<dir>.+)$/mu;
19
+ const ORIGIN_URL = /\[remote "origin"\][^[]*?\burl\s*=\s*(?<url>\S+)/u;
20
+ const isSet = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.map(Option.isSome), Effect.orElseSucceed(() => false));
21
+ const contextOf = Effect.gen(function* contextOf() {
22
+ if (yield* isSet("GITHUB_ACTIONS")) return "github-actions";
23
+ if (yield* isSet("CLAUDE_CODE_REMOTE")) return "claude-code-cloud";
24
+ if (yield* isSet("CLAUDECODE")) return "claude-code";
25
+ return "local";
26
+ });
27
+ const slugOf = (url) => {
28
+ const parts = pipe(url, String$1.trim, String$1.replace(GIT_SUFFIX, ""), String$1.split(SEPARATORS), Array.filter((part) => String$1.isNonEmpty(part)));
29
+ if (parts.length < SLUG_PARTS) return Option.none();
30
+ return Option.some(pipe(Array.takeRight(parts, SLUG_PARTS), Array.join("/")));
31
+ };
32
+ const linkedGitDir = Effect.fn("linkedGitDir")(function* linkedGitDir(dir, dotGit) {
33
+ const fs = yield* FileSystem.FileSystem;
34
+ const path = yield* Path.Path;
35
+ const text = yield* fs.readFileString(dotGit);
36
+ return captured(String$1.match(GITDIR)(text), "dir").pipe(Option.map((found) => path.resolve(dir, String$1.trim(found))));
37
+ });
38
+ const gitDirAt = Effect.fn("gitDirAt")(function* gitDirAt(dir) {
39
+ const fs = yield* FileSystem.FileSystem;
40
+ const dotGit = (yield* Path.Path).join(dir, ".git");
41
+ const info = yield* fs.stat(dotGit).pipe(Effect.option);
42
+ if (Option.isNone(info)) return Option.none();
43
+ if (info.value.type === "Directory") return Option.some(dotGit);
44
+ return yield* linkedGitDir(dir, dotGit);
45
+ });
46
+ const gitDirFrom = (dir) => Effect.gen(function* walk() {
47
+ const path = yield* Path.Path;
48
+ const here = yield* gitDirAt(dir);
49
+ const parent = path.dirname(dir);
50
+ if (Option.isSome(here) || parent === dir) return here;
51
+ return yield* gitDirFrom(parent);
52
+ });
53
+ const commonDirOf = Effect.fn("commonDirOf")(function* commonDirOf(gitDir) {
54
+ const fs = yield* FileSystem.FileSystem;
55
+ const path = yield* Path.Path;
56
+ const common = yield* fs.readFileString(path.join(gitDir, "commondir")).pipe(Effect.option);
57
+ return Option.match(common, {
58
+ onNone: () => gitDir,
59
+ onSome: (relative) => path.resolve(gitDir, String$1.trim(relative))
60
+ });
61
+ });
62
+ const remoteSlug = Effect.gen(function* remoteSlug() {
63
+ const fs = yield* FileSystem.FileSystem;
64
+ const path = yield* Path.Path;
65
+ const gitDir = yield* gitDirFrom(path.resolve("."));
66
+ if (Option.isNone(gitDir)) return Option.none();
67
+ const commonDir = yield* commonDirOf(gitDir.value);
68
+ const config = yield* fs.readFileString(path.join(commonDir, "config"));
69
+ return captured(String$1.match(ORIGIN_URL)(config), "url").pipe(Option.flatMap(slugOf));
70
+ }).pipe(Effect.orElseSucceed(() => Option.none()));
71
+ const repoOf = Effect.gen(function* repoOf() {
72
+ const fromActions = yield* Config.option(Config.NonEmptyString("GITHUB_REPOSITORY")).pipe(Effect.orElseSucceed(() => Option.none()));
73
+ if (Option.isSome(fromActions)) return fromActions;
74
+ return yield* remoteSlug;
75
+ });
76
+ /** @internal */
77
+ const appContext = Effect.gen(function* app() {
78
+ const context = yield* contextOf;
79
+ const repo = yield* repoOf;
80
+ return {
81
+ repo: Option.getOrElse(repo, () => SELF),
82
+ context
83
+ };
84
+ });
85
+ /** @internal */
86
+ const openRouterApp = (tool) => Effect.gen(function* attribution() {
87
+ const context = yield* contextOf;
88
+ const repo = yield* repoOf;
89
+ const slug = Option.getOrElse(repo, () => SELF);
90
+ return {
91
+ "HTTP-Referer": `${GITHUB}/${slug}/${tool}/${context}`,
92
+ "X-OpenRouter-Title": `${Option.getOrElse(repo, () => "unknown")} ${context} ${tool}`,
93
+ "X-OpenRouter-App-Visibility": "hidden"
94
+ };
95
+ });
96
+ // src/features/serve-decisions/model/workers-ai.ts
97
+ const TOOL$1 = "oxlint-plugin-decision";
98
+ const GATEWAY = "default";
99
+ const DEFAULT_API_URL = "https://api.cloudflare.com/client/v4";
100
+ const RUN_PATH = "/ai/run";
101
+ const TRAILING_SLASHES = /\/+$/u;
102
+ const MODEL_NAME = /(?<name>[^/]+)$/u;
103
+ const FIRST_REDIRECT = 300;
104
+ const RETRY_INITIAL_MS$1 = 10;
105
+ const RETRY_EXPONENT$1 = 2;
106
+ const Decisions = Schema.Struct({
107
+ model: Schema.String,
108
+ answers: Schema.Record(Schema.String, Answer)
109
+ });
110
+ const RunBody = Schema.Struct({ body: Schema.Struct({ result: Decisions }) });
111
+ const ErrorBody$1 = Schema.Struct({ errors: Schema.NonEmptyArray(Schema.Struct({ message: Schema.String })) });
112
+ const decodeErrorBody$1 = Schema.decodeUnknownOption(ErrorBody$1);
113
+ const accountUrl = ({ api, account }) => `${String$1.replace(TRAILING_SLASHES, "")(String$1.trim(api))}/accounts/${String$1.trim(account)}`;
114
+ /** @internal */
115
+ const endpointOf = (env) => Config.all({
116
+ api: Config.String(envNameOf(env, "CLOUDFLARE_API_BASE_URL")).pipe(Config.withDefault(DEFAULT_API_URL)),
117
+ account: Config.NonEmptyString(envNameOf(env, "CLOUDFLARE_ACCOUNT_ID"))
118
+ }).pipe(Config.map(accountUrl));
119
+ const modelNameOf = (model) => Option.getOrElse(captured(String$1.match(MODEL_NAME)(model), "name"), () => model);
120
+ const messageOfBody = (body) => Option.match(decodeErrorBody$1(body), {
121
+ onNone: () => "request failed",
122
+ onSome: ({ errors }) => pipe(errors, Array.map(({ message }) => message), Array.join("; "))
123
+ });
124
+ const failureOf = (response) => response.json.pipe(Effect.option, Effect.flatMap((body) => Effect.fail(`http ${String(response.status)}: ${messageOfBody(Option.getOrUndefined(body))}`)));
125
+ const workersAiRequest = (endpoint, wire) => HttpClientRequest.post(`${endpoint}${RUN_PATH}/${wire.model}`).pipe(HttpClientRequest.bodyJsonUnsafe({
126
+ model: modelNameOf(wire.model),
127
+ state: wire.state,
128
+ questions: wire.questions
129
+ }));
130
+ const post = Effect.fn("post")(function* post(endpoint, wire, { env }) {
131
+ const token = yield* Config.Redacted(envNameOf(env, "CLOUDFLARE_API_TOKEN"));
132
+ const app = yield* appContext;
133
+ const client = (yield* HttpClient.HttpClient).pipe(HttpClient.retryTransient({
134
+ retryOn: "response-only",
135
+ schedule: Schedule.exponential(RETRY_INITIAL_MS$1, RETRY_EXPONENT$1)
136
+ }));
137
+ return yield* workersAiRequest(endpoint, wire).pipe(HttpClientRequest.bearerToken(token), HttpClientRequest.setHeaders({
138
+ "cf-aig-gateway-id": GATEWAY,
139
+ "cf-aig-metadata": toJson({
140
+ tool: TOOL$1,
141
+ ...app
142
+ })
143
+ }), client.execute);
144
+ });
145
+ /** @internal */
146
+ const sendWorkersAi = Effect.fn("sendWorkersAi")(function* sendWorkersAi(endpoint, wire, input) {
147
+ const response = yield* post(endpoint, wire, input).pipe(Effect.mapError((error) => `network: ${error.message}`));
148
+ if (response.status >= FIRST_REDIRECT) return yield* failureOf(response);
149
+ const run = yield* HttpClientResponse.schemaJson(RunBody)(response).pipe(Effect.mapError((error) => `invalid response: ${error.message}`));
150
+ return {
151
+ model: wire.model,
152
+ answers: run.body.result.answers
153
+ };
154
+ });
155
+ // src/features/serve-decisions/model/decisions.ts
156
+ const TOOL = "oxlint-plugin-decision";
157
+ const API_PATH = "/api/v1";
158
+ const RETRY_INITIAL_MS = 10;
159
+ const RETRY_EXPONENT = 2;
160
+ const attribution = openRouterApp(TOOL).pipe(Effect.cached, Effect.runSync);
161
+ const ErrorBody = Schema.Struct({ error: Schema.Struct({ message: Schema.String }) });
162
+ const decodeErrorBody = Schema.decodeOption(Schema.fromJsonString(ErrorBody));
163
+ const serverMessageOf = (body, fallback) => Option.fromUndefinedOr(body).pipe(Option.flatMap(decodeErrorBody), Option.match({
164
+ onNone: () => fallback,
165
+ onSome: ({ error }) => error.message
166
+ }));
167
+ const reasonFor = ({ _tag, message, http }) => Option.fromUndefinedOr(http).pipe(Option.flatMap(({ response, body }) => Option.map(Option.fromUndefinedOr(response), ({ status }) => `http ${String(status)}: ${serverMessageOf(body, _tag)}`)), Option.getOrElse(() => `network: ${message}`));
168
+ /** @internal */
169
+ const send = Effect.fn("send")(function* send(endpoint, decisionsRequest, { env }) {
170
+ const apiKey = yield* Config.Redacted(envNameOf(env, "OPENROUTER_API_KEY"));
171
+ const headers = yield* attribution;
172
+ const [body] = yield* (yield* make({
173
+ apiKey,
174
+ apiUrl: `${endpoint}${API_PATH}`,
175
+ transformClient: (http) => http.pipe(HttpClient.mapRequest(HttpClientRequest.setHeaders(headers)), HttpClient.retryTransient({
176
+ retryOn: "response-only",
177
+ schedule: Schedule.exponential(RETRY_INITIAL_MS, RETRY_EXPONENT)
178
+ }))
179
+ })).createDecisions(decisionsRequest).pipe(Effect.mapError(({ reason }) => reasonFor(reason)));
180
+ return body;
181
+ });
182
+ // src/features/serve-decisions/model/cache.ts
183
+ const DATA_FIRST_ARITY = 2;
184
+ const CACHE_VERSION = 7;
185
+ /** @internal */
186
+ const CACHE_DIR = [
187
+ "node_modules",
188
+ ".cache",
189
+ "oxlint-plugin-decision"
190
+ ];
191
+ const encodeJson = (value) => Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(value).pipe(Effect.orDie);
192
+ /** @internal */
193
+ const cacheFile = Effect.fn("cacheFile")(function* cacheFile(endpoint, request) {
194
+ const digest = yield* Digest.Digest;
195
+ const path = yield* Path.Path;
196
+ const json = yield* encodeJson({
197
+ version: CACHE_VERSION,
198
+ endpoint,
199
+ request
200
+ });
201
+ const payload = new TextEncoder().encode(json);
202
+ const hash = yield* digest.digestHex(Digest.sha256, payload);
203
+ return path.resolve(...CACHE_DIR, `${hash}.json`);
204
+ });
205
+ const CachedResponse = Schema.Struct({
206
+ model: Schema.NonEmptyString,
207
+ answers: Schema.Record(Schema.String, AnswerSchema)
208
+ });
209
+ const decodeCached = Schema.decodeOption(Schema.fromJsonString(CachedResponse));
210
+ /** @internal */
211
+ const isComplete = Function.dual(DATA_FIRST_ARITY, (response, request) => Option.liftThrowable(() => parseVerdicts(response, request).complete)().pipe(Option.getOrElse(() => false)));
212
+ /** @internal */
213
+ const readCache = Effect.fn("readCache")(function* readCache(file, request) {
214
+ return (yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(Effect.option)).pipe(Option.flatMap((raw) => decodeCached(raw)), Option.filter((response) => isComplete(response, request)));
215
+ });
216
+ /** @internal */
217
+ const writeCache = Effect.fn("writeCache")(function* writeCache(file, response) {
218
+ const fs = yield* FileSystem.FileSystem;
219
+ const path = yield* Path.Path;
220
+ const now = yield* Clock.currentTimeMillis;
221
+ const temp = `${file}.tmp-${String(now)}`;
222
+ const json = yield* encodeJson(response);
223
+ yield* fs.makeDirectory(path.dirname(file), { recursive: true });
224
+ yield* fs.writeFileString(temp, json);
225
+ yield* fs.rename(temp, file);
226
+ });
227
+ // src/features/serve-decisions/model/services.ts
228
+ const tracing = OtlpTracer.layerFromConfig({ resource: { serviceName: "oxlint-plugin-decision" } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
229
+ /** @internal */
230
+ const workerServices = [
231
+ layer,
232
+ layer$1,
233
+ layerDigest,
234
+ FetchHttpClient.layer,
235
+ tracing
236
+ ];
237
+ // src/features/serve-decisions/model/serve-decisions.ts
238
+ const ask = Effect.fn("ask")(function* ask(transport, endpoint, { request, timeoutMs, env }) {
239
+ const responses = yield* Effect.forEach(transport.wires(request), (wire) => transport.send(endpoint, wire, { env }), { concurrency: "unbounded" }).pipe(Effect.timeoutOrElse({
240
+ duration: timeoutMs,
241
+ orElse: () => Effect.fail("timeout")
242
+ }));
243
+ return transport.combine(request, responses);
244
+ });
245
+ const askAndStore = Effect.fn("askAndStore")(function* askAndStore(transport, { endpoint, file }, input) {
246
+ const response = yield* ask(transport, endpoint, input);
247
+ if (isComplete(response, input.request)) yield* writeCache(file, response).pipe(Effect.ignore);
248
+ return response;
249
+ });
250
+ const decide = Effect.fn("decide")(function* decide(transport, input) {
251
+ yield* Effect.annotateCurrentSpan({ model: input.request.model });
252
+ const endpoint = yield* transport.endpoint(input.env);
253
+ const file = yield* cacheFile(endpoint, input.request);
254
+ const cached = yield* readCache(file, input.request);
255
+ yield* Effect.annotateCurrentSpan({ cached: Option.isSome(cached) });
256
+ if (Option.isSome(cached)) return {
257
+ response: cached.value,
258
+ cached: true
259
+ };
260
+ return {
261
+ response: yield* askAndStore(transport, {
262
+ endpoint,
263
+ file
264
+ }, input),
265
+ cached: false
266
+ };
267
+ });
268
+ const reasonOf = (error) => {
269
+ if (typeof error === "string") return error;
270
+ return messageOf(error);
271
+ };
272
+ const decideOne = (transport, input) => decide(transport, input).pipe(Effect.match({
273
+ onSuccess: ({ response, cached }) => ({
274
+ ok: true,
275
+ response,
276
+ cached
277
+ }),
278
+ onFailure: (error) => ({
279
+ ok: false,
280
+ reason: reasonOf(error)
281
+ })
282
+ }));
283
+ const decideEach = (transport, inputs) => Effect.all(pipe(inputs, Array.map((input) => decideOne(transport, input))), { concurrency: "unbounded" }).pipe(Effect.provide(workerServices));
284
+ /** @internal */
285
+ const serveDecisions = (transport) => {
286
+ runAsWorker((inputs) => Effect.runPromise(decideEach(transport, inputs)));
287
+ };
288
+ export { appContext as a, sendWorkersAi as i, send as n, openRouterApp as o, endpointOf as r, serveDecisions as t };
289
+
290
+ //# sourceMappingURL=serve-decisions-CjlhvYm7.mjs.map