@r_masseater/msch 0.98.0 → 0.100.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 (96) hide show
  1. package/README.md +1 -18
  2. package/dist/cargo-inputs.mjs +2 -2
  3. package/dist/cli.mjs +5215 -1075
  4. package/dist/cli.mjs.map +1 -1
  5. package/dist/config.d.mts +2 -2
  6. package/dist/config.mjs +2 -2
  7. package/dist/decision-rules.d.mts +1 -1
  8. package/dist/decision-rules.mjs +1 -1
  9. package/dist/{define-lint-preset-YcRo_ZW9.mjs → define-lint-preset-BnOZuTNT.mjs} +29 -133
  10. package/dist/define-lint-preset-BnOZuTNT.mjs.map +1 -0
  11. package/dist/{ignored-directories-D-7Rm_2X.mjs → ignored-directories-DVyp8bfD.mjs} +2 -2
  12. package/dist/{ignored-directories-D-7Rm_2X.mjs.map → ignored-directories-DVyp8bfD.mjs.map} +1 -1
  13. package/dist/{index-Dm0Gg9wS.d.mts → index-Cdap8t_F.d.mts} +2 -2
  14. package/dist/{index-CUrewm-i.d.mts → index-DbmdHsLx.d.mts} +43 -21
  15. package/dist/lint-rules.mjs +145 -17
  16. package/dist/lint-rules.mjs.map +1 -1
  17. package/dist/lint.d.mts +2 -2
  18. package/dist/lint.mjs +1 -1
  19. package/dist/oxlint.mjs +4 -3
  20. package/dist/oxlint.mjs.map +1 -1
  21. package/dist/{problem-DbuTeNvL.mjs → problem-BTQ96CJ5.mjs} +2 -2
  22. package/dist/{problem-DbuTeNvL.mjs.map → problem-BTQ96CJ5.mjs.map} +1 -1
  23. package/dist/{published-3eokcs_D.mjs → published-O6THHxdC.mjs} +172 -6
  24. package/dist/published-O6THHxdC.mjs.map +1 -0
  25. package/dist/{repository-files-DSwKJnrj.mjs → repository-files-BwjF-kJ8.mjs} +2 -2
  26. package/dist/{repository-files-DSwKJnrj.mjs.map → repository-files-BwjF-kJ8.mjs.map} +1 -1
  27. package/dist/{repository-text-DE4rRWEZ.mjs → repository-text-qZQSVg9L.mjs} +8 -8
  28. package/dist/repository-text-qZQSVg9L.mjs.map +1 -0
  29. package/dist/workspace-settings.d.mts +1 -1
  30. package/dist/workspace-settings.mjs +3 -4
  31. package/dist/workspace-settings.mjs.map +1 -1
  32. package/package.json +5 -13
  33. package/skills/msch-checks/SKILL.md +10 -10
  34. package/skills/msch-publishing/SKILL.md +12 -12
  35. package/skills/msch-repository-config/SKILL.md +2 -2
  36. package/dist/base-revision-Bl-4nxAd.mjs +0 -15
  37. package/dist/base-revision-Bl-4nxAd.mjs.map +0 -1
  38. package/dist/changed.d.mts +0 -1
  39. package/dist/changed.mjs +0 -245
  40. package/dist/changed.mjs.map +0 -1
  41. package/dist/cli-contract-D7btWrEu.mjs +0 -5
  42. package/dist/cli-contract-D7btWrEu.mjs.map +0 -1
  43. package/dist/define-lint-preset-YcRo_ZW9.mjs.map +0 -1
  44. package/dist/exits.d.mts +0 -1
  45. package/dist/exits.mjs +0 -40
  46. package/dist/exits.mjs.map +0 -1
  47. package/dist/judge.d.mts +0 -1
  48. package/dist/judge.mjs +0 -415
  49. package/dist/judge.mjs.map +0 -1
  50. package/dist/lookup-report-L5OLXRMf.mjs +0 -29
  51. package/dist/lookup-report-L5OLXRMf.mjs.map +0 -1
  52. package/dist/manifest-texts-DPgsV8kj.mjs +0 -19
  53. package/dist/manifest-texts-DPgsV8kj.mjs.map +0 -1
  54. package/dist/output-DAvdel9H.mjs +0 -33
  55. package/dist/output-DAvdel9H.mjs.map +0 -1
  56. package/dist/package-routes-BQWX5ttU.mjs +0 -73
  57. package/dist/package-routes-BQWX5ttU.mjs.map +0 -1
  58. package/dist/package-versions-sx15IGwA.mjs +0 -92
  59. package/dist/package-versions-sx15IGwA.mjs.map +0 -1
  60. package/dist/pass-records-BcAAWgiQ.mjs +0 -437
  61. package/dist/pass-records-BcAAWgiQ.mjs.map +0 -1
  62. package/dist/publish.d.mts +0 -1
  63. package/dist/publish.mjs +0 -1596
  64. package/dist/publish.mjs.map +0 -1
  65. package/dist/published-3eokcs_D.mjs.map +0 -1
  66. package/dist/published.d.mts +0 -1
  67. package/dist/published.mjs +0 -134
  68. package/dist/published.mjs.map +0 -1
  69. package/dist/refs.d.mts +0 -1
  70. package/dist/refs.mjs +0 -232
  71. package/dist/refs.mjs.map +0 -1
  72. package/dist/registries-DePiYd3D.mjs +0 -11
  73. package/dist/registries-DePiYd3D.mjs.map +0 -1
  74. package/dist/registry-releases-BBtz4wGE.mjs +0 -62
  75. package/dist/registry-releases-BBtz4wGE.mjs.map +0 -1
  76. package/dist/repository-text-DE4rRWEZ.mjs.map +0 -1
  77. package/dist/runtime-Djm7zMwu.mjs +0 -13
  78. package/dist/runtime-Djm7zMwu.mjs.map +0 -1
  79. package/dist/specifiers-BrCyPubD.mjs +0 -32
  80. package/dist/specifiers-BrCyPubD.mjs.map +0 -1
  81. package/dist/tree-sitter-BfzHNwTR.mjs +0 -41
  82. package/dist/tree-sitter-BfzHNwTR.mjs.map +0 -1
  83. package/dist/unbumped.d.mts +0 -1
  84. package/dist/unbumped.mjs +0 -19
  85. package/dist/unbumped.mjs.map +0 -1
  86. package/dist/upstream-exits-4bn4gblF.mjs +0 -357
  87. package/dist/upstream-exits-4bn4gblF.mjs.map +0 -1
  88. package/dist/upstream-record-DRNGym9S.mjs +0 -136
  89. package/dist/upstream-record-DRNGym9S.mjs.map +0 -1
  90. package/dist/upstream.d.mts +0 -1
  91. package/dist/upstream.mjs +0 -104
  92. package/dist/upstream.mjs.map +0 -1
  93. package/dist/workspace-manifest-BAVyPzbA.mjs +0 -8
  94. package/dist/workspace-manifest-BAVyPzbA.mjs.map +0 -1
  95. package/dist/workspace-projects-MpL8K7Nz.mjs +0 -172
  96. package/dist/workspace-projects-MpL8K7Nz.mjs.map +0 -1
package/dist/judge.mjs DELETED
@@ -1,415 +0,0 @@
1
- #!/usr/bin/env node
2
- import { i as writeProblems, n as failWhenAny, r as writeJsonProblems } from "./output-DAvdel9H.mjs";
3
- import { t as runCli } from "./runtime-Djm7zMwu.mjs";
4
- import { n as DECISION_TIMEOUT_MS, t as DECISION_MODEL } from "./config-BBdsNPSO.mjs";
5
- import { a as problemAtPosition, o as problemInFile, s as sortProblems } from "./problem-DbuTeNvL.mjs";
6
- import { r as RepositoryFiles } from "./repository-files-DSwKJnrj.mjs";
7
- import { t as JSON_FLAG } from "./cli-contract-D7btWrEu.mjs";
8
- import { Array, Effect, FileSystem, Option, Order, Path, Schema, Stdio, Stream, String as String$1, pipe } from "effect";
9
- import { ChildProcess } from "effect/process";
10
- import { judgeText } from "@r_masseater/oxlint-plugin-decision";
11
- // src/features/judge-documents/model/agent-prompt.ts
12
- /** @internal */
13
- const AgentAnswer = Schema.Struct({
14
- verdict: Schema.Literals([
15
- "violation",
16
- "pass",
17
- "unknown"
18
- ]),
19
- quote: Schema.String,
20
- reason: Schema.String
21
- });
22
- /** @internal */
23
- const AGENT_SCHEMA = Schema.toJsonSchemaDocument(AgentAnswer).schema;
24
- const listOf = (names) => pipe(names, Array.map((name) => `- ${name}`), Array.join("\n"));
25
- const readableNames = (context) => pipe(context, Array.map(({ name }) => name));
26
- /** @internal */
27
- const promptOf = ({ rule, target, context }) => pipe([
28
- "Judge one rule against one file. The working directory holds only the files you may read.",
29
- `Rule: ${rule.question}`,
30
- `Target file: ${target.name}`,
31
- "Other readable files:",
32
- listOf(readableNames(context)),
33
- "Read the target file, and read the other files when the rule needs them.",
34
- "Answer \"violation\" only when the target file breaks the rule, \"pass\" when it does not, and \"unknown\" when these files do not let you decide.",
35
- "For a violation, copy the offending text from the target file exactly as written into quote, without paraphrase and without added or removed characters. Leave quote empty otherwise.",
36
- "Give the reason in one sentence."
37
- ], Array.join("\n"));
38
- // src/features/judge-documents/model/verdict.ts
39
- const LINE_BREAK = "\n";
40
- const FIRST_LINE = 1;
41
- const START = 0;
42
- const Violation = Schema.Struct({
43
- status: Schema.Literal("violation"),
44
- line: Schema.Int,
45
- quote: Schema.String,
46
- reason: Schema.String
47
- });
48
- const Pass = Schema.Struct({ status: Schema.Literal("pass") });
49
- Schema.Struct({
50
- status: Schema.Literal("unknown"),
51
- reason: Schema.String
52
- });
53
- /** @internal */
54
- const DecidedVerdictSchema = Schema.Union([Violation, Pass]);
55
- /** @internal */
56
- const unknownBecause = (reason) => ({
57
- status: "unknown",
58
- reason
59
- });
60
- /** @internal */
61
- const isDecided = (verdict) => verdict.status !== "unknown";
62
- /** @internal */
63
- const lineOfQuote = ({ text, quote }) => {
64
- if (String$1.isEmpty(quote)) return Option.none();
65
- return pipe(String$1.indexOf(quote)(text), Option.map((index) => pipe(String$1.slice(START, index)(text), String$1.split(LINE_BREAK)).length));
66
- };
67
- /** @internal */
68
- const textOfLine = ({ text, line }) => pipe(String$1.split(text, LINE_BREAK), Array.get(line - FIRST_LINE), Option.getOrElse(() => ""));
69
- // src/features/judge-documents/model/agent-judge.ts
70
- const AGENT_MODEL = "claude-sonnet-5-5";
71
- const AGENT_EFFORT = "medium";
72
- const AGENT_TOOLS = "Read,Grep,Glob";
73
- const AGENT_TIMEOUT = "10 minutes";
74
- const SUCCESS = 0;
75
- const STDERR_TAIL = 400;
76
- /** @internal */
77
- const CLAUDE = { command: ["claude"] };
78
- const ClaudeResult = Schema.Struct({
79
- is_error: Schema.Boolean,
80
- structured_output: Schema.optional(AgentAnswer)
81
- });
82
- const decodeResult = Schema.decodeUnknownEffect(Schema.fromJsonString(ClaudeResult));
83
- const encodeJson$1 = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
84
- const argsOf = (input, schema) => [
85
- "-p",
86
- promptOf(input),
87
- "--model",
88
- AGENT_MODEL,
89
- "--effort",
90
- AGENT_EFFORT,
91
- "--restricted",
92
- "--tools",
93
- AGENT_TOOLS,
94
- "--strict-mcp-config",
95
- "--disable-slash-commands",
96
- "--no-session-persistence",
97
- "--permission-mode",
98
- "dontAsk",
99
- "--permission-prompts",
100
- "none",
101
- "--output-format",
102
- "json",
103
- "--json-schema",
104
- schema
105
- ];
106
- const sandboxOf = Effect.fn("sandboxOf")(function* sandboxOf(files) {
107
- const fs = yield* FileSystem.FileSystem;
108
- const path = yield* Path.Path;
109
- const directory = yield* fs.makeTempDirectoryScoped({ prefix: "msch-judge-" });
110
- yield* Effect.forEach(files, ({ name, text }) => {
111
- const file = path.join(directory, name);
112
- return fs.makeDirectory(path.dirname(file), { recursive: true }).pipe(Effect.andThen(fs.writeFileString(file, text)));
113
- }, {
114
- concurrency: "unbounded",
115
- discard: true
116
- });
117
- return directory;
118
- });
119
- const textOf = (stream) => stream.pipe(Stream.decodeText(), Stream.mkString);
120
- const runClaude = Effect.fn("runClaude")(function* runClaude(setup, call) {
121
- const [command, ...prefix] = setup.command;
122
- const handle = yield* ChildProcess.make(command, [...prefix, ...call.args], {
123
- cwd: call.directory,
124
- stdin: "ignore"
125
- });
126
- const [stdout, stderr, code] = yield* Effect.all([
127
- textOf(handle.stdout),
128
- textOf(handle.stderr),
129
- handle.exitCode
130
- ], { concurrency: "unbounded" });
131
- if (Number(code) !== SUCCESS) return yield* Effect.fail(`claude exited with ${String(code)}: ${pipe(stderr, String$1.trim, String$1.takeRight(STDERR_TAIL))}`);
132
- return stdout;
133
- });
134
- const verdictOf = (target, answer) => {
135
- if (answer.verdict === "pass") return { status: "pass" };
136
- if (answer.verdict === "unknown") return unknownBecause(answer.reason);
137
- return Option.match(lineOfQuote({
138
- text: target.text,
139
- quote: answer.quote
140
- }), {
141
- onNone: () => unknownBecause("the quoted text is not in the target file"),
142
- onSome: (line) => ({
143
- status: "violation",
144
- line,
145
- quote: answer.quote,
146
- reason: answer.reason
147
- })
148
- });
149
- };
150
- const judgeIn = Effect.fn("agentJudge")(function* judgeIn(setup, input) {
151
- const directory = yield* sandboxOf([input.target, ...input.context]);
152
- const schema = yield* encodeJson$1(AGENT_SCHEMA);
153
- const stdout = yield* runClaude(setup, {
154
- directory,
155
- args: argsOf(input, schema)
156
- });
157
- const result = yield* decodeResult(stdout);
158
- const answer = Option.fromUndefinedOr(result.structured_output);
159
- if (result.is_error || Option.isNone(answer)) return unknownBecause("claude returned no structured answer");
160
- return verdictOf(input.target, answer.value);
161
- });
162
- const reasonOf = (failure) => {
163
- if (typeof failure === "string") return failure;
164
- if (failure instanceof Error) return failure.message;
165
- return String(failure);
166
- };
167
- /** @internal */
168
- const agentJudge = (setup) => ({
169
- identity: {
170
- model: AGENT_MODEL,
171
- promptVersion: 1
172
- },
173
- judge: (input) => judgeIn(setup, input).pipe(Effect.scoped, Effect.timeout(AGENT_TIMEOUT), Effect.match({
174
- onSuccess: (verdict) => verdict,
175
- onFailure: (failure) => unknownBecause(reasonOf(failure))
176
- }))
177
- });
178
- // src/features/judge-documents/model/decision-judge.ts
179
- const ANSWERED_YES = "The decision model answered yes.";
180
- const judgeDecision = ({ rule, target: { text } }) => Effect.sync(() => {
181
- const judged = judgeText({
182
- rule: {
183
- id: rule.id,
184
- question: rule.question,
185
- cutoff: rule.cutoff
186
- },
187
- text,
188
- model: DECISION_MODEL,
189
- timeoutMs: DECISION_TIMEOUT_MS,
190
- env: {}
191
- });
192
- if (judged.status === "violation") return {
193
- status: "violation",
194
- line: judged.line,
195
- quote: textOfLine({
196
- text,
197
- line: judged.line
198
- }),
199
- reason: ANSWERED_YES
200
- };
201
- if (judged.status === "pass") return { status: "pass" };
202
- return unknownBecause(judged.reason);
203
- });
204
- /** @internal */
205
- const DECISION_JUDGE = {
206
- identity: {
207
- model: DECISION_MODEL,
208
- promptVersion: 1
209
- },
210
- judge: judgeDecision
211
- };
212
- // src/features/judge-documents/model/judge-rules.ts
213
- const DECISION_CUTOFF = .8;
214
- /** @internal */
215
- const JUDGE_RULES = [
216
- {
217
- kind: "decision",
218
- id: "agents-no-task-record",
219
- files: ["**/AGENTS.md"],
220
- question: "Does this document record finished work, such as a changelog, a dated list of completed tasks or the history of what was changed and why, instead of rules and facts that stay true? Answer no for standing rules, commands and structure, even when a rule names a date or gives the reason it exists.",
221
- message: "Do not add a record of finished work to AGENTS.md. Put the reason for a change in its commit message.",
222
- cutoff: DECISION_CUTOFF
223
- },
224
- {
225
- kind: "decision",
226
- id: "readme-no-code-restatement",
227
- files: ["**/README.md"],
228
- question: "Does this README list what the code already shows, such as every file, module, exported function, parameter, option or endpoint, instead of saying what the project is, how to start using it and where it is published? Answer no for a short table of entry points that a reader needs before opening the code, and for install and usage commands.",
229
- message: "Do not copy what the code shows into the README. Say what it is, how to start using it and where it is published, and leave parameters, options and file lists to the types and the code.",
230
- cutoff: DECISION_CUTOFF
231
- },
232
- {
233
- kind: "agent",
234
- id: "skill-restates-skill",
235
- files: ["**/skills/*/SKILL.md"],
236
- context: ["../*/SKILL.md", "./**/*.md"],
237
- question: "Does this skill state a rule that another skill among the readable files also states in substance, so that two copies of one rule can drift apart? Answer no when the two rules differ in scope or reason, and when this skill only points to the other one.",
238
- message: "Keep each rule in one skill. Replace the copy with a pointer to the skill that owns the rule, or move the rule to where both can follow it."
239
- }
240
- ];
241
- // src/features/judge-documents/model/judge-cache.ts
242
- const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
243
- const decodeCached = Schema.decodeUnknownOption(Schema.fromJsonString(DecidedVerdictSchema));
244
- const encodeCached = Schema.encodeEffect(Schema.fromJsonString(DecidedVerdictSchema));
245
- const ruleKey = ({ rule }) => {
246
- if (rule.kind === "decision") return {
247
- kind: rule.kind,
248
- id: rule.id,
249
- question: rule.question,
250
- cutoff: rule.cutoff
251
- };
252
- return {
253
- kind: rule.kind,
254
- id: rule.id,
255
- question: rule.question,
256
- context: rule.context
257
- };
258
- };
259
- /** @internal */
260
- const cacheKeyOf = Effect.fn("cacheKeyOf")(function* cacheKeyOf(input, identity) {
261
- const files = yield* RepositoryFiles;
262
- const json = yield* encodeJson({
263
- ...identity,
264
- rule: ruleKey(input),
265
- target: input.target,
266
- context: pipe(input.context, Array.map(({ name, text }) => [name, text]))
267
- }).pipe(Effect.orDie);
268
- return yield* files.hash(json);
269
- });
270
- const fileOf = (directory, key) => RepositoryFiles.pipe(Effect.map((files) => files.join(directory, `${key}.json`)));
271
- /** @internal */
272
- const readCached = Effect.fn("readCached")(function* readCached(directory, key) {
273
- const files = yield* RepositoryFiles;
274
- const file = yield* fileOf(directory, key);
275
- return (yield* files.readFile(file)).pipe(Option.flatMap(decodeCached));
276
- });
277
- /** @internal */
278
- const writeCached = Effect.fn("writeCached")(function* writeCached(directory, { key, verdict }) {
279
- if (!isDecided(verdict)) return;
280
- const files = yield* RepositoryFiles;
281
- const file = yield* fileOf(directory, key);
282
- const text = yield* encodeCached(verdict).pipe(Effect.orDie);
283
- yield* files.writeFile(file, text);
284
- });
285
- // src/features/judge-documents/model/judge-input.ts
286
- /** @internal */
287
- const isDecisionInput = (input) => input.rule.kind === "decision";
288
- /** @internal */
289
- const isAgentInput = (input) => input.rule.kind === "agent";
290
- /** @internal */
291
- const readJudgedFile = Effect.fn("readJudgedFile")(function* readJudgedFile(root, name) {
292
- const files = yield* RepositoryFiles;
293
- return (yield* files.readFile(files.join(root, name))).pipe(Option.map((found) => ({
294
- name,
295
- text: found
296
- })));
297
- });
298
- /** @internal */
299
- const readJudgedFiles = Effect.fn("readJudgedFiles")(function* readJudgedFiles(root, names) {
300
- const read = yield* Effect.forEach(names, (name) => readJudgedFile(root, name), { concurrency: "unbounded" });
301
- return pipe(read, Array.getSomes);
302
- });
303
- // src/features/judge-documents/model/judge-pairs.ts
304
- const GLOB = ":(glob)";
305
- const globsOf = (patterns) => pipe(patterns, Array.map((pattern) => `${GLOB}${pattern}`));
306
- const contextNames = Effect.fn("contextNames")(function* contextNames(root, rule, name) {
307
- if (rule.kind === "decision") return [];
308
- const files = yield* RepositoryFiles;
309
- const directory = files.dirname(name);
310
- const listed = yield* Effect.forEach(rule.context, (pattern) => files.matchingFiles(root, globsOf([files.join(directory, pattern)])), { concurrency: "unbounded" });
311
- return pipe(listed, Array.flatten, Array.filter((found) => found !== name), Array.dedupe, (names) => Array.sort(names, Order.String));
312
- });
313
- const inputOf = Effect.fn("inputOf")(function* inputOf(root, { rule, name }) {
314
- const target = yield* readJudgedFile(root, name);
315
- if (Option.isNone(target)) return Option.none();
316
- const names = yield* contextNames(root, rule, name);
317
- const context = yield* readJudgedFiles(root, names);
318
- return Option.some({
319
- rule,
320
- target: target.value,
321
- context
322
- });
323
- });
324
- const inputsOf = Effect.fn("inputsOf")(function* inputsOf(root, rule) {
325
- const names = yield* (yield* RepositoryFiles).matchingFiles(root, globsOf(rule.files));
326
- const inputs = yield* Effect.forEach(names, (name) => inputOf(root, {
327
- rule,
328
- name
329
- }), { concurrency: "unbounded" });
330
- return Array.getSomes(inputs);
331
- });
332
- /** @internal */
333
- const judgeInputs = Effect.fn("judgeInputs")(function* judgeInputs(root, rules) {
334
- const perRule = yield* Effect.forEach(rules, (rule) => inputsOf(root, rule), { concurrency: "unbounded" });
335
- return Array.flatten(perRule);
336
- });
337
- // src/features/judge-documents/model/judge-repository.ts
338
- const AGENT_CONCURRENCY = 4;
339
- const SEQUENTIAL = 1;
340
- const FIRST_COLUMN = 1;
341
- const QUOTE_START = 0;
342
- const QUOTE_LIMIT = 160;
343
- const WHITESPACE = /\s+/gu;
344
- const oneLine = (text) => pipe(text, String$1.replaceAll(WHITESPACE, " "), String$1.trim, String$1.slice(QUOTE_START, QUOTE_LIMIT));
345
- const cachedBy = (directory, judge) => (input) => Effect.gen(function* cached() {
346
- const key = yield* cacheKeyOf(input, judge.identity);
347
- const hit = yield* readCached(directory, key);
348
- if (Option.isSome(hit)) return hit.value;
349
- const verdict = yield* judge.judge(input);
350
- yield* writeCached(directory, {
351
- key,
352
- verdict
353
- });
354
- return verdict;
355
- });
356
- const problemOf = (file, { input, verdict }) => {
357
- const { rule } = input;
358
- if (verdict.status === "pass") return Option.none();
359
- if (verdict.status === "unknown") return Option.some(problemInFile("judge-unknown")(file, `Could not decide ${rule.id}. ${verdict.reason}`));
360
- return Option.some(problemAtPosition(rule.id)(file, {
361
- line: verdict.line,
362
- column: FIRST_COLUMN
363
- }, `${rule.message} ${verdict.reason} Quoted: ${oneLine(verdict.quote)}`));
364
- };
365
- /** @internal */
366
- const judgeRepository = Effect.fn("judgeRepository")(function* judgeRepository(root, setup) {
367
- const files = yield* RepositoryFiles;
368
- const inputs = yield* judgeInputs(root, setup.rules);
369
- const decisions = pipe(inputs, Array.filter(isDecisionInput));
370
- const agents = pipe(inputs, Array.filter(isAgentInput));
371
- const decided = yield* Effect.forEach(decisions, cachedBy(setup.cacheDirectory, setup.decision), { concurrency: SEQUENTIAL });
372
- const reasoned = yield* Effect.forEach(agents, cachedBy(setup.cacheDirectory, setup.agent), { concurrency: AGENT_CONCURRENCY });
373
- const answered = [...decisions, ...agents];
374
- return pipe(Array.zip(answered, [...decided, ...reasoned]), Array.map(([input, verdict]) => problemOf(files.join(root, input.target.name), {
375
- input,
376
- verdict
377
- })), Array.getSomes);
378
- });
379
- // bin/msch-judge.ts
380
- const taggedError = Schema.TaggedError;
381
- var UsageError = class extends taggedError()("UsageError", { message: Schema.String }) {};
382
- const USAGE = `usage: msch-judge <cache directory> [${JSON_FLAG}]`;
383
- const Arguments = Schema.Tuple([Schema.NonEmptyString]);
384
- const cacheDirectoryOf = Effect.fn("cacheDirectoryOf")(function* cacheDirectoryOf(args) {
385
- const positional = pipe(args, Array.filter((arg) => arg !== JSON_FLAG));
386
- const [directory] = yield* Schema.decodeUnknownEffect(Arguments)(positional).pipe(Effect.mapError(() => UsageError.make({ message: USAGE })));
387
- return directory;
388
- });
389
- const report = Effect.fn("report")(function* report(root, { problems, json }) {
390
- if (json) return yield* writeJsonProblems(problems);
391
- return yield* writeProblems(root)(problems);
392
- });
393
- const judge = Effect.gen(function* judge() {
394
- const stdio = yield* Stdio.Stdio;
395
- const files = yield* RepositoryFiles;
396
- const args = yield* stdio.args;
397
- const directory = yield* cacheDirectoryOf(args);
398
- const root = files.resolve(".");
399
- const found = yield* judgeRepository(root, {
400
- cacheDirectory: files.resolve(directory),
401
- rules: JUDGE_RULES,
402
- decision: DECISION_JUDGE,
403
- agent: agentJudge(CLAUDE)
404
- });
405
- const problems = sortProblems(found);
406
- yield* report(root, {
407
- problems,
408
- json: Array.contains(args, JSON_FLAG)
409
- });
410
- return yield* failWhenAny(problems.length);
411
- });
412
- runCli("msch-judge")(judge);
413
- export {};
414
-
415
- //# sourceMappingURL=judge.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"judge.mjs","names":["Arr","Str","Arr","encodeJson","Str","Arr","Arr","Arr","Str","Arr","Arr"],"sources":["../src/features/judge-documents/model/agent-prompt.ts","../src/features/judge-documents/model/verdict.ts","../src/features/judge-documents/model/agent-judge.ts","../src/features/judge-documents/model/decision-judge.ts","../src/features/judge-documents/model/judge-rules.ts","../src/features/judge-documents/model/judge-cache.ts","../src/features/judge-documents/model/judge-input.ts","../src/features/judge-documents/model/judge-pairs.ts","../src/features/judge-documents/model/judge-repository.ts","../bin/msch-judge.ts"],"sourcesContent":["import { Array as Arr, Schema, pipe } from \"effect\";\n\nimport type { AgentInput } from \"./judge-input.ts\";\n\n/** @internal */\nexport const AgentAnswer = Schema.Struct({\n verdict: Schema.Literals([\"violation\", \"pass\", \"unknown\"]),\n quote: Schema.String,\n reason: Schema.String,\n});\n\n/** @internal */\nexport const AGENT_SCHEMA = Schema.toJsonSchemaDocument(AgentAnswer).schema;\n\n/** @internal */\nexport const AGENT_PROMPT_VERSION = 1;\n\nconst listOf = (names: readonly string[]): string =>\n pipe(\n names,\n Arr.map((name) => `- ${name}`),\n Arr.join(\"\\n\"),\n );\n\nconst readableNames = (context: AgentInput[\"context\"]): readonly string[] =>\n pipe(\n context,\n Arr.map(({ name }) => name),\n );\n\n/** @internal */\nexport const promptOf = ({ rule, target, context }: AgentInput): string =>\n pipe(\n [\n \"Judge one rule against one file. The working directory holds only the files you may read.\",\n `Rule: ${rule.question}`,\n `Target file: ${target.name}`,\n \"Other readable files:\",\n listOf(readableNames(context)),\n \"Read the target file, and read the other files when the rule needs them.\",\n 'Answer \"violation\" only when the target file breaks the rule, \"pass\" when it does not, and \"unknown\" when these files do not let you decide.',\n \"For a violation, copy the offending text from the target file exactly as written into quote, without paraphrase and without added or removed characters. Leave quote empty otherwise.\",\n \"Give the reason in one sentence.\",\n ],\n Arr.join(\"\\n\"),\n );\n","import { Array as Arr, Option, Schema, String as Str, pipe } from \"effect\";\n\nconst LINE_BREAK = \"\\n\";\nconst FIRST_LINE = 1;\nconst START = 0;\n\nconst Violation = Schema.Struct({\n status: Schema.Literal(\"violation\"),\n line: Schema.Int,\n quote: Schema.String,\n reason: Schema.String,\n});\n\nconst Pass = Schema.Struct({ status: Schema.Literal(\"pass\") });\n\nconst Unknown = Schema.Struct({ status: Schema.Literal(\"unknown\"), reason: Schema.String });\n\n/** @internal */\nexport const DecidedVerdictSchema = Schema.Union([Violation, Pass]);\n\n/** @internal */\nexport type DecidedVerdict = typeof DecidedVerdictSchema.Type;\n\n/** @internal */\nexport type Verdict = DecidedVerdict | typeof Unknown.Type;\n\n/** @internal */\nexport const unknownBecause = (reason: string): Verdict => ({ status: \"unknown\", reason });\n\n/** @internal */\nexport const isDecided = (verdict: Verdict): verdict is DecidedVerdict =>\n verdict.status !== \"unknown\";\n\n/** @internal */\nexport const lineOfQuote = ({\n text,\n quote,\n}: {\n readonly text: string;\n readonly quote: string;\n}): Option.Option<number> => {\n if (Str.isEmpty(quote)) {\n return Option.none();\n }\n return pipe(\n Str.indexOf(quote)(text),\n Option.map((index) => pipe(Str.slice(START, index)(text), Str.split(LINE_BREAK)).length),\n );\n};\n\n/** @internal */\nexport const textOfLine = ({\n text,\n line,\n}: {\n readonly text: string;\n readonly line: number;\n}): string =>\n pipe(\n Str.split(text, LINE_BREAK),\n Arr.get(line - FIRST_LINE),\n Option.getOrElse(() => \"\"),\n );\n","import type { Array as Arr } from \"effect\";\nimport { Effect, FileSystem, Option, Path, Schema, Stream, String as Str, pipe } from \"effect\";\nimport { ChildProcess } from \"effect/process\";\nimport type { ChildProcessSpawner } from \"effect/process\";\n\nimport { AGENT_PROMPT_VERSION, AGENT_SCHEMA, AgentAnswer, promptOf } from \"./agent-prompt.ts\";\nimport type { AgentInput, JudgedFile } from \"./judge-input.ts\";\nimport type { Judge } from \"./judge.ts\";\nimport { lineOfQuote, unknownBecause } from \"./verdict.ts\";\nimport type { Verdict } from \"./verdict.ts\";\n\nconst AGENT_MODEL = \"claude-sonnet-5-5\";\nconst AGENT_EFFORT = \"medium\";\nconst AGENT_TOOLS = \"Read,Grep,Glob\";\nconst AGENT_TIMEOUT = \"10 minutes\";\nconst SUCCESS = 0;\nconst STDERR_TAIL = 400;\n\n/** @internal */\nexport interface AgentSetup {\n readonly command: Arr.NonEmptyReadonlyArray<string>;\n}\n\n/** @internal */\nexport const CLAUDE: AgentSetup = { command: [\"claude\"] };\n\nconst ClaudeResult = Schema.Struct({\n is_error: Schema.Boolean,\n structured_output: Schema.optional(AgentAnswer),\n});\n\nconst decodeResult = Schema.decodeUnknownEffect(Schema.fromJsonString(ClaudeResult));\n\nconst encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));\n\nconst argsOf = (input: AgentInput, schema: string): readonly string[] => [\n \"-p\",\n promptOf(input),\n \"--model\",\n AGENT_MODEL,\n \"--effort\",\n AGENT_EFFORT,\n \"--restricted\",\n \"--tools\",\n AGENT_TOOLS,\n \"--strict-mcp-config\",\n \"--disable-slash-commands\",\n \"--no-session-persistence\",\n \"--permission-mode\",\n \"dontAsk\",\n \"--permission-prompts\",\n \"none\",\n \"--output-format\",\n \"json\",\n \"--json-schema\",\n schema,\n];\n\nconst sandboxOf = Effect.fn(\"sandboxOf\")(function* sandboxOf(files: readonly JudgedFile[]) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const directory = yield* fs.makeTempDirectoryScoped({ prefix: \"msch-judge-\" });\n yield* Effect.forEach(\n files,\n ({ name, text }) => {\n const file = path.join(directory, name);\n return fs\n .makeDirectory(path.dirname(file), { recursive: true })\n .pipe(Effect.andThen(fs.writeFileString(file, text)));\n },\n { concurrency: \"unbounded\", discard: true },\n );\n return directory;\n});\n\nconst textOf = <Failure, Requirements>(\n stream: Stream.Stream<Uint8Array, Failure, Requirements>,\n): Effect.Effect<string, Failure, Requirements> =>\n stream.pipe(Stream.decodeText(), Stream.mkString);\n\nconst runClaude = Effect.fn(\"runClaude\")(function* runClaude(\n setup: AgentSetup,\n call: { readonly directory: string; readonly args: readonly string[] },\n) {\n const [command, ...prefix] = setup.command;\n const handle = yield* ChildProcess.make(command, [...prefix, ...call.args], {\n cwd: call.directory,\n stdin: \"ignore\",\n });\n const [stdout, stderr, code] = yield* Effect.all(\n [textOf(handle.stdout), textOf(handle.stderr), handle.exitCode],\n { concurrency: \"unbounded\" },\n );\n if (Number(code) !== SUCCESS) {\n return yield* Effect.fail(\n `claude exited with ${String(code)}: ${pipe(stderr, Str.trim, Str.takeRight(STDERR_TAIL))}`,\n );\n }\n return stdout;\n});\n\nconst verdictOf = (target: JudgedFile, answer: typeof AgentAnswer.Type): Verdict => {\n if (answer.verdict === \"pass\") {\n return { status: \"pass\" };\n }\n if (answer.verdict === \"unknown\") {\n return unknownBecause(answer.reason);\n }\n return Option.match(lineOfQuote({ text: target.text, quote: answer.quote }), {\n onNone: () => unknownBecause(\"the quoted text is not in the target file\"),\n onSome: (line): Verdict => ({\n status: \"violation\",\n line,\n quote: answer.quote,\n reason: answer.reason,\n }),\n });\n};\n\nconst judgeIn = Effect.fn(\"agentJudge\")(function* judgeIn(setup: AgentSetup, input: AgentInput) {\n const directory = yield* sandboxOf([input.target, ...input.context]);\n const schema = yield* encodeJson(AGENT_SCHEMA);\n const stdout = yield* runClaude(setup, { directory, args: argsOf(input, schema) });\n const result = yield* decodeResult(stdout);\n const answer = Option.fromUndefinedOr(result.structured_output);\n if (result.is_error || Option.isNone(answer)) {\n return unknownBecause(\"claude returned no structured answer\");\n }\n return verdictOf(input.target, answer.value);\n});\n\nconst reasonOf = (failure: unknown): string => {\n if (typeof failure === \"string\") {\n return failure;\n }\n if (failure instanceof Error) {\n return failure.message;\n }\n return String(failure);\n};\n\n/** @internal */\nexport const agentJudge = (\n setup: AgentSetup,\n): Judge<\n AgentInput,\n FileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner\n> => ({\n identity: { model: AGENT_MODEL, promptVersion: AGENT_PROMPT_VERSION },\n judge: (input) =>\n judgeIn(setup, input).pipe(\n Effect.scoped,\n Effect.timeout(AGENT_TIMEOUT),\n Effect.match({\n onSuccess: (verdict) => verdict,\n onFailure: (failure) => unknownBecause(reasonOf(failure)),\n }),\n ),\n});\n","import { judgeText } from \"@r_masseater/oxlint-plugin-decision\";\nimport { Effect } from \"effect\";\n\nimport { DECISION_MODEL, DECISION_TIMEOUT_MS } from \"#/shared/config/index.ts\";\n\nimport type { DecisionInput } from \"./judge-input.ts\";\nimport type { Judge } from \"./judge.ts\";\nimport { textOfLine, unknownBecause } from \"./verdict.ts\";\nimport type { Verdict } from \"./verdict.ts\";\n\nconst ANSWERED_YES = \"The decision model answered yes.\";\n\nconst judgeDecision = ({ rule, target: { text } }: DecisionInput): Effect.Effect<Verdict> =>\n Effect.sync((): Verdict => {\n const judged = judgeText({\n rule: { id: rule.id, question: rule.question, cutoff: rule.cutoff },\n text,\n model: DECISION_MODEL,\n timeoutMs: DECISION_TIMEOUT_MS,\n env: {},\n });\n if (judged.status === \"violation\") {\n return {\n status: \"violation\",\n line: judged.line,\n quote: textOfLine({ text, line: judged.line }),\n reason: ANSWERED_YES,\n };\n }\n if (judged.status === \"pass\") {\n return { status: \"pass\" };\n }\n return unknownBecause(judged.reason);\n });\n\n/** @internal */\nexport const DECISION_JUDGE: Judge<DecisionInput, never> = {\n identity: { model: DECISION_MODEL, promptVersion: 1 },\n judge: judgeDecision,\n};\n","import type { JudgeRule } from \"./judge-rule.ts\";\n\nconst DECISION_CUTOFF = 0.8;\n\n/** @internal */\nexport const JUDGE_RULES: readonly JudgeRule[] = [\n {\n kind: \"decision\",\n id: \"agents-no-task-record\",\n files: [\"**/AGENTS.md\"],\n question:\n \"Does this document record finished work, such as a changelog, a dated list of completed tasks or the history of what was changed and why, instead of rules and facts that stay true? Answer no for standing rules, commands and structure, even when a rule names a date or gives the reason it exists.\",\n message:\n \"Do not add a record of finished work to AGENTS.md. Put the reason for a change in its commit message.\",\n cutoff: DECISION_CUTOFF,\n },\n {\n kind: \"decision\",\n id: \"readme-no-code-restatement\",\n files: [\"**/README.md\"],\n question:\n \"Does this README list what the code already shows, such as every file, module, exported function, parameter, option or endpoint, instead of saying what the project is, how to start using it and where it is published? Answer no for a short table of entry points that a reader needs before opening the code, and for install and usage commands.\",\n message:\n \"Do not copy what the code shows into the README. Say what it is, how to start using it and where it is published, and leave parameters, options and file lists to the types and the code.\",\n cutoff: DECISION_CUTOFF,\n },\n {\n kind: \"agent\",\n id: \"skill-restates-skill\",\n files: [\"**/skills/*/SKILL.md\"],\n context: [\"../*/SKILL.md\", \"./**/*.md\"],\n question:\n \"Does this skill state a rule that another skill among the readable files also states in substance, so that two copies of one rule can drift apart? Answer no when the two rules differ in scope or reason, and when this skill only points to the other one.\",\n message:\n \"Keep each rule in one skill. Replace the copy with a pointer to the skill that owns the rule, or move the rule to where both can follow it.\",\n },\n];\n","import { Array as Arr, Effect, Option, Schema, pipe } from \"effect\";\n\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\n\nimport type { JudgeInput } from \"./judge-input.ts\";\nimport type { JudgeIdentity } from \"./judge.ts\";\nimport { DecidedVerdictSchema, isDecided } from \"./verdict.ts\";\nimport type { Verdict } from \"./verdict.ts\";\n\nconst encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));\n\nconst decodeCached = Schema.decodeUnknownOption(Schema.fromJsonString(DecidedVerdictSchema));\n\nconst encodeCached = Schema.encodeEffect(Schema.fromJsonString(DecidedVerdictSchema));\n\nconst ruleKey = ({ rule }: JudgeInput): unknown => {\n if (rule.kind === \"decision\") {\n return { kind: rule.kind, id: rule.id, question: rule.question, cutoff: rule.cutoff };\n }\n return { kind: rule.kind, id: rule.id, question: rule.question, context: rule.context };\n};\n\n/** @internal */\nexport const cacheKeyOf = Effect.fn(\"cacheKeyOf\")(function* cacheKeyOf(\n input: JudgeInput,\n identity: JudgeIdentity,\n) {\n const files = yield* RepositoryFiles;\n const json = yield* encodeJson({\n ...identity,\n rule: ruleKey(input),\n target: input.target,\n context: pipe(\n input.context,\n Arr.map(({ name, text }) => [name, text]),\n ),\n }).pipe(Effect.orDie);\n return yield* files.hash(json);\n});\n\nconst fileOf = (directory: string, key: string): Effect.Effect<string, never, RepositoryFiles> =>\n RepositoryFiles.pipe(Effect.map((files) => files.join(directory, `${key}.json`)));\n\n/** @internal */\nexport const readCached = Effect.fn(\"readCached\")(function* readCached(\n directory: string,\n key: string,\n) {\n const files = yield* RepositoryFiles;\n const file = yield* fileOf(directory, key);\n const text = yield* files.readFile(file);\n return text.pipe(Option.flatMap(decodeCached));\n});\n\n/** @internal */\nexport const writeCached = Effect.fn(\"writeCached\")(function* writeCached(\n directory: string,\n { key, verdict }: { readonly key: string; readonly verdict: Verdict },\n) {\n if (!isDecided(verdict)) {\n return;\n }\n const files = yield* RepositoryFiles;\n const file = yield* fileOf(directory, key);\n const text = yield* encodeCached(verdict).pipe(Effect.orDie);\n yield* files.writeFile(file, text);\n});\n","import { Array as Arr, Effect, Option, pipe } from \"effect\";\n\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\n\nimport type { AgentJudgeRule, DecisionJudgeRule, JudgeRule } from \"./judge-rule.ts\";\n\n/** @internal */\nexport interface JudgedFile {\n readonly name: string;\n readonly text: string;\n}\n\n/** @internal */\nexport interface JudgeInput<Rule extends JudgeRule = JudgeRule> {\n readonly rule: Rule;\n readonly target: JudgedFile;\n readonly context: readonly JudgedFile[];\n}\n\n/** @internal */\nexport type DecisionInput = JudgeInput<DecisionJudgeRule>;\n\n/** @internal */\nexport type AgentInput = JudgeInput<AgentJudgeRule>;\n\n/** @internal */\nexport const isDecisionInput = (input: JudgeInput): input is DecisionInput =>\n input.rule.kind === \"decision\";\n\n/** @internal */\nexport const isAgentInput = (input: JudgeInput): input is AgentInput => input.rule.kind === \"agent\";\n\n/** @internal */\nexport const readJudgedFile = Effect.fn(\"readJudgedFile\")(function* readJudgedFile(\n root: string,\n name: string,\n) {\n const files = yield* RepositoryFiles;\n const text = yield* files.readFile(files.join(root, name));\n return text.pipe(Option.map((found): JudgedFile => ({ name, text: found })));\n});\n\n/** @internal */\nexport const readJudgedFiles = Effect.fn(\"readJudgedFiles\")(function* readJudgedFiles(\n root: string,\n names: readonly string[],\n) {\n const read = yield* Effect.forEach(names, (name) => readJudgedFile(root, name), {\n concurrency: \"unbounded\",\n });\n return pipe(read, Arr.getSomes);\n});\n","import { Array as Arr, Effect, Option, Order, pipe } from \"effect\";\n\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\n\nimport { readJudgedFile, readJudgedFiles } from \"./judge-input.ts\";\nimport type { JudgeInput } from \"./judge-input.ts\";\nimport type { JudgeRule } from \"./judge-rule.ts\";\n\nconst GLOB = \":(glob)\";\n\nconst globsOf = (patterns: readonly string[]): readonly string[] =>\n pipe(\n patterns,\n Arr.map((pattern) => `${GLOB}${pattern}`),\n );\n\nconst contextNames = Effect.fn(\"contextNames\")(function* contextNames(\n root: string,\n rule: JudgeRule,\n name: string,\n) {\n if (rule.kind === \"decision\") {\n return [];\n }\n const files = yield* RepositoryFiles;\n const directory = files.dirname(name);\n const listed = yield* Effect.forEach(\n rule.context,\n (pattern) => files.matchingFiles(root, globsOf([files.join(directory, pattern)])),\n { concurrency: \"unbounded\" },\n );\n return pipe(\n listed,\n Arr.flatten,\n Arr.filter((found) => found !== name),\n Arr.dedupe,\n (names) => Arr.sort(names, Order.String),\n );\n});\n\nconst inputOf = Effect.fn(\"inputOf\")(function* inputOf(\n root: string,\n { rule, name }: { readonly rule: JudgeRule; readonly name: string },\n) {\n const target = yield* readJudgedFile(root, name);\n if (Option.isNone(target)) {\n return Option.none<JudgeInput>();\n }\n const names = yield* contextNames(root, rule, name);\n const context = yield* readJudgedFiles(root, names);\n return Option.some<JudgeInput>({ rule, target: target.value, context });\n});\n\nconst inputsOf = Effect.fn(\"inputsOf\")(function* inputsOf(root: string, rule: JudgeRule) {\n const files = yield* RepositoryFiles;\n const names = yield* files.matchingFiles(root, globsOf(rule.files));\n const inputs = yield* Effect.forEach(names, (name) => inputOf(root, { rule, name }), {\n concurrency: \"unbounded\",\n });\n return Arr.getSomes(inputs);\n});\n\n/** @internal */\nexport const judgeInputs = Effect.fn(\"judgeInputs\")(function* judgeInputs(\n root: string,\n rules: readonly JudgeRule[],\n) {\n const perRule = yield* Effect.forEach(rules, (rule) => inputsOf(root, rule), {\n concurrency: \"unbounded\",\n });\n return Arr.flatten(perRule);\n});\n","import { Array as Arr, Effect, Option, String as Str, pipe } from \"effect\";\n\nimport { problemAtPosition, problemInFile } from \"#/shared/lib/problem.ts\";\nimport type { Problem } from \"#/shared/lib/problem.ts\";\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\n\nimport { cacheKeyOf, readCached, writeCached } from \"./judge-cache.ts\";\nimport { isAgentInput, isDecisionInput } from \"./judge-input.ts\";\nimport type { AgentInput, DecisionInput, JudgeInput } from \"./judge-input.ts\";\nimport { judgeInputs } from \"./judge-pairs.ts\";\nimport type { JudgeRule } from \"./judge-rule.ts\";\nimport type { Judge } from \"./judge.ts\";\nimport type { Verdict } from \"./verdict.ts\";\n\nconst AGENT_CONCURRENCY = 4;\nconst SEQUENTIAL = 1;\nconst FIRST_COLUMN = 1;\nconst QUOTE_START = 0;\nconst QUOTE_LIMIT = 160;\nconst WHITESPACE = /\\s+/gu;\n\n/** @internal */\nexport interface JudgeSetup<Requirements> {\n readonly cacheDirectory: string;\n readonly rules: readonly JudgeRule[];\n readonly decision: Judge<DecisionInput, Requirements>;\n readonly agent: Judge<AgentInput, Requirements>;\n}\n\nconst oneLine = (text: string): string =>\n pipe(text, Str.replaceAll(WHITESPACE, \" \"), Str.trim, Str.slice(QUOTE_START, QUOTE_LIMIT));\n\nconst cachedBy =\n <Input extends JudgeInput, Requirements>(directory: string, judge: Judge<Input, Requirements>) =>\n (input: Input): Effect.Effect<Verdict, never, Requirements | RepositoryFiles> =>\n Effect.gen(function* cached() {\n const key = yield* cacheKeyOf(input, judge.identity);\n const hit = yield* readCached(directory, key);\n if (Option.isSome(hit)) {\n return hit.value;\n }\n const verdict = yield* judge.judge(input);\n yield* writeCached(directory, { key, verdict });\n return verdict;\n });\n\nconst problemOf = (\n file: string,\n { input, verdict }: { readonly input: JudgeInput; readonly verdict: Verdict },\n): Option.Option<Problem> => {\n const { rule } = input;\n if (verdict.status === \"pass\") {\n return Option.none();\n }\n if (verdict.status === \"unknown\") {\n return Option.some(\n problemInFile(\"judge-unknown\")(file, `Could not decide ${rule.id}. ${verdict.reason}`),\n );\n }\n return Option.some(\n problemAtPosition(rule.id)(\n file,\n { line: verdict.line, column: FIRST_COLUMN },\n `${rule.message} ${verdict.reason} Quoted: ${oneLine(verdict.quote)}`,\n ),\n );\n};\n\n/** @internal */\nexport const judgeRepository = Effect.fn(\"judgeRepository\")(function* judgeRepository<Requirements>(\n root: string,\n setup: JudgeSetup<Requirements>,\n) {\n const files = yield* RepositoryFiles;\n const inputs = yield* judgeInputs(root, setup.rules);\n const decisions = pipe(inputs, Arr.filter(isDecisionInput));\n const agents = pipe(inputs, Arr.filter(isAgentInput));\n const decided = yield* Effect.forEach(decisions, cachedBy(setup.cacheDirectory, setup.decision), {\n concurrency: SEQUENTIAL,\n });\n const reasoned = yield* Effect.forEach(agents, cachedBy(setup.cacheDirectory, setup.agent), {\n concurrency: AGENT_CONCURRENCY,\n });\n const answered: readonly JudgeInput[] = [...decisions, ...agents];\n return pipe(\n Arr.zip(answered, [...decided, ...reasoned]),\n Arr.map(([input, verdict]) =>\n problemOf(files.join(root, input.target.name), { input, verdict }),\n ),\n Arr.getSomes,\n );\n});\n","#!/usr/bin/env node\nimport { Array as Arr, Effect, Schema, Stdio, pipe } from \"effect\";\n\nimport { failWhenAny, writeJsonProblems, writeProblems } from \"#/app/output.ts\";\nimport { runCli } from \"#/app/runtime.ts\";\nimport {\n CLAUDE,\n DECISION_JUDGE,\n JUDGE_RULES,\n agentJudge,\n judgeRepository,\n} from \"#/features/judge-documents/index.ts\";\nimport { JSON_FLAG } from \"#/shared/lib/cli-contract.ts\";\nimport { sortProblems } from \"#/shared/lib/problem.ts\";\nimport type { Problem } from \"#/shared/lib/problem.ts\";\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\n\nconst taggedError = Schema.TaggedError;\n\nclass UsageError extends taggedError<UsageError, { readonly brand: unique symbol }>()(\n \"UsageError\",\n { message: Schema.String },\n) {}\n\nconst USAGE = `usage: msch-judge <cache directory> [${JSON_FLAG}]`;\n\nconst Arguments = Schema.Tuple([Schema.NonEmptyString]);\n\nconst cacheDirectoryOf = Effect.fn(\"cacheDirectoryOf\")(function* cacheDirectoryOf(\n args: readonly string[],\n) {\n const positional = pipe(\n args,\n Arr.filter((arg) => arg !== JSON_FLAG),\n );\n const [directory] = yield* Schema.decodeUnknownEffect(Arguments)(positional).pipe(\n Effect.mapError(() => UsageError.make({ message: USAGE })),\n );\n return directory;\n});\n\nconst report = Effect.fn(\"report\")(function* report(\n root: string,\n { problems, json }: { readonly problems: readonly Problem[]; readonly json: boolean },\n) {\n if (json) {\n return yield* writeJsonProblems(problems);\n }\n return yield* writeProblems(root)(problems);\n});\n\nconst judge = Effect.gen(function* judge() {\n const stdio = yield* Stdio.Stdio;\n const files = yield* RepositoryFiles;\n const args = yield* stdio.args;\n const directory = yield* cacheDirectoryOf(args);\n const root = files.resolve(\".\");\n const found = yield* judgeRepository(root, {\n cacheDirectory: files.resolve(directory),\n rules: JUDGE_RULES,\n decision: DECISION_JUDGE,\n agent: agentJudge(CLAUDE),\n });\n const problems = sortProblems(found);\n yield* report(root, { problems, json: Arr.contains(args, JSON_FLAG) });\n return yield* failWhenAny(problems.length);\n});\n\nrunCli(\"msch-judge\")(judge);\n"],"mappings":";;;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I,CAAC,CAAC,QAAQ;AAC5C,CAAC;AAED,MAAM,QAAQ,OAAO,IAAI,UAAU,QAAQ;CACzC,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,QAAQ,OAAO;CACrB,MAAM,OAAO,OAAO,MAAM;CAC1B,MAAM,YAAY,OAAO,iBAAiB,IAAI;CAC9C,MAAM,OAAO,MAAM,QAAQ,GAAG;CAC9B,MAAM,QAAQ,OAAO,gBAAgB,MAAM;EACzC,gBAAgB,MAAM,QAAQ,SAAS;EACvC,OAAO;EACP,UAAU;EACV,OAAO,WAAW,MAAM;CAC1B,CAAC;CACD,MAAM,WAAW,aAAa,KAAK;CACnC,OAAO,OAAO,MAAM;EAAE;EAAU,MAAMA,MAAI,SAAS,MAAM,SAAS;CAAE,CAAC;CACrE,OAAO,OAAO,YAAY,SAAS,MAAM;AAC3C,CAAC;AAED,OAAO,YAAY,CAAC,CAAC,KAAK"}
@@ -1,29 +0,0 @@
1
- import { t as JSON_FLAG } from "./cli-contract-D7btWrEu.mjs";
2
- import { r as RepositoryFiles } from "./repository-files-DSwKJnrj.mjs";
3
- import { a as writeStdout, t as ProblemsFound } from "./output-DAvdel9H.mjs";
4
- import { Array, Effect, Order, Schema, Stdio, pipe } from "effect";
5
- // src/app/lookup-report.ts
6
- const NONE_FOUND = 0;
7
- const LINE_BREAK = "\n";
8
- const byPlace = Order.Struct({
9
- file: Order.String,
10
- line: Order.Number
11
- });
12
- const textOf = (row, describe) => (json, rows) => {
13
- if (json) return Schema.encodeEffect(row.pipe(Schema.Array, Schema.fromJsonString))(rows);
14
- return Effect.succeed(pipe(rows, Array.map((found) => `${describe(found)}${LINE_BREAK}`), Array.join("")));
15
- };
16
- /** @internal */
17
- const lookupReport = ({ row, rows, describe }) => Effect.gen(function* report() {
18
- const stdio = yield* Stdio.Stdio;
19
- const files = yield* RepositoryFiles;
20
- const args = yield* stdio.args;
21
- const found = yield* rows(files.resolve("."));
22
- const text = yield* textOf(row, describe)(Array.contains(args, JSON_FLAG), Array.sort(found, byPlace));
23
- yield* writeStdout(text);
24
- if (found.length > NONE_FOUND) return yield* ProblemsFound.make({ count: found.length });
25
- return NONE_FOUND;
26
- });
27
- export { lookupReport as t };
28
-
29
- //# sourceMappingURL=lookup-report-L5OLXRMf.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lookup-report-L5OLXRMf.mjs","names":["Arr"],"sources":["../src/app/lookup-report.ts"],"sourcesContent":["import { Array as Arr, Effect, Order, Schema, Stdio, pipe } from \"effect\";\n\nimport { JSON_FLAG } from \"#/shared/lib/cli-contract.ts\";\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\n\nimport { ProblemsFound, writeStdout } from \"./output.ts\";\n\nconst NONE_FOUND = 0;\nconst LINE_BREAK = \"\\n\";\n\nconst byPlace = Order.Struct({ file: Order.String, line: Order.Number });\n\n/** @internal */\nexport interface Place {\n readonly file: string;\n readonly line: number;\n}\n\n/** @internal */\nexport interface LookupReport<Row extends Place, Failure, Requirements> {\n readonly row: Schema.Codec<Row>;\n readonly rows: (root: string) => Effect.Effect<readonly Row[], Failure, Requirements>;\n readonly describe: (row: Row) => string;\n}\n\nconst textOf =\n <Row extends Place>(row: Schema.Codec<Row>, describe: (row: Row) => string) =>\n (json: boolean, rows: readonly Row[]): Effect.Effect<string, Schema.SchemaError> => {\n if (json) {\n return Schema.encodeEffect(row.pipe(Schema.Array, Schema.fromJsonString))(rows);\n }\n return Effect.succeed(\n pipe(\n rows,\n Arr.map((found) => `${describe(found)}${LINE_BREAK}`),\n Arr.join(\"\"),\n ),\n );\n };\n\n/** @internal */\nexport const lookupReport = <Row extends Place, Failure, Requirements>({\n row,\n rows,\n describe,\n}: LookupReport<Row, Failure, Requirements>): Effect.Effect<\n number,\n Failure | Schema.SchemaError | ProblemsFound,\n Requirements | RepositoryFiles | Stdio.Stdio\n> =>\n Effect.gen(function* report() {\n const stdio = yield* Stdio.Stdio;\n const files = yield* RepositoryFiles;\n const args = yield* stdio.args;\n const found = yield* rows(files.resolve(\".\"));\n const text = yield* textOf(row, describe)(\n Arr.contains(args, JSON_FLAG),\n Arr.sort(found, byPlace),\n );\n yield* writeStdout(text);\n if (found.length > NONE_FOUND) {\n return yield* ProblemsFound.make({ count: found.length });\n }\n return NONE_FOUND;\n });\n"],"mappings":";;;;;AAOA,MAAM,aAAa;AACnB,MAAM,aAAa;AAEnB,MAAM,UAAU,MAAM,OAAO;CAAE,MAAM,MAAM;CAAQ,MAAM,MAAM;AAAO,CAAC;AAevE,MAAM,UACgB,KAAwB,cAC3C,MAAe,SAAoE;CAClF,IAAI,MACF,OAAO,OAAO,aAAa,IAAI,KAAK,OAAO,OAAO,OAAO,cAAc,CAAC,CAAC,CAAC,IAAI;CAEhF,OAAO,OAAO,QACZ,KACE,MACAA,MAAI,KAAK,UAAU,GAAG,SAAS,KAAK,IAAI,YAAY,GACpDA,MAAI,KAAK,EAAE,CACb,CACF;AACF;;AAGF,MAAa,gBAA0D,EACrE,KACA,MACA,eAMA,OAAO,IAAI,UAAU,SAAS;CAC5B,MAAM,QAAQ,OAAO,MAAM;CAC3B,MAAM,QAAQ,OAAO;CACrB,MAAM,OAAO,OAAO,MAAM;CAC1B,MAAM,QAAQ,OAAO,KAAK,MAAM,QAAQ,GAAG,CAAC;CAC5C,MAAM,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CACvCA,MAAI,SAAS,MAAM,SAAS,GAC5BA,MAAI,KAAK,OAAO,OAAO,CACzB;CACA,OAAO,YAAY,IAAI;CACvB,IAAI,MAAM,SAAS,YACjB,OAAO,OAAO,cAAc,KAAK,EAAE,OAAO,MAAM,OAAO,CAAC;CAE1D,OAAO;AACT,CAAC"}
@@ -1,19 +0,0 @@
1
- import { r as RepositoryFiles } from "./repository-files-DSwKJnrj.mjs";
2
- import { Array, Effect, Option, pipe } from "effect";
3
- // src/shared/lib/manifest-texts.ts
4
- const MANIFEST = /(?:^|\/)package\.json$/u;
5
- const READ_CONCURRENCY = 16;
6
- /** @internal */
7
- const manifestTexts = Effect.fn("manifestTexts")(function* manifestTexts(root) {
8
- const files = yield* RepositoryFiles;
9
- const listed = yield* files.listedFiles(root);
10
- const names = pipe(listed, Array.filter((name) => MANIFEST.test(name)));
11
- const read = yield* Effect.forEach(names, (file) => Effect.map(files.readFile(files.join(root, file)), Option.map((text) => ({
12
- file,
13
- text
14
- }))), { concurrency: READ_CONCURRENCY });
15
- return Array.getSomes(read);
16
- });
17
- export { manifestTexts as t };
18
-
19
- //# sourceMappingURL=manifest-texts-DPgsV8kj.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"manifest-texts-DPgsV8kj.mjs","names":["Arr"],"sources":["../src/shared/lib/manifest-texts.ts"],"sourcesContent":["import { Array as Arr, Effect, Option, pipe } from \"effect\";\n\nimport { RepositoryFiles } from \"./repository-files.ts\";\n\nconst MANIFEST = /(?:^|\\/)package\\.json$/u;\nconst READ_CONCURRENCY = 16;\n\n/** @internal */\nexport interface ManifestText {\n readonly file: string;\n readonly text: string;\n}\n\n/** @internal */\nexport const manifestTexts = Effect.fn(\"manifestTexts\")(function* manifestTexts(root: string) {\n const files = yield* RepositoryFiles;\n const listed = yield* files.listedFiles(root);\n const names = pipe(\n listed,\n Arr.filter((name) => MANIFEST.test(name)),\n );\n const read = yield* Effect.forEach(\n names,\n (file) =>\n Effect.map(\n files.readFile(files.join(root, file)),\n Option.map((text): ManifestText => ({ file, text })),\n ),\n { concurrency: READ_CONCURRENCY },\n );\n return Arr.getSomes(read);\n});\n"],"mappings":";;;AAIA,MAAM,WAAW;AACjB,MAAM,mBAAmB;;AASzB,MAAa,gBAAgB,OAAO,GAAG,eAAe,CAAC,CAAC,UAAU,cAAc,MAAc;CAC5F,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,OAAO,MAAM,YAAY,IAAI;CAC5C,MAAM,QAAQ,KACZ,QACAA,MAAI,QAAQ,SAAS,SAAS,KAAK,IAAI,CAAC,CAC1C;CACA,MAAM,OAAO,OAAO,OAAO,QACzB,QACC,SACC,OAAO,IACL,MAAM,SAAS,MAAM,KAAK,MAAM,IAAI,CAAC,GACrC,OAAO,KAAK,UAAwB;EAAE;EAAM;CAAK,EAAE,CACrD,GACF,EAAE,aAAa,iBAAiB,CAClC;CACA,OAAOA,MAAI,SAAS,IAAI;AAC1B,CAAC"}
@@ -1,33 +0,0 @@
1
- import { r as formatProblem, t as ProblemList } from "./problem-DbuTeNvL.mjs";
2
- import { r as RepositoryFiles } from "./repository-files-DSwKJnrj.mjs";
3
- import { Array, Effect, Runtime, Schema, Stdio, Stream, pipe } from "effect";
4
- // src/app/output.ts
5
- const taggedError = Schema.TaggedError;
6
- const NO_PROBLEMS = 0;
7
- var ProblemsFound = class extends taggedError()("ProblemsFound", { count: Schema.Finite }) {
8
- [Runtime.errorReported] = false;
9
- };
10
- /** @internal */
11
- const writeStdout = Effect.fn("writeStdout")(function* writeStdout(text) {
12
- const stdio = yield* Stdio.Stdio;
13
- yield* Stream.make(text).pipe(Stream.run(stdio.stdout()), Effect.orDie);
14
- });
15
- /** @internal */
16
- const writeProblems = (root) => (problems) => Effect.gen(function* report() {
17
- const files = yield* RepositoryFiles;
18
- const format = formatProblem((file) => files.relative(root, file));
19
- yield* writeStdout(pipe(problems, Array.map((problem) => `${format(problem)}\n`), Array.join("")));
20
- });
21
- /** @internal */
22
- const writeJsonProblems = Effect.fn("writeJsonProblems")(function* writeJsonProblems(problems) {
23
- const text = yield* Schema.encodeEffect(Schema.fromJsonString(ProblemList))(problems);
24
- return yield* writeStdout(text);
25
- });
26
- /** @internal */
27
- const failWhenAny = (count) => {
28
- if (count > NO_PROBLEMS) return Effect.fail(ProblemsFound.make({ count }));
29
- return Effect.void;
30
- };
31
- export { writeStdout as a, writeProblems as i, failWhenAny as n, writeJsonProblems as r, ProblemsFound as t };
32
-
33
- //# sourceMappingURL=output-DAvdel9H.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"output-DAvdel9H.mjs","names":["Arr"],"sources":["../src/app/output.ts"],"sourcesContent":["import { Array as Arr, Effect, Runtime, Schema, Stdio, Stream, pipe } from \"effect\";\n\nimport { ProblemList, formatProblem } from \"#/shared/lib/problem.ts\";\nimport type { Problem } from \"#/shared/lib/problem.ts\";\nimport { RepositoryFiles } from \"#/shared/lib/repository-files.ts\";\n\nconst taggedError = Schema.TaggedError;\nconst NO_PROBLEMS = 0;\n\nexport class ProblemsFound extends taggedError<ProblemsFound, { readonly brand: unique symbol }>()(\n \"ProblemsFound\",\n {\n count: Schema.Finite,\n },\n) {\n public override readonly [Runtime.errorReported] = false;\n}\n\n/** @internal */\nexport const writeStdout = Effect.fn(\"writeStdout\")(function* writeStdout(text: string) {\n const stdio = yield* Stdio.Stdio;\n yield* Stream.make(text).pipe(Stream.run(stdio.stdout()), Effect.orDie);\n});\n\n/** @internal */\nexport const writeProblems =\n (root: string) =>\n (problems: readonly Problem[]): Effect.Effect<void, never, RepositoryFiles | Stdio.Stdio> =>\n Effect.gen(function* report() {\n const files = yield* RepositoryFiles;\n const format = formatProblem((file) => files.relative(root, file));\n yield* writeStdout(\n pipe(\n problems,\n Arr.map((problem) => `${format(problem)}\\n`),\n Arr.join(\"\"),\n ),\n );\n });\n\n/** @internal */\nexport const writeJsonProblems = Effect.fn(\"writeJsonProblems\")(function* writeJsonProblems(\n problems: readonly Problem[],\n) {\n const text = yield* Schema.encodeEffect(Schema.fromJsonString(ProblemList))(problems);\n return yield* writeStdout(text);\n});\n\n/** @internal */\nexport const failWhenAny = (count: number): Effect.Effect<void, ProblemsFound> => {\n if (count > NO_PROBLEMS) {\n return Effect.fail(ProblemsFound.make({ count }));\n }\n return Effect.void;\n};\n"],"mappings":";;;;AAMA,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc;AAEpB,IAAa,gBAAb,cAAmC,YAA8D,CAAC,CAChG,iBACA,EACE,OAAO,OAAO,OAChB,CACF,CAAC,CAAC;CACA,CAA0B,QAAQ,iBAAiB;AACrD;;AAGA,MAAa,cAAc,OAAO,GAAG,aAAa,CAAC,CAAC,UAAU,YAAY,MAAc;CACtF,MAAM,QAAQ,OAAO,MAAM;CAC3B,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,KAAK,OAAO,IAAI,MAAM,OAAO,CAAC,GAAG,OAAO,KAAK;AACxE,CAAC;;AAGD,MAAa,iBACV,UACA,aACC,OAAO,IAAI,UAAU,SAAS;CAC5B,MAAM,QAAQ,OAAO;CACrB,MAAM,SAAS,eAAe,SAAS,MAAM,SAAS,MAAM,IAAI,CAAC;CACjE,OAAO,YACL,KACE,UACAA,MAAI,KAAK,YAAY,GAAG,OAAO,OAAO,EAAE,GAAG,GAC3CA,MAAI,KAAK,EAAE,CACb,CACF;AACF,CAAC;;AAGL,MAAa,oBAAoB,OAAO,GAAG,mBAAmB,CAAC,CAAC,UAAU,kBACxE,UACA;CACA,MAAM,OAAO,OAAO,OAAO,aAAa,OAAO,eAAe,WAAW,CAAC,CAAC,CAAC,QAAQ;CACpF,OAAO,OAAO,YAAY,IAAI;AAChC,CAAC;;AAGD,MAAa,eAAe,UAAsD;CAChF,IAAI,QAAQ,aACV,OAAO,OAAO,KAAK,cAAc,KAAK,EAAE,MAAM,CAAC,CAAC;CAElD,OAAO,OAAO;AAChB"}