@autotelic/joggle 0.0.0-stage → 0.1.2

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 (101) hide show
  1. package/JOGGLE.md +634 -0
  2. package/LICENSE +21 -0
  3. package/README.md +88 -2
  4. package/bin/joggle.js +6 -0
  5. package/dist/answer-store.js +305 -0
  6. package/dist/architecture.js +190 -0
  7. package/dist/ask.js +184 -0
  8. package/dist/astro.js +75 -0
  9. package/dist/atoms.js +76 -0
  10. package/dist/bundles.js +156 -0
  11. package/dist/calibration.js +60 -0
  12. package/dist/candidates.js +561 -0
  13. package/dist/canonical.js +24 -0
  14. package/dist/cascade.js +98 -0
  15. package/dist/check.js +854 -0
  16. package/dist/cluster.js +69 -0
  17. package/dist/config.js +195 -0
  18. package/dist/content-mappers.js +83 -0
  19. package/dist/decision.js +203 -0
  20. package/dist/fingerprint.js +61 -0
  21. package/dist/git.js +127 -0
  22. package/dist/gitignore.js +65 -0
  23. package/dist/glob.js +51 -0
  24. package/dist/imports.js +153 -0
  25. package/dist/jsonc.js +95 -0
  26. package/dist/main.js +630 -0
  27. package/dist/manifest.js +42 -0
  28. package/dist/meta.js +170 -0
  29. package/dist/moves.js +47 -0
  30. package/dist/operation.js +133 -0
  31. package/dist/parsecache.js +264 -0
  32. package/dist/plans.js +425 -0
  33. package/dist/plugin.js +71 -0
  34. package/dist/plugins.js +136 -0
  35. package/dist/policy.js +676 -0
  36. package/dist/presets/composition.js +32 -0
  37. package/dist/report.js +474 -0
  38. package/dist/reporting.js +132 -0
  39. package/dist/result.js +28 -0
  40. package/dist/roles.js +303 -0
  41. package/dist/rule.js +194 -0
  42. package/dist/rules/append-only-honoured.js +190 -0
  43. package/dist/rules/bundle-conformance.js +245 -0
  44. package/dist/rules/call-pattern.js +209 -0
  45. package/dist/rules/cluster-verdict.js +700 -0
  46. package/dist/rules/compose-types.js +250 -0
  47. package/dist/rules/data-error-as-outage.js +482 -0
  48. package/dist/rules/declared-staleness.js +242 -0
  49. package/dist/rules/dependency-fit.js +297 -0
  50. package/dist/rules/deviation-has-a-shape.js +225 -0
  51. package/dist/rules/doc-matches-code.js +191 -0
  52. package/dist/rules/duplicate-call-run.js +240 -0
  53. package/dist/rules/duplicate-implementation.js +89 -0
  54. package/dist/rules/duplicate-meaning.js +130 -0
  55. package/dist/rules/fact-or-derivation.js +202 -0
  56. package/dist/rules/field-type-drift.js +373 -0
  57. package/dist/rules/generic-carries-a-caller.js +198 -0
  58. package/dist/rules/hoist-to-domain.js +288 -0
  59. package/dist/rules/import-architecture.js +393 -0
  60. package/dist/rules/index.js +105 -0
  61. package/dist/rules/inferred-over-recorded.js +214 -0
  62. package/dist/rules/intent-drift.js +286 -0
  63. package/dist/rules/invariant-has-a-reconciler.js +190 -0
  64. package/dist/rules/language-drift.js +234 -0
  65. package/dist/rules/meaning-switched-by-flag.js +189 -0
  66. package/dist/rules/module-direction.js +231 -0
  67. package/dist/rules/name-as-address.js +216 -0
  68. package/dist/rules/name-the-primitive.js +203 -0
  69. package/dist/rules/naming-drift.js +218 -0
  70. package/dist/rules/nullability-drift.js +220 -0
  71. package/dist/rules/object-shape.js +280 -0
  72. package/dist/rules/one-concept-one-type.js +243 -0
  73. package/dist/rules/page-needs-composition.js +227 -0
  74. package/dist/rules/reimplemented-primitive.js +283 -0
  75. package/dist/rules/reversal.js +264 -0
  76. package/dist/rules/rule-judgment.js +252 -0
  77. package/dist/rules/schema-excludes-domain-value.js +190 -0
  78. package/dist/rules/shallow-module.js +204 -0
  79. package/dist/rules/single-path.js +237 -0
  80. package/dist/rules/structural-collapse.js +198 -0
  81. package/dist/rules/temporal-coupling.js +205 -0
  82. package/dist/rules/types-over-logic.js +198 -0
  83. package/dist/rules/unaccounted-drop.js +190 -0
  84. package/dist/rules/unbounded-default-read.js +227 -0
  85. package/dist/run-cache.js +132 -0
  86. package/dist/schema.js +285 -0
  87. package/dist/similarity.js +119 -0
  88. package/dist/source.js +30 -0
  89. package/dist/sql.js +34 -0
  90. package/dist/stages.js +39 -0
  91. package/dist/state.js +65 -0
  92. package/dist/testing.js +131 -0
  93. package/dist/tsconfig-scope.js +32 -0
  94. package/dist/tsgo.js +127 -0
  95. package/dist/typefacts.js +455 -0
  96. package/dist/typetrace.js +283 -0
  97. package/dist/verdict.js +65 -0
  98. package/dist/vocabulary.js +365 -0
  99. package/dist/workspace.js +1963 -0
  100. package/extensions/joggle.ts +454 -0
  101. package/package.json +85 -3
@@ -0,0 +1,482 @@
1
+ import { Effect } from "effect";
2
+ import { parseSync } from "oxc-parser";
3
+ import { blockingErrors, isAstro, parseInputOf } from "../astro.js";
4
+ import { Decision } from "effect/ai";
5
+ import { Atoms } from "../atoms.js";
6
+ import { policy } from "../policy.js";
7
+ import { verdictsOf } from "../plans.js";
8
+ import { locator, messages, reporter } from "../reporting.js";
9
+ import { budgetNote, declined, marginOfAnswer, outcome, qualityOf, } from "../rule.js";
10
+ import { dataErrorVocabulary } from "../vocabulary.js";
11
+ const RULE_ID = "joggle/data-error-as-outage";
12
+ // A 5xx for a row that is not there.
13
+ //
14
+ // The amplifier the nullability work cannot see. A missing row is a normal
15
+ // outcome -- somebody deleted it, or the id is wrong -- and answering "the server
16
+ // is broken" turns one bad request into an outage signal: pagers, error budgets,
17
+ // retries against a request that will never succeed.
18
+ //
19
+ // THE CANDIDATE IS HIGH RECALL, AND IT DOES NOT DECIDE WHAT A ROW READ IS.
20
+ //
21
+ // An earlier version of this rule decided "does this branch read a row?" in code,
22
+ // by the callee's name: `find*`, `get*`, `load*`, and `parse*`. That was the
23
+ // classifier's work done ahead of time. Against a real repository it missed a
24
+ // read named inside a callback, a bare call, and a read whose verb was not on the
25
+ // list -- three false negatives a reviewer had to find by hand, because a
26
+ // candidate that is never sent cannot be recovered by any answer. So the code now
27
+ // finds the SHAPE that could be about a row (a nullish guard, or a catch, that
28
+ // answers a 5xx) and asks the model the question the names were guessing at.
29
+ //
30
+ // Two questions, atomic, answered against the same state:
31
+ // about_a_row is the branch about a row in a data store? (Noul)
32
+ // verdict is the absent row normal, or a broken invariant? (Choice)
33
+ // Code composes them: report only when the branch IS about a row and the absence
34
+ // is normal. The names are gone; the state carries the answer.
35
+ /** The method names that emit an HTTP status. */
36
+ const STATUS_METHODS = new Set(["code", "status", "statusCode"]);
37
+ /** The node kinds that make a scope for the status walk. */
38
+ const FUNCTION_KINDS = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
39
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
40
+ /**
41
+ * The name a call names, bare or dotted: `getComments` -> `getComments`,
42
+ * `reply.code` -> `code`.
43
+ *
44
+ * Used only to READ a status or to describe a branch in the state. It no longer
45
+ * decides whether anything is a row read -- that is the question.
46
+ */
47
+ const calleeName = (callee) => {
48
+ if (!isRecord(callee))
49
+ return undefined;
50
+ if (callee["type"] === "Identifier" && typeof callee["name"] === "string")
51
+ return callee["name"];
52
+ if (callee["type"] !== "MemberExpression")
53
+ return undefined;
54
+ const property = callee["property"];
55
+ return isRecord(property) && typeof property["name"] === "string" ? property["name"] : undefined;
56
+ };
57
+ /**
58
+ * Visit every node under `root` that is NOT inside a nested function.
59
+ *
60
+ * The guard and the status have to belong to the SAME handler. A walk that
61
+ * descends into nested functions attributes an inner callback's status to an
62
+ * outer handler, which is a candidate that never existed.
63
+ */
64
+ const eachOwn = (root, visit) => {
65
+ const stack = [];
66
+ const pushChildren = (node) => {
67
+ for (const value of Object.values(node)) {
68
+ if (value !== null && typeof value === "object")
69
+ stack.push(value);
70
+ }
71
+ };
72
+ if (!isRecord(root))
73
+ return;
74
+ pushChildren(root);
75
+ while (stack.length > 0) {
76
+ const node = stack.pop();
77
+ if (Array.isArray(node)) {
78
+ for (const child of node)
79
+ stack.push(child);
80
+ continue;
81
+ }
82
+ if (!isRecord(node))
83
+ continue;
84
+ if (FUNCTION_KINDS.has(String(node["type"])))
85
+ continue;
86
+ visit(node);
87
+ pushChildren(node);
88
+ }
89
+ };
90
+ /** The variable a nullish guard tests: `!row`, `row == null`, `row === undefined`. */
91
+ const guardedVariable = (test) => {
92
+ if (!isRecord(test))
93
+ return undefined;
94
+ if (test["type"] === "UnaryExpression" && test["operator"] === "!" && isRecord(test["argument"])) {
95
+ const argument = test["argument"];
96
+ return argument["type"] === "Identifier" && typeof argument["name"] === "string"
97
+ ? argument["name"]
98
+ : undefined;
99
+ }
100
+ if (test["type"] === "BinaryExpression") {
101
+ const operator = test["operator"];
102
+ if (operator !== "==" && operator !== "===" && operator !== "!=" && operator !== "!==")
103
+ return undefined;
104
+ const sides = [test["left"], test["right"]];
105
+ const identifier = sides.find((side) => isRecord(side) && side["type"] === "Identifier");
106
+ const nullish = sides.some((side) => {
107
+ if (!isRecord(side))
108
+ return false;
109
+ if (side["type"] === "Literal") {
110
+ const value = side["value"];
111
+ const raw = side["raw"];
112
+ return value === null || raw === "null" || raw === "undefined";
113
+ }
114
+ return side["type"] === "Identifier" && side["name"] === "undefined";
115
+ });
116
+ return nullish && identifier !== undefined && typeof identifier["name"] === "string"
117
+ ? identifier["name"]
118
+ : undefined;
119
+ }
120
+ return undefined;
121
+ };
122
+ /** The 5xx emitted in this subtree: `.code(500)` or `x.statusCode = 503`. */
123
+ const outageIn = (root) => {
124
+ let found;
125
+ eachOwn(root, (node) => {
126
+ if (found !== undefined)
127
+ return;
128
+ if (node["type"] === "CallExpression" && STATUS_METHODS.has(calleeName(node["callee"]) ?? "")) {
129
+ const args = node["arguments"];
130
+ const first = Array.isArray(args) ? args[0] : undefined;
131
+ if (isRecord(first) && first["type"] === "Literal" && typeof first["value"] === "number") {
132
+ const code = first["value"];
133
+ if (code >= 500 && code <= 599)
134
+ found = code;
135
+ }
136
+ }
137
+ if (node["type"] === "AssignmentExpression" && isRecord(node["left"]) && isRecord(node["right"])) {
138
+ const left = node["left"];
139
+ const right = node["right"];
140
+ if (isRecord(left["property"]) &&
141
+ left["property"]["name"] === "statusCode" &&
142
+ right["type"] === "Literal" &&
143
+ typeof right["value"] === "number" &&
144
+ right["value"] >= 500 &&
145
+ right["value"] <= 599) {
146
+ found = right["value"];
147
+ }
148
+ }
149
+ });
150
+ return found;
151
+ };
152
+ /**
153
+ * One candidate per handler: a branch that could be about a row and answers a 5xx.
154
+ *
155
+ * No name decides this. A nullish guard with a 5xx inside, or a try whose catch
156
+ * answers a 5xx, is the shape; whether the branch is about a ROW is the question.
157
+ */
158
+ const candidatesIn = (workspace, scope) => {
159
+ const found = [];
160
+ for (const file of workspace.files) {
161
+ if (scope.changed !== undefined && !scope.changed.has(file.path))
162
+ continue;
163
+ // A cheap gate from the facts already indexed, so only a file that could hold
164
+ // a candidate is parsed a second time.
165
+ const names = file.facts.callSites.map((site) => site.name.split(".").at(-1) ?? "");
166
+ if (!names.some((name) => STATUS_METHODS.has(name)) && !file.text.includes("statusCode"))
167
+ continue;
168
+ const parsed = parseSync(file.path, parseInputOf({ file: file.path, text: file.text }), isAstro(file.path) ? { sourceType: "module", lang: "ts" } : undefined);
169
+ if (blockingErrors(file.path, parsed.errors).length > 0)
170
+ continue;
171
+ // Each function WITH its parent, so an anonymous handler can be named from the
172
+ // call it was handed to -- `fastify.decorate('getComments', async ...)`.
173
+ const functions = [];
174
+ const collect = (root) => {
175
+ const stack = [[root, undefined]];
176
+ while (stack.length > 0) {
177
+ const [node, parent] = stack.pop();
178
+ if (Array.isArray(node)) {
179
+ for (const child of node)
180
+ stack.push([child, parent]);
181
+ continue;
182
+ }
183
+ if (!isRecord(node))
184
+ continue;
185
+ if (FUNCTION_KINDS.has(String(node["type"])))
186
+ functions.push({ node, parent });
187
+ for (const value of Object.values(node)) {
188
+ if (value !== null && typeof value === "object")
189
+ stack.push([value, node]);
190
+ }
191
+ }
192
+ };
193
+ collect(parsed.program);
194
+ const nameFromCaller = (parent) => {
195
+ if (!isRecord(parent) || parent["type"] !== "CallExpression")
196
+ return undefined;
197
+ const args = parent["arguments"];
198
+ if (Array.isArray(args)) {
199
+ for (const arg of args) {
200
+ if (isRecord(arg) && typeof arg["value"] === "string" && arg["value"] !== "")
201
+ return arg["value"];
202
+ }
203
+ }
204
+ return calleeName(parent["callee"]);
205
+ };
206
+ for (const { node: handler, parent: handlerParent } of functions) {
207
+ const start = handler["start"];
208
+ if (typeof start !== "number")
209
+ continue;
210
+ const body = handler["body"];
211
+ if (body === undefined)
212
+ continue;
213
+ const line = file.text.slice(0, start).split("\n").length;
214
+ const handlerName = isRecord(handler["id"]) && typeof handler["id"]["name"] === "string"
215
+ ? handler["id"]["name"]
216
+ : (nameFromCaller(handlerParent) ?? "handler");
217
+ const source = file.text.slice(start, Math.min(file.text.length, start + policy.evidence.maxSourceChars));
218
+ let candidate;
219
+ // Narrower first: a guard on a value's absence. The guard shape is a subset
220
+ // of the catch shape's reach, so it is preferred when both are present.
221
+ eachOwn(body, (node) => {
222
+ if (candidate !== undefined || node["type"] !== "IfStatement")
223
+ return;
224
+ const guarded = guardedVariable(node["test"]);
225
+ if (guarded === undefined)
226
+ return;
227
+ const code = outageIn(node["consequent"]);
228
+ if (code === undefined)
229
+ return;
230
+ candidate = {
231
+ file: file.path,
232
+ line,
233
+ handler: handlerName,
234
+ reached: "guard",
235
+ trigger: guarded,
236
+ statusCode: code,
237
+ handlerSource: source,
238
+ };
239
+ });
240
+ // Wider: a catch that answers a 5xx. Whether the try read a row is the
241
+ // question, not a name lookup.
242
+ if (candidate === undefined) {
243
+ eachOwn(body, (node) => {
244
+ if (candidate !== undefined || node["type"] !== "TryStatement")
245
+ return;
246
+ const handlerNode = node["handler"];
247
+ if (!isRecord(handlerNode))
248
+ return;
249
+ const code = outageIn(handlerNode["body"]);
250
+ if (code === undefined)
251
+ return;
252
+ candidate = {
253
+ file: file.path,
254
+ line,
255
+ handler: handlerName,
256
+ reached: "catch",
257
+ trigger: "",
258
+ statusCode: code,
259
+ handlerSource: source,
260
+ };
261
+ });
262
+ }
263
+ if (candidate !== undefined)
264
+ found.push(candidate);
265
+ }
266
+ }
267
+ // Two handlers can share a start line once nested functions are in play; the
268
+ // identity is the file and the line, so one candidate is kept.
269
+ const seen = new Set();
270
+ return found.filter((entry) => {
271
+ const key = entry.file + "\u0000" + String(entry.line);
272
+ if (seen.has(key))
273
+ return false;
274
+ seen.add(key);
275
+ return true;
276
+ });
277
+ };
278
+ const labelOf = (outage) => outage.handler + " (" + outage.file + ":" + String(outage.line) + ")";
279
+ /** How the 5xx is reached, in the reader's terms. */
280
+ const describe = (outage) => outage.reached === "guard"
281
+ ? "when `" + outage.trigger + "` is empty"
282
+ : "when reading the row fails";
283
+ const findingFor = (report, outage, unverified) => report({
284
+ about: { file: outage.file, line: outage.line, column: 1 },
285
+ messageId: "outage",
286
+ data: {
287
+ handler: outage.handler,
288
+ code: outage.statusCode,
289
+ describe: describe(outage),
290
+ closing: unverified === undefined
291
+ ? "Pin a deliberate 5xx in .joggle/answers/ so the question is not asked again."
292
+ : "Not verified: " + unverified + ".",
293
+ },
294
+ helpId: "outage_help",
295
+ identity: [RULE_ID, outage.file, outage.handler, String(outage.statusCode)].join("\u0000"),
296
+ judged: unverified === undefined,
297
+ severity: "warn",
298
+ });
299
+ export const dataErrorAsOutage = {
300
+ id: RULE_ID,
301
+ severity: "warn",
302
+ description: "A 5xx answer to a row that is simply not there.",
303
+ judged: true,
304
+ onUnavailable: "report",
305
+ messages: messages({
306
+ outage: "`{{handler}}` answers {{code}} {{describe}}, so a missing row reads as a server outage.",
307
+ outage_help: "A lookup that finds nothing is usually a normal outcome: a 404, an empty list, or a 4xx the caller caused. If the absence really is a broken invariant, say so here; otherwise answer the request. {{closing}}",
308
+ }),
309
+ plan: Effect.fn("joggle/data-error-as-outage")(function* (workspace, scope) {
310
+ const report = reporter(dataErrorAsOutage, locator(workspace));
311
+ const all = candidatesIn(workspace, scope);
312
+ if (all.length === 0) {
313
+ return {
314
+ plans: [],
315
+ read: () => outcome([], [
316
+ "no branch answers a 5xx for a guarded or failed read: the guard and the status did not meet",
317
+ ]),
318
+ };
319
+ }
320
+ const budget = policy.dataError.maxHandlers;
321
+ const judged = all.slice(0, budget);
322
+ const overBudget = all.slice(budget).map((outage) => ({
323
+ ruleId: RULE_ID,
324
+ subject: labelOf(outage),
325
+ stage: "budget",
326
+ reason: "past the budget of " + String(budget) + " handlers",
327
+ }));
328
+ const atoms = yield* Atoms;
329
+ const planned = [];
330
+ for (const outage of judged) {
331
+ const id = yield* atoms.add({
332
+ handler: outage.handler,
333
+ reached: outage.reached,
334
+ status: outage.statusCode,
335
+ trigger: outage.trigger,
336
+ source: outage.handlerSource,
337
+ });
338
+ // The predicate the candidate used to guess at, now asked. Each shape gets
339
+ // the question it needs: a guard tests a VALUE (is it a row?), a catch wraps
340
+ // a TRY (does it read a row?). Asking a catch whether "the branch concerns a
341
+ // row" got "it is error handling" -- the branch is the catch, the read is the
342
+ // try, and the question has to point at the try.
343
+ const aboutInstructions = outage.reached === "guard"
344
+ ? [
345
+ `\`atoms[${id}].source\` is an HTTP handler that answers \`atoms[${id}].status\` when \`atoms[${id}].trigger\` is empty.`,
346
+ `Is \`atoms[${id}].trigger\` a row in a data store, so that an empty value is a row that is absent?`,
347
+ "Answer true when it is a database record or a stored entity.",
348
+ "Answer false when it is the request, a cache entry, configuration, an external service response, or an unrelated value.",
349
+ ]
350
+ : [
351
+ `\`atoms[${id}].source\` is an HTTP handler that answers \`atoms[${id}].status\` in a \`catch\`. The \`try\` it wraps is in \`atoms[${id}].source\`.`,
352
+ "Does that `try` read or decode a row in a data store, so that a missing or undecodable row is a plausible cause of the failure it catches?",
353
+ "Answer true when the try reads or decodes a database record or a stored entity.",
354
+ "Answer false when the try only writes, validates input, calls an external service, or does unrelated work.",
355
+ ];
356
+ const verdictInstructions = outage.reached === "guard"
357
+ ? [
358
+ `\`atoms[${id}].source\` answers \`atoms[${id}].status\` when \`atoms[${id}].trigger\` is empty.`,
359
+ "Is an empty row here a normal outcome, or a broken invariant?",
360
+ "Answer `row_absence_is_normal` when the request can legitimately name a row that is not there -- a wrong id, a deleted record, an empty result set.",
361
+ "Answer `row_absence_is_an_error` when an empty row here means data that must exist does not, so a 5xx is honest.",
362
+ "Answer `not_applicable` when the branch is not about a row's absence.",
363
+ ]
364
+ : [
365
+ `\`atoms[${id}].source\` answers \`atoms[${id}].status\` in a \`catch\`. The \`try\` it wraps is in \`atoms[${id}].source\`.`,
366
+ "When that read fails, is the likely cause a missing or undecodable row (a data fact), or a genuine server fault?",
367
+ "Answer `row_absence_is_normal` when the failure is the data being absent or undecodable -- a wrong id, a deleted record, a row that does not match the contract -- so a 5xx misreports a data fact as a server outage.",
368
+ "Answer `row_absence_is_an_error` when the failure is a genuine server fault, so a 5xx is honest.",
369
+ "Answer `not_applicable` when the branch is not about a row's absence.",
370
+ ];
371
+ planned.push({
372
+ outage,
373
+ plan: {
374
+ ruleId: RULE_ID,
375
+ subject: labelOf(outage),
376
+ concerns: [outage.file],
377
+ atoms: [id],
378
+ violations: { about_a_row: [] },
379
+ decisions: {
380
+ about_a_row: Decision.probability({
381
+ instructions: aboutInstructions.join("\n"),
382
+ criteria: {
383
+ false: "The branch is not about a row.",
384
+ true: "The branch is about a row.",
385
+ },
386
+ }),
387
+ verdict: Decision.classify({
388
+ instructions: verdictInstructions.join("\n"),
389
+ criteria: dataErrorVocabulary,
390
+ }),
391
+ },
392
+ read: (answers) => answers,
393
+ },
394
+ });
395
+ }
396
+ return {
397
+ plans: planned.map((entry) => entry.plan),
398
+ read: (answers) => {
399
+ const verdicts = verdictsOf(answers);
400
+ const diagnostics = [];
401
+ const drops = [...overBudget];
402
+ planned.forEach((entry, index) => {
403
+ const outage = entry.outage;
404
+ const answer = verdicts[index];
405
+ const about = answer === undefined ? undefined : answer["about_a_row"];
406
+ const verdict = answer === undefined ? undefined : answer["verdict"];
407
+ if (about === undefined ||
408
+ !("probability" in about) ||
409
+ verdict === undefined ||
410
+ !("label" in verdict)) {
411
+ // A nullish guard with a 5xx inside is specific enough to report
412
+ // without a judgement. A catch that answers a 5xx is not: every
413
+ // ordinary error handler has one, so reporting it unverified would
414
+ // be the noise the verification exists to remove.
415
+ if (outage.reached === "guard") {
416
+ diagnostics.push(findingFor(report, outage, "no judgement was available"));
417
+ }
418
+ else {
419
+ drops.push({
420
+ ruleId: RULE_ID,
421
+ subject: labelOf(outage),
422
+ stage: "unreadable",
423
+ reason: "not judged, and a `catch` that answers a 5xx is too common to report without one",
424
+ });
425
+ }
426
+ return;
427
+ }
428
+ // The verification the name prefixes used to skip: is this branch about
429
+ // a row at all? A low probability is the model saying no, which is a
430
+ // verdict, not a shrug -- so it is a decline, not a gate failure.
431
+ if (about.probability < policy.decision.gates.probabilityFloor) {
432
+ drops.push({
433
+ ruleId: RULE_ID,
434
+ subject: labelOf(outage),
435
+ stage: "declined",
436
+ reason: "the branch is not about a row (probability " + about.probability.toFixed(2) + ")",
437
+ });
438
+ return;
439
+ }
440
+ if (declined(verdict.label)) {
441
+ drops.push({
442
+ ruleId: RULE_ID,
443
+ subject: labelOf(outage),
444
+ stage: "declined",
445
+ reason: "the model read the branch as not about a row's absence",
446
+ });
447
+ return;
448
+ }
449
+ if (verdict.label !== "row_absence_is_normal") {
450
+ drops.push({
451
+ ruleId: RULE_ID,
452
+ subject: labelOf(outage),
453
+ stage: "declined",
454
+ reason: "the model read the absence as a broken invariant, so a 5xx is honest",
455
+ });
456
+ return;
457
+ }
458
+ const quality = qualityOf({
459
+ score: about.probability,
460
+ margin: marginOfAnswer(verdict),
461
+ confidence: verdict.confidence,
462
+ });
463
+ if (quality.quality === "drop") {
464
+ drops.push({ ruleId: RULE_ID, subject: labelOf(outage), stage: "gated", reason: quality.reason });
465
+ return;
466
+ }
467
+ diagnostics.push(findingFor(report, outage, quality.quality === "act" ? undefined : quality.reason));
468
+ });
469
+ return outcome(diagnostics, budgetNote({
470
+ unitKind: "handlers",
471
+ judged: budget,
472
+ candidates: all.length,
473
+ sample: all.slice(budget).map(labelOf),
474
+ }), drops);
475
+ },
476
+ };
477
+ }),
478
+ };
479
+ // meta-allow: no-pattern-classifier -- `status`, `code`, `statusCode` are the HTTP
480
+ // framework's own method names, a language-level fact like the `node:` builtins in
481
+ // dependency-fit, not this repository's naming. A checker host would make it exact;
482
+ // until then it is a framework vocabulary. docs/rule-coupling.md.