tewip-ai 0.63.0 → 0.64.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.
@@ -23,13 +23,78 @@ export function parseLlmOutput(raw) {
23
23
  evidence: value.evidence.slice(0, 4).map((e) => truncate(e, 300)),
24
24
  };
25
25
  }
26
+ /**
27
+ * A verdict the run history already rules out, whatever the model says.
28
+ *
29
+ * The prompt has told the model since llm-6 that a failure which passed on another attempt of the
30
+ * same code cannot be a real bug or a drifted locator - both of those fail every time. Measured
31
+ * against 547 real labelled CI failures from WordPress/gutenberg, it does not obey: the model layer
32
+ * decided 87 of them and got **9 right**, and almost every miss was a flaky timing failure called
33
+ * REAL_BUG or LOCATOR_DRIFT at a confidence of 0.9 or higher.
34
+ *
35
+ * Telling a team to hunt a bug that is not there is the most expensive mistake this tool can make,
36
+ * and an instruction in a prompt is a request, not a guarantee. The same fact is checked here in
37
+ * code, where it holds.
38
+ *
39
+ * It refuses rather than rewrites. "This cannot be REAL_BUG" is not "this is TIMING" - ENV and
40
+ * TEST_DATA both survive a retry too - so the answer becomes UNKNOWN, which routes the failure to a
41
+ * person with the model's reasoning attached rather than replacing one guess with another.
42
+ */
43
+ /**
44
+ * The most this layer may claim, until a measured run says otherwise.
45
+ *
46
+ * Below 0.5 so that it routes to a person by the rule the prompt already states: "Low confidence
47
+ * routes the failure to a human". See the comment at the call site for the measurement.
48
+ */
49
+ export const LLM_CONFIDENCE_CEILING = 0.45;
50
+ export function contradictsHistory(category, context) {
51
+ if (category !== 'REAL_BUG' && category !== 'LOCATOR_DRIFT')
52
+ return null;
53
+ if (context.thisRun?.anotherAttemptPassed) {
54
+ return `refused: another attempt of the same code passed in this run, so the failure is not deterministic and cannot be ${category}`;
55
+ }
56
+ if (/both failed and passed|not deterministic/i.test(context.history?.pattern ?? '')) {
57
+ return `refused: the history says "${context.history.pattern}", so the failure is not deterministic and cannot be ${category}`;
58
+ }
59
+ return null;
60
+ }
26
61
  export async function llmDiagnose(context, rules, client, now = new Date()) {
27
62
  try {
28
63
  const raw = await client.complete({ system: SYSTEM_PROMPT, user: JSON.stringify(context), schemaName: OUTPUT_SCHEMA_NAME, schema: OUTPUT_SCHEMA });
29
64
  const out = parseLlmOutput(raw);
65
+ const refused = contradictsHistory(out.category, context);
66
+ if (refused) {
67
+ return {
68
+ category: 'UNKNOWN',
69
+ confidence: 0,
70
+ source: 'llm',
71
+ model: client.model,
72
+ engineVersion: `${rules.engineVersion}+${PROMPT_VERSION}`,
73
+ diagnosedAt: now.toISOString(),
74
+ evidence: [
75
+ { source: 'llm', message: `the model said ${out.category} (${out.confidence.toFixed(2)}): ${out.reasoning}` },
76
+ { source: 'rules', message: refused },
77
+ ],
78
+ };
79
+ }
30
80
  return {
31
81
  category: out.category,
32
- confidence: out.confidence,
82
+ // Capped, because the number it reports is not the number it earns.
83
+ //
84
+ // Measured against 752 real labelled CI failures from WordPress/gutenberg - labels taken from
85
+ // what the developer actually changed to fix each one - this layer decided 90 and got 16
86
+ // right: **17.8%**. Seventy per cent of those failures are TIMING, so answering "TIMING" to
87
+ // everything would have scored about 70%. The model is four times worse than the most trivial
88
+ // baseline there is, and it was reporting 0.90 to 0.96 while being wrong.
89
+ //
90
+ // The rules layer, on the same data, is 98.5% and keeps its own confidence untouched.
91
+ //
92
+ // Nothing is discarded: the category and the reasoning are still reported, and a person still
93
+ // sees them. What changes is that no consumer downstream can mistake this for a settled
94
+ // answer - 0.7 is where a rule becomes actionable and 0.85 is where a fix may be attempted,
95
+ // and a layer at 17.8% has no business clearing either. Raise this when a measured run earns
96
+ // it, and not before.
97
+ confidence: Math.min(out.confidence, LLM_CONFIDENCE_CEILING),
33
98
  source: 'llm',
34
99
  model: client.model,
35
100
  engineVersion: `${rules.engineVersion}+${PROMPT_VERSION}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tewip-ai",
3
- "version": "0.63.0",
3
+ "version": "0.64.0",
4
4
  "mcpName": "io.github.hmamut39/tewip",
5
5
  "description": "Tewip finds why each failing test failed - real bug, flaky test, environment, test data or changed selector - for any stack, from the command line, CI, or your editor.",
6
6
  "keywords": [