@r_masseater/oxlint-plugin-decision 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -3
- package/dist/{src-CknkhDKf.mjs → app-UakaWKAT.mjs} +69 -209
- package/dist/app-UakaWKAT.mjs.map +1 -0
- package/dist/cloudflare-worker.mjs +5 -182
- package/dist/cloudflare-worker.mjs.map +1 -1
- package/dist/decision-B7hahWHz.mjs +561 -0
- package/dist/decision-B7hahWHz.mjs.map +1 -0
- package/dist/{presets-CxYinkkJ.mjs → define-presets-yflVt8vT.mjs} +197 -17
- package/dist/define-presets-yflVt8vT.mjs.map +1 -0
- package/dist/{index-DiH-hZUS.d.mts → index-C0Twu0w7.d.mts} +26 -33
- package/dist/index-HOwrGbIA.d.mts +89 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/preset-plugin-ClpEFUN5.mjs +10 -0
- package/dist/preset-plugin-ClpEFUN5.mjs.map +1 -0
- package/dist/presets/ai-slop.d.mts +3 -13
- package/dist/presets/ai-slop.mjs +3 -183
- package/dist/presets/ai-slop.mjs.map +1 -1
- package/dist/presets/index.d.mts +2 -78
- package/dist/presets/index.mjs +1 -1
- package/dist/presets/recommended.d.mts +1 -1
- package/dist/presets/recommended.mjs +3 -2
- package/dist/presets/recommended.mjs.map +1 -1
- package/dist/presets/review-only.d.mts +1 -1
- package/dist/presets/review-only.mjs +3 -2
- package/dist/presets/review-only.mjs.map +1 -1
- package/dist/presets/strict.d.mts +1 -1
- package/dist/presets/strict.mjs +3 -2
- package/dist/presets/strict.mjs.map +1 -1
- package/dist/serve-decisions-DYGwLMft.mjs +287 -0
- package/dist/serve-decisions-DYGwLMft.mjs.map +1 -0
- package/dist/typesafe-worker.mjs +11 -0
- package/dist/typesafe-worker.mjs.map +1 -0
- package/package.json +7 -12
- package/skills/write-decision-rules/SKILL.md +18 -17
- package/skills/write-decision-rules/references/tuning.md +1 -3
- package/dist/openrouter-app.d.mts +0 -15
- package/dist/openrouter-app.mjs +0 -89
- package/dist/openrouter-app.mjs.map +0 -1
- package/dist/openrouter-worker.mjs +0 -46
- package/dist/openrouter-worker.mjs.map +0 -1
- package/dist/presets-CxYinkkJ.mjs.map +0 -1
- package/dist/runtime-CICpEidL.mjs +0 -271
- package/dist/runtime-CICpEidL.mjs.map +0 -1
- package/dist/select-bvQylrUt.mjs +0 -12
- package/dist/select-bvQylrUt.mjs.map +0 -1
- package/dist/serve-decisions-BM0bUWWe.mjs +0 -119
- package/dist/serve-decisions-BM0bUWWe.mjs.map +0 -1
- package/dist/src-CknkhDKf.mjs.map +0 -1
- package/dist/wire-CRD1mSAo.mjs +0 -251
- package/dist/wire-CRD1mSAo.mjs.map +0 -1
- package/skills/write-decision-rules/references/providers.md +0 -55
- /package/dist/{openrouter-worker.d.mts → typesafe-worker.d.mts} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as recommended } from "../define-presets-yflVt8vT.mjs";
|
|
2
|
+
import { t as presetPlugin } from "../preset-plugin-ClpEFUN5.mjs";
|
|
3
|
+
// src/app/recommended.ts
|
|
3
4
|
const plugin = presetPlugin(recommended);
|
|
4
5
|
export { plugin as default };
|
|
5
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recommended.mjs","names":[],"sources":["../../src/
|
|
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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { r as reviewOnly } from "../define-presets-yflVt8vT.mjs";
|
|
2
|
+
import { t as presetPlugin } from "../preset-plugin-ClpEFUN5.mjs";
|
|
3
|
+
// src/app/review-only.ts
|
|
3
4
|
const plugin = presetPlugin(reviewOnly);
|
|
4
5
|
export { plugin as default };
|
|
5
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"review-only.mjs","names":[],"sources":["../../src/
|
|
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"}
|
package/dist/presets/strict.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { i as strict
|
|
2
|
-
|
|
1
|
+
import { i as strict } from "../define-presets-yflVt8vT.mjs";
|
|
2
|
+
import { t as presetPlugin } from "../preset-plugin-ClpEFUN5.mjs";
|
|
3
|
+
// src/app/strict.ts
|
|
3
4
|
const plugin = presetPlugin(strict);
|
|
4
5
|
export { plugin as default };
|
|
5
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strict.mjs","names":[],"sources":["../../src/
|
|
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,287 @@
|
|
|
1
|
+
import { H as AnswerSchema, a as envNameOf, c as messageOf, d as toJson, h as parseVerdicts, i as captured, n as mergeResponses, y as PREFIX } from "./decision-B7hahWHz.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 { FetchHttpClient, HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
5
|
+
import { Digest } from "effect/crypto";
|
|
6
|
+
import { layerDigest } from "@effect/platform-node-shared/NodeCrypto";
|
|
7
|
+
import { layer } from "@effect/platform-node-shared/NodeFileSystem";
|
|
8
|
+
import { layer as layer$1 } from "@effect/platform-node-shared/NodePath";
|
|
9
|
+
import { OtlpSerialization, OtlpTracer } from "effect/observability";
|
|
10
|
+
// src/features/serve-decisions/model/app-context.ts
|
|
11
|
+
const SELF = "masseater/masseater.dev";
|
|
12
|
+
const GIT_SUFFIX = /\.git\/?$/u;
|
|
13
|
+
const SEPARATORS = /[/:]/u;
|
|
14
|
+
const SLUG_PARTS = 2;
|
|
15
|
+
const GITDIR = /^gitdir:\s*(?<dir>.+)$/mu;
|
|
16
|
+
const ORIGIN_URL = /\[remote "origin"\][^[]*?\burl\s*=\s*(?<url>\S+)/u;
|
|
17
|
+
const isSet = (name) => Config.option(Config.NonEmptyString(name)).pipe(Effect.map(Option.isSome), Effect.orElseSucceed(() => false));
|
|
18
|
+
const contextOf = Effect.gen(function* contextOf() {
|
|
19
|
+
if (yield* isSet("GITHUB_ACTIONS")) return "github-actions";
|
|
20
|
+
if (yield* isSet("CLAUDE_CODE_REMOTE")) return "claude-code-cloud";
|
|
21
|
+
if (yield* isSet("CLAUDECODE")) return "claude-code";
|
|
22
|
+
return "local";
|
|
23
|
+
});
|
|
24
|
+
const slugOf = (url) => {
|
|
25
|
+
const parts = pipe(url, String$1.trim, String$1.replace(GIT_SUFFIX, ""), String$1.split(SEPARATORS), Array.filter((part) => String$1.isNonEmpty(part)));
|
|
26
|
+
if (parts.length < SLUG_PARTS) return Option.none();
|
|
27
|
+
return Option.some(pipe(Array.takeRight(parts, SLUG_PARTS), Array.join("/")));
|
|
28
|
+
};
|
|
29
|
+
const linkedGitDir = Effect.fn("linkedGitDir")(function* linkedGitDir(dir, dotGit) {
|
|
30
|
+
const fs = yield* FileSystem.FileSystem;
|
|
31
|
+
const path = yield* Path.Path;
|
|
32
|
+
const text = yield* fs.readFileString(dotGit);
|
|
33
|
+
return captured(String$1.match(GITDIR)(text), "dir").pipe(Option.map((found) => path.resolve(dir, String$1.trim(found))));
|
|
34
|
+
});
|
|
35
|
+
const gitDirAt = Effect.fn("gitDirAt")(function* gitDirAt(dir) {
|
|
36
|
+
const fs = yield* FileSystem.FileSystem;
|
|
37
|
+
const dotGit = (yield* Path.Path).join(dir, ".git");
|
|
38
|
+
const info = yield* fs.stat(dotGit).pipe(Effect.option);
|
|
39
|
+
if (Option.isNone(info)) return Option.none();
|
|
40
|
+
if (info.value.type === "Directory") return Option.some(dotGit);
|
|
41
|
+
return yield* linkedGitDir(dir, dotGit);
|
|
42
|
+
});
|
|
43
|
+
const gitDirFrom = (dir) => Effect.gen(function* walk() {
|
|
44
|
+
const path = yield* Path.Path;
|
|
45
|
+
const here = yield* gitDirAt(dir);
|
|
46
|
+
const parent = path.dirname(dir);
|
|
47
|
+
if (Option.isSome(here) || parent === dir) return here;
|
|
48
|
+
return yield* gitDirFrom(parent);
|
|
49
|
+
});
|
|
50
|
+
const commonDirOf = Effect.fn("commonDirOf")(function* commonDirOf(gitDir) {
|
|
51
|
+
const fs = yield* FileSystem.FileSystem;
|
|
52
|
+
const path = yield* Path.Path;
|
|
53
|
+
const common = yield* fs.readFileString(path.join(gitDir, "commondir")).pipe(Effect.option);
|
|
54
|
+
return Option.match(common, {
|
|
55
|
+
onNone: () => gitDir,
|
|
56
|
+
onSome: (relative) => path.resolve(gitDir, String$1.trim(relative))
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
const remoteSlug = Effect.gen(function* remoteSlug() {
|
|
60
|
+
const fs = yield* FileSystem.FileSystem;
|
|
61
|
+
const path = yield* Path.Path;
|
|
62
|
+
const gitDir = yield* gitDirFrom(path.resolve("."));
|
|
63
|
+
if (Option.isNone(gitDir)) return Option.none();
|
|
64
|
+
const commonDir = yield* commonDirOf(gitDir.value);
|
|
65
|
+
const config = yield* fs.readFileString(path.join(commonDir, "config"));
|
|
66
|
+
return captured(String$1.match(ORIGIN_URL)(config), "url").pipe(Option.flatMap(slugOf));
|
|
67
|
+
}).pipe(Effect.orElseSucceed(() => Option.none()));
|
|
68
|
+
const repoOf = Effect.gen(function* repoOf() {
|
|
69
|
+
const fromActions = yield* Config.option(Config.NonEmptyString("GITHUB_REPOSITORY")).pipe(Effect.orElseSucceed(() => Option.none()));
|
|
70
|
+
if (Option.isSome(fromActions)) return fromActions;
|
|
71
|
+
return yield* remoteSlug;
|
|
72
|
+
});
|
|
73
|
+
/** @internal */
|
|
74
|
+
const appContext = Effect.gen(function* app() {
|
|
75
|
+
const context = yield* contextOf;
|
|
76
|
+
const repo = yield* repoOf;
|
|
77
|
+
return {
|
|
78
|
+
repo: Option.getOrElse(repo, () => SELF),
|
|
79
|
+
context
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
// src/features/serve-decisions/model/system-one.ts
|
|
83
|
+
const FIRST_REDIRECT = 300;
|
|
84
|
+
const RETRY_INITIAL_MS = 10;
|
|
85
|
+
const RETRY_EXPONENT = 2;
|
|
86
|
+
const Decisions = Schema.Struct({
|
|
87
|
+
model: Schema.String,
|
|
88
|
+
answers: Schema.Record(Schema.String, AnswerSchema)
|
|
89
|
+
});
|
|
90
|
+
const Envelope = Schema.Struct({ result: Decisions });
|
|
91
|
+
const ErrorMessage = Schema.Struct({ message: Schema.String });
|
|
92
|
+
const ErrorBody = Schema.Union([Schema.Struct({ errors: Schema.NonEmptyArray(ErrorMessage) }), Schema.Struct({ detail: ErrorMessage })]);
|
|
93
|
+
const decodeErrorBody = Schema.decodeUnknownOption(ErrorBody);
|
|
94
|
+
const messageOfBody = (body) => Option.match(decodeErrorBody(body), {
|
|
95
|
+
onNone: () => "request failed",
|
|
96
|
+
onSome: (decoded) => {
|
|
97
|
+
if ("detail" in decoded) return decoded.detail.message;
|
|
98
|
+
return pipe(decoded.errors, Array.map(({ message }) => message), Array.join("; "));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const failureOf = (response) => response.json.pipe(Effect.option, Effect.flatMap((body) => Effect.fail(`http ${String(response.status)}: ${messageOfBody(Option.getOrUndefined(body))}`)));
|
|
102
|
+
const decodeEnvelope = HttpClientResponse.schemaBodyJson(Envelope);
|
|
103
|
+
const decodeDecisions = HttpClientResponse.schemaBodyJson(Decisions);
|
|
104
|
+
const invalid = ({ message }) => `invalid response: ${message}`;
|
|
105
|
+
const decisionsOf = (response, envelope) => {
|
|
106
|
+
if (envelope) return decodeEnvelope(response).pipe(Effect.mapBoth({
|
|
107
|
+
onSuccess: ({ result }) => result,
|
|
108
|
+
onFailure: invalid
|
|
109
|
+
}));
|
|
110
|
+
return decodeDecisions(response).pipe(Effect.mapError(invalid));
|
|
111
|
+
};
|
|
112
|
+
/** @internal */
|
|
113
|
+
const sendSystemOne = Effect.fn("sendSystemOne")(function* sendSystemOne(call, wire) {
|
|
114
|
+
const client = (yield* HttpClient.HttpClient).pipe(HttpClient.retryTransient({
|
|
115
|
+
retryOn: "response-only",
|
|
116
|
+
schedule: Schedule.exponential(RETRY_INITIAL_MS, RETRY_EXPONENT)
|
|
117
|
+
}));
|
|
118
|
+
const response = yield* HttpClientRequest.post(call.url).pipe(HttpClientRequest.bearerToken(call.token), HttpClientRequest.setHeaders(call.headers), HttpClientRequest.bodyJsonUnsafe({
|
|
119
|
+
model: call.model,
|
|
120
|
+
state: wire.state,
|
|
121
|
+
questions: wire.questions
|
|
122
|
+
}), client.execute, Effect.mapError(({ message }) => `network: ${message}`));
|
|
123
|
+
if (response.status >= FIRST_REDIRECT) return yield* failureOf(response);
|
|
124
|
+
const decisions = yield* decisionsOf(response, call.envelope);
|
|
125
|
+
return {
|
|
126
|
+
model: decisions.model,
|
|
127
|
+
answers: decisions.answers
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
// src/features/serve-decisions/model/workers-ai.ts
|
|
131
|
+
const DEFAULT_GATEWAY = "default";
|
|
132
|
+
const DEFAULT_API_URL = "https://api.cloudflare.com/client/v4";
|
|
133
|
+
const RUN_PATH = "/ai/run";
|
|
134
|
+
const TRAILING_SLASHES$1 = /\/+$/u;
|
|
135
|
+
const MODEL_NAME = /(?<name>[^/]+)$/u;
|
|
136
|
+
const accountUrl = ({ api, account }) => `${String$1.replace(TRAILING_SLASHES$1, "")(String$1.trim(api))}/accounts/${String$1.trim(account)}`;
|
|
137
|
+
/** @internal */
|
|
138
|
+
const endpointOf = (env) => Config.all({
|
|
139
|
+
api: Config.String(envNameOf(env, "CLOUDFLARE_API_BASE_URL")).pipe(Config.withDefault(DEFAULT_API_URL)),
|
|
140
|
+
account: Config.NonEmptyString(envNameOf(env, "CLOUDFLARE_ACCOUNT_ID"))
|
|
141
|
+
}).pipe(Config.map(accountUrl));
|
|
142
|
+
const modelNameOf = (model) => Option.getOrElse(captured(String$1.match(MODEL_NAME)(model), "name"), () => model);
|
|
143
|
+
/** @internal */
|
|
144
|
+
const sendWorkersAi = Effect.fn("sendWorkersAi")(function* sendWorkersAi(endpoint, wire, { env }) {
|
|
145
|
+
const token = yield* Config.Redacted(envNameOf(env, "CLOUDFLARE_API_TOKEN"));
|
|
146
|
+
const gateway = yield* Config.NonEmptyString(envNameOf(env, "CLOUDFLARE_AI_GATEWAY_ID")).pipe(Config.withDefault(DEFAULT_GATEWAY));
|
|
147
|
+
const app = yield* appContext;
|
|
148
|
+
const decided = yield* sendSystemOne({
|
|
149
|
+
url: `${endpoint}${RUN_PATH}/${wire.model}`,
|
|
150
|
+
model: modelNameOf(wire.model),
|
|
151
|
+
token,
|
|
152
|
+
headers: {
|
|
153
|
+
"cf-aig-gateway-id": gateway,
|
|
154
|
+
"cf-aig-metadata": toJson({
|
|
155
|
+
tool: PREFIX,
|
|
156
|
+
...app
|
|
157
|
+
})
|
|
158
|
+
},
|
|
159
|
+
envelope: true
|
|
160
|
+
}, wire);
|
|
161
|
+
return {
|
|
162
|
+
model: wire.model,
|
|
163
|
+
answers: decided.answers
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
// src/features/serve-decisions/model/typesafe.ts
|
|
167
|
+
const DEFAULT_BASE_URL = "https://api.typesafe.ai";
|
|
168
|
+
const SYSTEM_ONE_PATH = "/v1/systemone";
|
|
169
|
+
const TRAILING_SLASHES = /\/+$/u;
|
|
170
|
+
/** @internal */
|
|
171
|
+
const typesafeEndpointOf = (env) => Config.String(envNameOf(env, "TYPESAFE_BASE_URL")).pipe(Config.withDefault(DEFAULT_BASE_URL), Config.map((url) => String$1.replace(TRAILING_SLASHES, "")(String$1.trim(url))));
|
|
172
|
+
/** @internal */
|
|
173
|
+
const sendTypesafe = Effect.fn("sendTypesafe")(function* sendTypesafe(endpoint, wire, { env }) {
|
|
174
|
+
const token = yield* Config.Redacted(envNameOf(env, "TYPESAFE_API_KEY"));
|
|
175
|
+
return yield* sendSystemOne({
|
|
176
|
+
url: `${endpoint}${SYSTEM_ONE_PATH}`,
|
|
177
|
+
model: wire.model,
|
|
178
|
+
token,
|
|
179
|
+
headers: {},
|
|
180
|
+
envelope: false
|
|
181
|
+
}, wire);
|
|
182
|
+
});
|
|
183
|
+
// src/features/serve-decisions/model/cache.ts
|
|
184
|
+
const DATA_FIRST_ARITY = 2;
|
|
185
|
+
const CACHE_VERSION = 7;
|
|
186
|
+
/** @internal */
|
|
187
|
+
const CACHE_DIR = `node_modules/.cache/${PREFIX}`;
|
|
188
|
+
const encodeJson = (value) => Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(value).pipe(Effect.orDie);
|
|
189
|
+
/** @internal */
|
|
190
|
+
const cacheFile = Effect.fn("cacheFile")(function* cacheFile(endpoint, request) {
|
|
191
|
+
const digest = yield* Digest.Digest;
|
|
192
|
+
const path = yield* Path.Path;
|
|
193
|
+
const json = yield* encodeJson({
|
|
194
|
+
version: CACHE_VERSION,
|
|
195
|
+
endpoint,
|
|
196
|
+
request
|
|
197
|
+
});
|
|
198
|
+
const payload = new TextEncoder().encode(json);
|
|
199
|
+
const hash = yield* digest.digestHex(Digest.sha256, payload);
|
|
200
|
+
return path.resolve(CACHE_DIR, `${hash}.json`);
|
|
201
|
+
});
|
|
202
|
+
const CachedResponse = Schema.Struct({
|
|
203
|
+
model: Schema.NonEmptyString,
|
|
204
|
+
answers: Schema.Record(Schema.String, AnswerSchema)
|
|
205
|
+
});
|
|
206
|
+
const decodeCached = Schema.decodeOption(Schema.fromJsonString(CachedResponse));
|
|
207
|
+
/** @internal */
|
|
208
|
+
const isComplete = Function.dual(DATA_FIRST_ARITY, (response, request) => Option.liftThrowable(() => parseVerdicts(response, request).complete)().pipe(Option.getOrElse(() => false)));
|
|
209
|
+
/** @internal */
|
|
210
|
+
const readCache = Effect.fn("readCache")(function* readCache(file, request) {
|
|
211
|
+
return (yield* (yield* FileSystem.FileSystem).readFileString(file).pipe(Effect.option)).pipe(Option.flatMap((raw) => decodeCached(raw)), Option.filter((response) => isComplete(response, request)));
|
|
212
|
+
});
|
|
213
|
+
/** @internal */
|
|
214
|
+
const writeCache = Effect.fn("writeCache")(function* writeCache(file, response) {
|
|
215
|
+
const fs = yield* FileSystem.FileSystem;
|
|
216
|
+
const path = yield* Path.Path;
|
|
217
|
+
const now = yield* Clock.currentTimeMillis;
|
|
218
|
+
const temp = `${file}.tmp-${String(now)}`;
|
|
219
|
+
const json = yield* encodeJson(response);
|
|
220
|
+
yield* fs.makeDirectory(path.dirname(file), { recursive: true });
|
|
221
|
+
yield* fs.writeFileString(temp, json);
|
|
222
|
+
yield* fs.rename(temp, file);
|
|
223
|
+
});
|
|
224
|
+
// src/features/serve-decisions/model/services.ts
|
|
225
|
+
const tracing = OtlpTracer.layerFromConfig({ resource: { serviceName: "oxlint-plugin-decision" } }).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));
|
|
226
|
+
/** @internal */
|
|
227
|
+
const workerServices = [
|
|
228
|
+
layer,
|
|
229
|
+
layer$1,
|
|
230
|
+
layerDigest,
|
|
231
|
+
FetchHttpClient.layer,
|
|
232
|
+
tracing
|
|
233
|
+
];
|
|
234
|
+
// src/features/serve-decisions/model/serve-decisions.ts
|
|
235
|
+
const ask = Effect.fn("ask")(function* ask(transport, endpoint, { request, timeoutMs, env }) {
|
|
236
|
+
const responses = yield* Effect.forEach(transport.wires(request), (wire) => transport.send(endpoint, wire, { env }), { concurrency: "unbounded" }).pipe(Effect.timeoutOrElse({
|
|
237
|
+
duration: timeoutMs,
|
|
238
|
+
orElse: () => Effect.fail("timeout")
|
|
239
|
+
}));
|
|
240
|
+
return mergeResponses(responses);
|
|
241
|
+
});
|
|
242
|
+
const askAndStore = Effect.fn("askAndStore")(function* askAndStore(transport, { endpoint, file }, input) {
|
|
243
|
+
const response = yield* ask(transport, endpoint, input);
|
|
244
|
+
if (isComplete(response, input.request)) yield* writeCache(file, response).pipe(Effect.ignore);
|
|
245
|
+
return response;
|
|
246
|
+
});
|
|
247
|
+
const decide = Effect.fn("decide")(function* decide(transport, input) {
|
|
248
|
+
yield* Effect.annotateCurrentSpan({ model: input.request.model });
|
|
249
|
+
const endpoint = yield* transport.endpoint(input.env);
|
|
250
|
+
const file = yield* cacheFile(endpoint, input.request);
|
|
251
|
+
const cached = yield* readCache(file, input.request);
|
|
252
|
+
yield* Effect.annotateCurrentSpan({ cached: Option.isSome(cached) });
|
|
253
|
+
if (Option.isSome(cached)) return {
|
|
254
|
+
response: cached.value,
|
|
255
|
+
cached: true
|
|
256
|
+
};
|
|
257
|
+
return {
|
|
258
|
+
response: yield* askAndStore(transport, {
|
|
259
|
+
endpoint,
|
|
260
|
+
file
|
|
261
|
+
}, input),
|
|
262
|
+
cached: false
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
const reasonOf = (error) => {
|
|
266
|
+
if (typeof error === "string") return error;
|
|
267
|
+
return messageOf(error);
|
|
268
|
+
};
|
|
269
|
+
const decideOne = (transport, input) => decide(transport, input).pipe(Effect.match({
|
|
270
|
+
onSuccess: ({ response, cached }) => ({
|
|
271
|
+
ok: true,
|
|
272
|
+
response,
|
|
273
|
+
cached
|
|
274
|
+
}),
|
|
275
|
+
onFailure: (error) => ({
|
|
276
|
+
ok: false,
|
|
277
|
+
reason: reasonOf(error)
|
|
278
|
+
})
|
|
279
|
+
}));
|
|
280
|
+
const decideEach = (transport, inputs) => Effect.all(pipe(inputs, Array.map((input) => decideOne(transport, input))), { concurrency: "unbounded" }).pipe(Effect.provide(workerServices));
|
|
281
|
+
/** @internal */
|
|
282
|
+
const serveDecisions = (transport) => {
|
|
283
|
+
runAsWorker((inputs) => Effect.runPromise(decideEach(transport, inputs)));
|
|
284
|
+
};
|
|
285
|
+
export { sendWorkersAi as a, endpointOf as i, sendTypesafe as n, typesafeEndpointOf as r, serveDecisions as t };
|
|
286
|
+
|
|
287
|
+
//# sourceMappingURL=serve-decisions-DYGwLMft.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-decisions-DYGwLMft.mjs","names":["Str","Arr","Arr","TRAILING_SLASHES","Str","Str","Fn","fileSystem","path","Arr"],"sources":["../src/features/serve-decisions/model/app-context.ts","../src/features/serve-decisions/model/system-one.ts","../src/features/serve-decisions/model/workers-ai.ts","../src/features/serve-decisions/model/typesafe.ts","../src/features/serve-decisions/model/cache.ts","../src/features/serve-decisions/model/services.ts","../src/features/serve-decisions/model/serve-decisions.ts"],"sourcesContent":["import {\n Array as Arr,\n Config,\n Effect,\n FileSystem,\n Option,\n Path,\n String as Str,\n pipe,\n} from \"effect\";\nimport type { PlatformError } from \"effect/PlatformError\";\n\nimport { captured } from \"#/entities/decision/index.ts\";\n\nconst SELF = \"masseater/masseater.dev\";\nconst GIT_SUFFIX = /\\.git\\/?$/u;\nconst SEPARATORS = /[/:]/u;\nconst SLUG_PARTS = 2;\nconst GITDIR = /^gitdir:\\s*(?<dir>.+)$/mu;\nconst ORIGIN_URL = /\\[remote \"origin\"\\][^[]*?\\burl\\s*=\\s*(?<url>\\S+)/u;\n\nconst isSet = (name: string): Effect.Effect<boolean> =>\n Config.option(Config.NonEmptyString(name)).pipe(\n Effect.map(Option.isSome),\n Effect.orElseSucceed(() => false),\n );\n\nconst contextOf = Effect.gen(function* contextOf() {\n if (yield* isSet(\"GITHUB_ACTIONS\")) {\n return \"github-actions\";\n }\n if (yield* isSet(\"CLAUDE_CODE_REMOTE\")) {\n return \"claude-code-cloud\";\n }\n if (yield* isSet(\"CLAUDECODE\")) {\n return \"claude-code\";\n }\n return \"local\";\n});\n\nconst slugOf = (url: string): Option.Option<string> => {\n const parts = pipe(\n url,\n Str.trim,\n Str.replace(GIT_SUFFIX, \"\"),\n Str.split(SEPARATORS),\n Arr.filter((part) => Str.isNonEmpty(part)),\n );\n if (parts.length < SLUG_PARTS) {\n return Option.none();\n }\n return Option.some(pipe(Arr.takeRight(parts, SLUG_PARTS), Arr.join(\"/\")));\n};\n\nconst linkedGitDir = Effect.fn(\"linkedGitDir\")(function* linkedGitDir(dir: string, dotGit: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const text = yield* fs.readFileString(dotGit);\n return captured(Str.match(GITDIR)(text), \"dir\").pipe(\n Option.map((found) => path.resolve(dir, Str.trim(found))),\n );\n});\n\n/** @internal */\nexport type AppServices = FileSystem.FileSystem | Path.Path;\n\nconst gitDirAt = Effect.fn(\"gitDirAt\")(function* gitDirAt(dir: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const dotGit = path.join(dir, \".git\");\n const info = yield* fs.stat(dotGit).pipe(Effect.option);\n if (Option.isNone(info)) {\n return Option.none<string>();\n }\n if (info.value.type === \"Directory\") {\n return Option.some(dotGit);\n }\n return yield* linkedGitDir(dir, dotGit);\n});\n\nconst gitDirFrom = (\n dir: string,\n): Effect.Effect<Option.Option<string>, PlatformError, AppServices> =>\n Effect.gen(function* walk() {\n const path = yield* Path.Path;\n const here = yield* gitDirAt(dir);\n const parent = path.dirname(dir);\n if (Option.isSome(here) || parent === dir) {\n return here;\n }\n return yield* gitDirFrom(parent);\n });\n\nconst commonDirOf = Effect.fn(\"commonDirOf\")(function* commonDirOf(gitDir: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const common = yield* fs.readFileString(path.join(gitDir, \"commondir\")).pipe(Effect.option);\n return Option.match(common, {\n onNone: () => gitDir,\n onSome: (relative) => path.resolve(gitDir, Str.trim(relative)),\n });\n});\n\nconst remoteSlug = Effect.gen(function* remoteSlug() {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const gitDir = yield* gitDirFrom(path.resolve(\".\"));\n if (Option.isNone(gitDir)) {\n return Option.none<string>();\n }\n const commonDir = yield* commonDirOf(gitDir.value);\n const config = yield* fs.readFileString(path.join(commonDir, \"config\"));\n return captured(Str.match(ORIGIN_URL)(config), \"url\").pipe(Option.flatMap(slugOf));\n}).pipe(Effect.orElseSucceed(() => Option.none<string>()));\n\nconst repoOf = Effect.gen(function* repoOf() {\n const fromActions = yield* Config.option(Config.NonEmptyString(\"GITHUB_REPOSITORY\")).pipe(\n Effect.orElseSucceed(() => Option.none<string>()),\n );\n if (Option.isSome(fromActions)) {\n return fromActions;\n }\n return yield* remoteSlug;\n});\n\n/** @internal */\nexport interface AppContext {\n readonly repo: string;\n readonly context: string;\n}\n\n/** @internal */\nexport const appContext: Effect.Effect<AppContext, never, AppServices> = Effect.gen(\n function* app() {\n const context = yield* contextOf;\n const repo = yield* repoOf;\n return { repo: Option.getOrElse(repo, () => SELF), context };\n },\n);\n","import { Array as Arr, Effect, Option, Schedule, Schema, pipe } from \"effect\";\nimport type { Redacted } from \"effect\";\nimport { HttpClient, HttpClientRequest, HttpClientResponse } from \"effect/http\";\n\nimport { AnswerSchema } from \"#/entities/decision/index.ts\";\nimport type { DecisionResponse, WireRequest } from \"#/entities/decision/index.ts\";\n\nconst FIRST_REDIRECT = 300;\nconst RETRY_INITIAL_MS = 10;\nconst RETRY_EXPONENT = 2;\n\nconst Decisions = Schema.Struct({\n model: Schema.String,\n answers: Schema.Record(Schema.String, AnswerSchema),\n});\n\nconst Envelope = Schema.Struct({ result: Decisions });\n\nconst ErrorMessage = Schema.Struct({ message: Schema.String });\n\nconst ErrorBody = Schema.Union([\n Schema.Struct({ errors: Schema.NonEmptyArray(ErrorMessage) }),\n Schema.Struct({ detail: ErrorMessage }),\n]);\n\nconst decodeErrorBody = Schema.decodeUnknownOption(ErrorBody);\n\nconst messageOfBody = (body: unknown): string =>\n Option.match(decodeErrorBody(body), {\n onNone: () => \"request failed\",\n onSome: (decoded) => {\n if (\"detail\" in decoded) {\n return decoded.detail.message;\n }\n return pipe(\n decoded.errors,\n Arr.map(({ message }) => message),\n Arr.join(\"; \"),\n );\n },\n });\n\nconst failureOf = (response: HttpClientResponse.HttpClientResponse): Effect.Effect<never, string> =>\n response.json.pipe(\n Effect.option,\n Effect.flatMap((body) =>\n Effect.fail(`http ${String(response.status)}: ${messageOfBody(Option.getOrUndefined(body))}`),\n ),\n );\n\n/** @internal */\nexport interface SystemOneCall {\n readonly url: string;\n readonly model: string;\n readonly token: Redacted.Redacted;\n readonly headers: Readonly<Record<string, string>>;\n readonly envelope: boolean;\n}\n\nconst decodeEnvelope = HttpClientResponse.schemaBodyJson(Envelope);\n\nconst decodeDecisions = HttpClientResponse.schemaBodyJson(Decisions);\n\nconst invalid = ({ message }: Readonly<{ message: string }>): string =>\n `invalid response: ${message}`;\n\nconst decisionsOf = (\n response: HttpClientResponse.HttpClientResponse,\n envelope: boolean,\n): Effect.Effect<typeof Decisions.Type, string> => {\n if (envelope) {\n return decodeEnvelope(response).pipe(\n Effect.mapBoth({ onSuccess: ({ result }) => result, onFailure: invalid }),\n );\n }\n return decodeDecisions(response).pipe(Effect.mapError(invalid));\n};\n\n/** @internal */\nexport const sendSystemOne = Effect.fn(\"sendSystemOne\")(function* sendSystemOne(\n call: SystemOneCall,\n wire: WireRequest,\n) {\n const client = (yield* HttpClient.HttpClient).pipe(\n HttpClient.retryTransient({\n retryOn: \"response-only\",\n schedule: Schedule.exponential(RETRY_INITIAL_MS, RETRY_EXPONENT),\n }),\n );\n const response = yield* HttpClientRequest.post(call.url).pipe(\n HttpClientRequest.bearerToken(call.token),\n HttpClientRequest.setHeaders(call.headers),\n HttpClientRequest.bodyJsonUnsafe({\n model: call.model,\n state: wire.state,\n questions: wire.questions,\n }),\n client.execute,\n Effect.mapError(({ message }) => `network: ${message}`),\n );\n if (response.status >= FIRST_REDIRECT) {\n return yield* failureOf(response);\n }\n const decisions = yield* decisionsOf(response, call.envelope);\n return { model: decisions.model, answers: decisions.answers } satisfies DecisionResponse;\n});\n","import { Config, Effect, Option, String as Str } from \"effect\";\n\nimport { PREFIX, captured, envNameOf, toJson } from \"#/entities/decision/index.ts\";\nimport type { DecideInput, WireRequest } from \"#/entities/decision/index.ts\";\n\nimport { appContext } from \"./app-context.ts\";\nimport { sendSystemOne } from \"./system-one.ts\";\n\nconst DEFAULT_GATEWAY = \"default\";\nconst DEFAULT_API_URL = \"https://api.cloudflare.com/client/v4\";\nconst RUN_PATH = \"/ai/run\";\nconst TRAILING_SLASHES = /\\/+$/u;\nconst MODEL_NAME = /(?<name>[^/]+)$/u;\n\nconst accountUrl = ({ api, account }: Readonly<{ api: string; account: string }>): string =>\n `${Str.replace(TRAILING_SLASHES, \"\")(Str.trim(api))}/accounts/${Str.trim(account)}`;\n\n/** @internal */\nexport const endpointOf = (env: DecideInput[\"env\"]): Config.Config<string> =>\n Config.all({\n api: Config.String(envNameOf(env, \"CLOUDFLARE_API_BASE_URL\")).pipe(\n Config.withDefault(DEFAULT_API_URL),\n ),\n account: Config.NonEmptyString(envNameOf(env, \"CLOUDFLARE_ACCOUNT_ID\")),\n }).pipe(Config.map(accountUrl));\n\nconst modelNameOf = (model: string): string =>\n Option.getOrElse(captured(Str.match(MODEL_NAME)(model), \"name\"), () => model);\n\n/** @internal */\nexport const sendWorkersAi = Effect.fn(\"sendWorkersAi\")(function* sendWorkersAi(\n endpoint: string,\n wire: WireRequest,\n { env }: Pick<DecideInput, \"env\">,\n) {\n const token = yield* Config.Redacted(envNameOf(env, \"CLOUDFLARE_API_TOKEN\"));\n const gateway = yield* Config.NonEmptyString(envNameOf(env, \"CLOUDFLARE_AI_GATEWAY_ID\")).pipe(\n Config.withDefault(DEFAULT_GATEWAY),\n );\n const app = yield* appContext;\n const decided = yield* sendSystemOne(\n {\n url: `${endpoint}${RUN_PATH}/${wire.model}`,\n model: modelNameOf(wire.model),\n token,\n headers: {\n \"cf-aig-gateway-id\": gateway,\n \"cf-aig-metadata\": toJson({ tool: PREFIX, ...app }),\n },\n envelope: true,\n },\n wire,\n );\n return { model: wire.model, answers: decided.answers };\n});\n","import { Config, Effect, String as Str } from \"effect\";\n\nimport { envNameOf } from \"#/entities/decision/index.ts\";\nimport type { DecideInput, WireRequest } from \"#/entities/decision/index.ts\";\n\nimport { sendSystemOne } from \"./system-one.ts\";\n\nconst DEFAULT_BASE_URL = \"https://api.typesafe.ai\";\nconst SYSTEM_ONE_PATH = \"/v1/systemone\";\nconst TRAILING_SLASHES = /\\/+$/u;\n\n/** @internal */\nexport const typesafeEndpointOf = (env: DecideInput[\"env\"]): Config.Config<string> =>\n Config.String(envNameOf(env, \"TYPESAFE_BASE_URL\")).pipe(\n Config.withDefault(DEFAULT_BASE_URL),\n Config.map((url) => Str.replace(TRAILING_SLASHES, \"\")(Str.trim(url))),\n );\n\n/** @internal */\nexport const sendTypesafe = Effect.fn(\"sendTypesafe\")(function* sendTypesafe(\n endpoint: string,\n wire: WireRequest,\n { env }: Pick<DecideInput, \"env\">,\n) {\n const token = yield* Config.Redacted(envNameOf(env, \"TYPESAFE_API_KEY\"));\n return yield* sendSystemOne(\n {\n url: `${endpoint}${SYSTEM_ONE_PATH}`,\n model: wire.model,\n token,\n headers: {},\n envelope: false,\n },\n wire,\n );\n});\n","import { Clock, Effect, FileSystem, Option, Path, Schema, Function as Fn } from \"effect\";\nimport { Digest } from \"effect/crypto\";\n\nimport { AnswerSchema, PREFIX, parseVerdicts } from \"#/entities/decision/index.ts\";\nimport type { DecisionRequest, DecisionResponse } from \"#/entities/decision/index.ts\";\n\nconst DATA_FIRST_ARITY = 2;\n\nconst CACHE_VERSION = 7;\n/** @internal */\nexport const CACHE_DIR = `node_modules/.cache/${PREFIX}`;\n\nconst encodeJson = (value: unknown): Effect.Effect<string> =>\n Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(value).pipe(Effect.orDie);\n\n/** @internal */\nexport const cacheFile = Effect.fn(\"cacheFile\")(function* cacheFile(\n endpoint: string,\n request: DecisionRequest,\n) {\n const digest = yield* Digest.Digest;\n const path = yield* Path.Path;\n const json = yield* encodeJson({ version: CACHE_VERSION, endpoint, request });\n const payload = new TextEncoder().encode(json);\n const hash = yield* digest.digestHex(Digest.sha256, payload);\n return path.resolve(CACHE_DIR, `${hash}.json`);\n});\n\nconst CachedResponse = Schema.Struct({\n model: Schema.NonEmptyString,\n answers: Schema.Record(Schema.String, AnswerSchema),\n});\n\nconst decodeCached = Schema.decodeOption(Schema.fromJsonString(CachedResponse));\n\n/** @internal */\nexport const isComplete: {\n (request: DecisionRequest): (response: DecisionResponse) => boolean;\n (response: DecisionResponse, request: DecisionRequest): boolean;\n} = Fn.dual(DATA_FIRST_ARITY, (response: DecisionResponse, request: DecisionRequest): boolean =>\n Option.liftThrowable(() => parseVerdicts(response, request).complete)().pipe(\n Option.getOrElse(() => false),\n ),\n);\n\n/** @internal */\nexport const readCache = Effect.fn(\"readCache\")(function* readCache(\n file: string,\n request: DecisionRequest,\n) {\n const fs = yield* FileSystem.FileSystem;\n const text = yield* fs.readFileString(file).pipe(Effect.option);\n return text.pipe(\n Option.flatMap((raw): Option.Option<DecisionResponse> => decodeCached(raw)),\n Option.filter((response) => isComplete(response, request)),\n );\n});\n\n/** @internal */\nexport const writeCache = Effect.fn(\"writeCache\")(function* writeCache(\n file: string,\n response: DecisionResponse,\n) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const now = yield* Clock.currentTimeMillis;\n const temp = `${file}.tmp-${String(now)}`;\n const json = yield* encodeJson(response);\n yield* fs.makeDirectory(path.dirname(file), { recursive: true });\n yield* fs.writeFileString(temp, json);\n yield* fs.rename(temp, file);\n});\n\n/** @internal */\nexport type CacheServices = Digest.Digest | FileSystem.FileSystem | Path.Path;\n","import { layerDigest } from \"@effect/platform-node-shared/NodeCrypto\";\nimport { layer as fileSystem } from \"@effect/platform-node-shared/NodeFileSystem\";\nimport { layer as path } from \"@effect/platform-node-shared/NodePath\";\nimport { Layer } from \"effect\";\nimport { FetchHttpClient } from \"effect/http\";\nimport { OtlpSerialization, OtlpTracer } from \"effect/observability\";\n\nconst tracing = OtlpTracer.layerFromConfig({\n resource: { serviceName: \"oxlint-plugin-decision\" },\n}).pipe(Layer.provide(OtlpSerialization.layerJson), Layer.provide(FetchHttpClient.layer));\n\n/** @internal */\nexport const workerServices: [\n typeof fileSystem,\n typeof path,\n typeof layerDigest,\n typeof FetchHttpClient.layer,\n typeof tracing,\n] = [fileSystem, path, layerDigest, FetchHttpClient.layer, tracing];\n","import { Array as Arr, Effect, Option, pipe } from \"effect\";\nimport type { Config } from \"effect\";\nimport type { HttpClient } from \"effect/http\";\nimport { runAsWorker } from \"synckit\";\n\nimport { mergeResponses, messageOf } from \"#/entities/decision/index.ts\";\nimport type {\n DecideInput,\n DecideResult,\n DecisionRequest,\n DecisionResponse,\n WireRequest,\n} from \"#/entities/decision/index.ts\";\n\nimport type { AppServices } from \"./app-context.ts\";\nimport { cacheFile, isComplete, readCache, writeCache } from \"./cache.ts\";\nimport type { CacheServices } from \"./cache.ts\";\nimport { workerServices } from \"./services.ts\";\n\n/** @internal */\nexport type Services = AppServices | CacheServices | HttpClient.HttpClient;\n\ntype Inputs = Arr.NonEmptyReadonlyArray<DecideInput>;\n\n/** @internal */\nexport interface Transport {\n readonly endpoint: (env: DecideInput[\"env\"]) => Config.Config<string>;\n readonly wires: (request: DecisionRequest) => Arr.NonEmptyReadonlyArray<WireRequest>;\n readonly send: (\n endpoint: string,\n wire: WireRequest,\n input: Pick<DecideInput, \"env\">,\n ) => Effect.Effect<DecisionResponse, Config.ConfigError | string, Services>;\n}\n\nconst ask = Effect.fn(\"ask\")(function* ask(\n transport: Transport,\n endpoint: string,\n { request, timeoutMs, env }: DecideInput,\n) {\n const responses = yield* Effect.forEach(\n transport.wires(request),\n (wire) => transport.send(endpoint, wire, { env }),\n { concurrency: \"unbounded\" },\n ).pipe(\n Effect.timeoutOrElse({\n duration: timeoutMs,\n orElse: () => Effect.fail(\"timeout\"),\n }),\n );\n return mergeResponses(responses);\n});\n\nconst askAndStore = Effect.fn(\"askAndStore\")(function* askAndStore(\n transport: Transport,\n { endpoint, file }: Readonly<{ endpoint: string; file: string }>,\n input: DecideInput,\n) {\n const response = yield* ask(transport, endpoint, input);\n if (isComplete(response, input.request)) {\n yield* writeCache(file, response).pipe(Effect.ignore);\n }\n return response;\n});\n\nconst decide = Effect.fn(\"decide\")(function* decide(transport: Transport, input: DecideInput) {\n yield* Effect.annotateCurrentSpan({ model: input.request.model });\n const endpoint = yield* transport.endpoint(input.env);\n const file = yield* cacheFile(endpoint, input.request);\n const cached = yield* readCache(file, input.request);\n yield* Effect.annotateCurrentSpan({ cached: Option.isSome(cached) });\n if (Option.isSome(cached)) {\n return { response: cached.value, cached: true };\n }\n return { response: yield* askAndStore(transport, { endpoint, file }, input), cached: false };\n});\n\nconst reasonOf = (error: unknown): string => {\n if (typeof error === \"string\") {\n return error;\n }\n return messageOf(error);\n};\n\nconst decideOne = (\n transport: Transport,\n input: DecideInput,\n): Effect.Effect<DecideResult, never, Services> =>\n decide(transport, input).pipe(\n Effect.match({\n onSuccess: ({ response, cached }): DecideResult => ({ ok: true, response, cached }),\n onFailure: (error): DecideResult => ({ ok: false, reason: reasonOf(error) }),\n }),\n );\n\nconst decideEach = (\n transport: Transport,\n inputs: Inputs,\n): Effect.Effect<Arr.NonEmptyReadonlyArray<DecideResult>> =>\n Effect.all(\n pipe(\n inputs,\n Arr.map((input) => decideOne(transport, input)),\n ),\n { concurrency: \"unbounded\" },\n ).pipe(Effect.provide(workerServices));\n\n/** @internal */\nexport const serveDecisions = (transport: Transport): void => {\n runAsWorker((inputs: Inputs): Promise<Arr.NonEmptyReadonlyArray<DecideResult>> =>\n Effect.runPromise(decideEach(transport, inputs)),\n );\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,OAAO;AACb,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,SAAS;AACf,MAAM,aAAa;AAEnB,MAAM,SAAS,SACb,OAAO,OAAO,OAAO,eAAe,IAAI,CAAC,CAAC,CAAC,KACzC,OAAO,IAAI,OAAO,MAAM,GACxB,OAAO,oBAAoB,KAAK,CAClC;AAEF,MAAM,YAAY,OAAO,IAAI,UAAU,YAAY;CACjD,IAAI,OAAO,MAAM,gBAAgB,GAC/B,OAAO;CAET,IAAI,OAAO,MAAM,oBAAoB,GACnC,OAAO;CAET,IAAI,OAAO,MAAM,YAAY,GAC3B,OAAO;CAET,OAAO;AACT,CAAC;AAED,MAAM,UAAU,QAAuC;CACrD,MAAM,QAAQ,KACZ,KACAA,SAAI,MACJA,SAAI,QAAQ,YAAY,EAAE,GAC1BA,SAAI,MAAM,UAAU,GACpBC,MAAI,QAAQ,SAASD,SAAI,WAAW,IAAI,CAAC,CAC3C;CACA,IAAI,MAAM,SAAS,YACjB,OAAO,OAAO,KAAK;CAErB,OAAO,OAAO,KAAK,KAAKC,MAAI,UAAU,OAAO,UAAU,GAAGA,MAAI,KAAK,GAAG,CAAC,CAAC;AAC1E;AAEA,MAAM,eAAe,OAA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AAO;EAAO,QAAQ;CAAK;CAEhD,OAAO;EAAE,UAAU,OAAO,YAAY,WAAW;GAAE;GAAU;EAAK,GAAG,KAAK;EAAG,QAAQ;CAAM;AAC7F,CAAC;AAED,MAAM,YAAY,UAA2B;CAC3C,IAAI,OAAO,UAAU,UACnB,OAAO;CAET,OAAO,UAAU,KAAK;AACxB;AAEA,MAAM,aACJ,WACA,UAEA,OAAO,WAAW,KAAK,CAAC,CAAC,KACvB,OAAO,MAAM;CACX,YAAY,EAAE,UAAU,cAA4B;EAAE,IAAI;EAAM;EAAU;CAAO;CACjF,YAAY,WAAyB;EAAE,IAAI;EAAO,QAAQ,SAAS,KAAK;CAAE;AAC5E,CAAC,CACH;AAEF,MAAM,cACJ,WACA,WAEA,OAAO,IACL,KACE,QACAC,MAAI,KAAK,UAAU,UAAU,WAAW,KAAK,CAAC,CAChD,GACA,EAAE,aAAa,YAAY,CAC7B,CAAC,CAAC,KAAK,OAAO,QAAQ,cAAc,CAAC;;AAGvC,MAAa,kBAAkB,cAA+B;CAC5D,aAAa,WACX,OAAO,WAAW,WAAW,WAAW,MAAM,CAAC,CACjD;AACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as fileRequestsFor } from "./decision-B7hahWHz.mjs";
|
|
2
|
+
import { n as sendTypesafe, r as typesafeEndpointOf, t as serveDecisions } from "./serve-decisions-DYGwLMft.mjs";
|
|
3
|
+
// src/app/typesafe-worker.ts
|
|
4
|
+
serveDecisions({
|
|
5
|
+
endpoint: typesafeEndpointOf,
|
|
6
|
+
wires: fileRequestsFor,
|
|
7
|
+
send: sendTypesafe
|
|
8
|
+
});
|
|
9
|
+
export {};
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=typesafe-worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typesafe-worker.mjs","names":[],"sources":["../src/app/typesafe-worker.ts"],"sourcesContent":["import { fileRequestsFor } from \"#/entities/decision/index.ts\";\nimport {\n sendTypesafe,\n serveDecisions,\n typesafeEndpointOf,\n} from \"#/features/serve-decisions/index.ts\";\n\nserveDecisions({\n endpoint: typesafeEndpointOf,\n wires: fileRequestsFor,\n send: sendTypesafe,\n});\n"],"mappings":";;;AAOA,eAAe;CACb,UAAU;CACV,OAAO;CACP,MAAM;AACR,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@r_masseater/oxlint-plugin-decision",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Oxlint JS plugin that lints code with plain-English rules answered by models on
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Oxlint JS plugin that lints code with plain-English rules answered by decision models: Clef on Workers AI or Jev on the Typesafe System One API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-gateway",
|
|
7
7
|
"cloudflare",
|
|
8
8
|
"decision-model",
|
|
9
9
|
"lint",
|
|
10
|
-
"openrouter",
|
|
11
10
|
"oxlint",
|
|
12
11
|
"oxlint-plugin",
|
|
13
12
|
"preset",
|
|
14
|
-
"tanstack-intent"
|
|
13
|
+
"tanstack-intent",
|
|
14
|
+
"typesafe"
|
|
15
15
|
],
|
|
16
16
|
"homepage": "https://github.com/masseater/masseater.dev/tree/main/libs/oxlint-plugin-decision#readme",
|
|
17
17
|
"bugs": {
|
|
@@ -29,18 +29,14 @@
|
|
|
29
29
|
],
|
|
30
30
|
"type": "module",
|
|
31
31
|
"imports": {
|
|
32
|
-
"#
|
|
33
|
-
"
|
|
32
|
+
"#example-presets/*": "./example-presets/*",
|
|
33
|
+
"#/*": "./src/*"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
|
37
37
|
"types": "./dist/index.d.mts",
|
|
38
38
|
"default": "./dist/index.mjs"
|
|
39
39
|
},
|
|
40
|
-
"./openrouter-app": {
|
|
41
|
-
"types": "./dist/openrouter-app.d.mts",
|
|
42
|
-
"default": "./dist/openrouter-app.mjs"
|
|
43
|
-
},
|
|
44
40
|
"./presets": {
|
|
45
41
|
"types": "./dist/presets/index.d.mts",
|
|
46
42
|
"default": "./dist/presets/index.mjs"
|
|
@@ -68,13 +64,12 @@
|
|
|
68
64
|
"provenance": true
|
|
69
65
|
},
|
|
70
66
|
"dependencies": {
|
|
71
|
-
"@effect/ai-openrouter": "4.1.4",
|
|
72
67
|
"synckit": "0.12.3"
|
|
73
68
|
},
|
|
74
69
|
"devDependencies": {
|
|
75
70
|
"@effect/platform-node": "4.1.4",
|
|
76
71
|
"@effect/platform-node-shared": "4.1.4",
|
|
77
|
-
"@effect/tsgo": "0.
|
|
72
|
+
"@effect/tsgo": "0.69.0",
|
|
78
73
|
"@effect/vitest": "4.1.4",
|
|
79
74
|
"@oxlint/plugins": "1.93.0",
|
|
80
75
|
"@types/node": "26.6.6",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: write-decision-rules
|
|
3
3
|
description: >
|
|
4
4
|
Use when writing, wiring up, or debugging lint rules for @r_masseater/oxlint-plugin-decision: rules
|
|
5
|
-
phrased as plain-English questions that models on
|
|
5
|
+
phrased as plain-English questions that decision models on Workers AI or the Typesafe API answer about functions, calls,
|
|
6
6
|
JSX elements, or whole files in an Oxlint run. Covers defineDecisionRule, createDecisionPlugin,
|
|
7
7
|
enabling the rules in oxlint.config.ts, select, answer kinds, context, per-rule models, settings,
|
|
8
8
|
explain mode, and keeping request cost under control. Also use when someone wants a lint check
|
|
@@ -20,8 +20,8 @@ sources:
|
|
|
20
20
|
- src/**
|
|
21
21
|
- README.md
|
|
22
22
|
- example/**
|
|
23
|
-
- src/skill-write-decision-rules.task.md
|
|
24
|
-
- src/skill-write-decision-rules.test.ts
|
|
23
|
+
- src/app/skill-write-decision-rules.task.md
|
|
24
|
+
- src/app/skill-write-decision-rules.test.ts
|
|
25
25
|
---
|
|
26
26
|
|
|
27
27
|
# write-decision-rules
|
|
@@ -38,7 +38,7 @@ The package root ships no rules; the ready-made ones are under `/presets`. You w
|
|
|
38
38
|
export CLOUDFLARE_API_TOKEN="..." # account API token with Workers AI Read
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
Result: `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` are set in the shell that runs oxlint. The default model runs on Workers AI
|
|
41
|
+
Result: `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` are set in the shell that runs oxlint. The default model, `cloudflare/@cf/cloudflare/clef-flash`, runs on Workers AI. `typesafe/jev-...` models read `TYPESAFE_API_KEY` instead. Without it the plugin warns once and reports nothing outside CI, and fails the run in CI.
|
|
42
42
|
|
|
43
43
|
2. Write a plugin file that default-exports `createDecisionPlugin`.
|
|
44
44
|
|
|
@@ -165,20 +165,20 @@ A `"file"` rule can add `location: { question, cutoff }`. It moves the diagnosti
|
|
|
165
165
|
|
|
166
166
|
Settings apply to the whole plugin. Pass them to `createDecisionPlugin` or put them under `settings.<plugin name>` in `oxlint.config.ts`. The config file wins.
|
|
167
167
|
|
|
168
|
-
| Setting | Default
|
|
169
|
-
| ----------------- |
|
|
170
|
-
| `model` | `"cloudflare/@cf/
|
|
171
|
-
| `ci` | `"fail"`
|
|
172
|
-
| `timeoutMs` | `10000`
|
|
173
|
-
| `maxSnippetChars` | `4000`
|
|
174
|
-
| `env` | `{}`
|
|
175
|
-
| `explain` | `false`
|
|
168
|
+
| Setting | Default | Meaning |
|
|
169
|
+
| ----------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
170
|
+
| `model` | `"cloudflare/@cf/cloudflare/clef-flash"` | A decision model id (Clef or Jev), or a list; every listed model answers every match. |
|
|
171
|
+
| `ci` | `"fail"` | When `CI` is set and a model can't be asked: `"fail"` fails the run, `"skip"` warns. A spent budget only warns. |
|
|
172
|
+
| `timeoutMs` | `10000` | Per-file budget shared by every request, retry, and location refinement. |
|
|
173
|
+
| `maxSnippetChars` | `4000` | Longer snippets are cut and end with `/* ...truncated */`. |
|
|
174
|
+
| `env` | `{}` | Renames variables providers read, e.g. `{ CLOUDFLARE_API_TOKEN: "TEAM_KEY" }`. Names only. |
|
|
175
|
+
| `explain` | `false` | `true`/`"text"` or `"json"` prints why each match was or wasn't reported, to stderr. |
|
|
176
176
|
|
|
177
|
-
A rule's model comes from the first source that sets one. The rule's options in `oxlint.config.ts` come first, such as `["warn", { model: "
|
|
177
|
+
A rule's model comes from the first source that sets one. The rule's options in `oxlint.config.ts` come first, such as `["warn", { model: "typesafe/jev-latest" }]`. Next comes the rule's own `model`, and then `settings.<plugin name>.model`. After that comes the `model` passed to `createDecisionPlugin`. The default comes last.
|
|
178
178
|
|
|
179
179
|
When tuning a question or cutoff, or switching models, read [tuning rules](references/tuning.md) first.
|
|
180
180
|
|
|
181
|
-
|
|
181
|
+
The plugin asks only Clef and Jev. Other models and custom providers are refused.
|
|
182
182
|
|
|
183
183
|
## Common Mistakes
|
|
184
184
|
|
|
@@ -196,7 +196,8 @@ createDecisionPlugin({
|
|
|
196
196
|
});
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
-
Keys are read only from environment variables
|
|
199
|
+
Keys are read only from environment variables, and `env` values are variable names, not keys.
|
|
200
|
+
See `options.ts` and `runtime.ts` in `src/entities/decision/model/`.
|
|
200
201
|
|
|
201
202
|
### HIGH: a broad target on a whole codebase
|
|
202
203
|
|
|
@@ -226,10 +227,10 @@ Asking whether a function is named well reports the well-named functions. With t
|
|
|
226
227
|
|
|
227
228
|
### MEDIUM: rule ids that are not lowercase-hyphenated or are repeated
|
|
228
229
|
|
|
229
|
-
`id` must match `^[a-z0-9]+(?:-[a-z0-9]+)*$` and be unique within the plugin. `rules` must list at least one rule. Otherwise loading the plugin throws (`src/options.ts`).
|
|
230
|
+
`id` must match `^[a-z0-9]+(?:-[a-z0-9]+)*$` and be unique within the plugin. `rules` must list at least one rule. Otherwise loading the plugin throws (`src/entities/decision/model/options.ts`).
|
|
230
231
|
|
|
231
232
|
## Completion
|
|
232
233
|
|
|
233
|
-
1. Run `npx oxlint` (or the CI overlay) on a file that should fail and one that should pass. Result: the failing file gets a diagnostic like `[no-pii-in-logs]
|
|
234
|
+
1. Run `npx oxlint` (or the CI overlay) on a file that should fail and one that should pass. Result: the failing file gets a diagnostic like `[no-pii-in-logs] cloudflare/... answered yes (0.93 >= 0.80): ...`. The passing file gets none.
|
|
234
235
|
2. If nothing is reported, run once with `OXLINT_DECISION_EXPLAIN=1` and check stderr. A missing match means the target, `select` or `context: { scope: "comment" }` excluded it. An `error` line means the key, timeout or API failed. A low probability means the question or cutoff needs tuning (see [tuning rules](references/tuning.md)).
|
|
235
236
|
3. If the plugin fails to load, fix the rule or setting the thrown error names; do not remove validation.
|
|
@@ -21,9 +21,7 @@ A changed question, snippet, context, or answer kind re-asks that file. A change
|
|
|
21
21
|
|
|
22
22
|
Probabilities are not calibrated the same across models. Re-tune cutoffs after switching, and pin a versioned model id once tuned.
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
You can override one rule's model in `oxlint.config.ts` without touching the plugin file. For example, write `"team/stale-comment": ["warn", { model: "openrouter/~typesafe/jev-latest" }]`. Rules on different models are asked in separate requests and cached separately.
|
|
24
|
+
You can override one rule's model in `oxlint.config.ts` without touching the plugin file. For example, write `"team/stale-comment": ["warn", { model: "typesafe/jev-latest" }]`. Rules on different models are asked in separate requests and cached separately.
|
|
27
25
|
|
|
28
26
|
## Cache
|
|
29
27
|
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Effect, FileSystem, Path } from "effect";
|
|
2
|
-
/** @internal */
|
|
3
|
-
export type AppServices = FileSystem.FileSystem | Path.Path;
|
|
4
|
-
/** @internal */
|
|
5
|
-
export interface AppContext {
|
|
6
|
-
readonly repo: string;
|
|
7
|
-
readonly context: string;
|
|
8
|
-
}
|
|
9
|
-
/** @internal */
|
|
10
|
-
export declare const appContext: Effect.Effect<AppContext, never, AppServices>;
|
|
11
|
-
/** @internal */
|
|
12
|
-
export type OpenRouterApp = Readonly<Record<"HTTP-Referer" | "X-OpenRouter-Title" | "X-OpenRouter-App-Visibility", string>>;
|
|
13
|
-
/** @internal */
|
|
14
|
-
export declare const openRouterApp: (tool: string) => Effect.Effect<OpenRouterApp, never, AppServices>;
|
|
15
|
-
//# sourceMappingURL=openrouter-app.d.mts.map
|