clarent-methods 0.1.0__py3-none-any.whl

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 (59) hide show
  1. clarent/__init__.py +2 -0
  2. clarent/__main__.py +5 -0
  3. clarent/_methods/ach/CARD.md +46 -0
  4. clarent/_methods/ach/clarent_ach/__init__.py +6 -0
  5. clarent/_methods/ach/clarent_ach/__main__.py +5 -0
  6. clarent/_methods/ach/clarent_ach/cli.py +123 -0
  7. clarent/_methods/ach/clarent_ach/engine.py +214 -0
  8. clarent/_methods/ach/clarent_ach/i18n.py +160 -0
  9. clarent/_methods/ach/clarent_ach/model.py +174 -0
  10. clarent/_methods/ach/clarent_ach/render.py +72 -0
  11. clarent/_methods/ach/examples/flaky-test.es.json +156 -0
  12. clarent/_methods/ach/examples/flaky-test.json +156 -0
  13. clarent/_methods/ach/method.toml +43 -0
  14. clarent/_methods/ach/skill/SKILL.md +58 -0
  15. clarent/_methods/ach/tests/test_ach.py +231 -0
  16. clarent/_methods/redteam/CARD.md +66 -0
  17. clarent/_methods/redteam/clarent_redteam/__init__.py +6 -0
  18. clarent/_methods/redteam/clarent_redteam/__main__.py +5 -0
  19. clarent/_methods/redteam/clarent_redteam/catalog.py +192 -0
  20. clarent/_methods/redteam/clarent_redteam/cli.py +189 -0
  21. clarent/_methods/redteam/clarent_redteam/engine.py +281 -0
  22. clarent/_methods/redteam/clarent_redteam/i18n.py +199 -0
  23. clarent/_methods/redteam/clarent_redteam/model.py +320 -0
  24. clarent/_methods/redteam/clarent_redteam/render.py +103 -0
  25. clarent/_methods/redteam/examples/design-doc/design.es.md +27 -0
  26. clarent/_methods/redteam/examples/design-doc/design.md +27 -0
  27. clarent/_methods/redteam/examples/design-doc/findings.es.json +132 -0
  28. clarent/_methods/redteam/examples/design-doc/findings.json +132 -0
  29. clarent/_methods/redteam/examples/design-doc/findings.rejected.json +130 -0
  30. clarent/_methods/redteam/examples/pr/change.diff +34 -0
  31. clarent/_methods/redteam/examples/pr/description.md +13 -0
  32. clarent/_methods/redteam/examples/pr/findings.json +114 -0
  33. clarent/_methods/redteam/method.toml +43 -0
  34. clarent/_methods/redteam/skill/SKILL.md +52 -0
  35. clarent/_methods/redteam/tests/test_redteam.py +640 -0
  36. clarent/_methods/triz-matrix/CARD.md +50 -0
  37. clarent/_methods/triz-matrix/clarent_triz/__init__.py +6 -0
  38. clarent/_methods/triz-matrix/clarent_triz/__main__.py +5 -0
  39. clarent/_methods/triz-matrix/clarent_triz/cli.py +184 -0
  40. clarent/_methods/triz-matrix/clarent_triz/data/DATA_LICENSE.md +51 -0
  41. clarent/_methods/triz-matrix/clarent_triz/data/catalog.json +89 -0
  42. clarent/_methods/triz-matrix/clarent_triz/data/matrix.json +11920 -0
  43. clarent/_methods/triz-matrix/clarent_triz/engine.py +103 -0
  44. clarent/_methods/triz-matrix/clarent_triz/i18n.py +134 -0
  45. clarent/_methods/triz-matrix/clarent_triz/model.py +179 -0
  46. clarent/_methods/triz-matrix/clarent_triz/render.py +101 -0
  47. clarent/_methods/triz-matrix/examples/search-api.es.json +9 -0
  48. clarent/_methods/triz-matrix/examples/search-api.json +9 -0
  49. clarent/_methods/triz-matrix/method.toml +58 -0
  50. clarent/_methods/triz-matrix/skill/SKILL.md +50 -0
  51. clarent/_methods/triz-matrix/tests/test_triz.py +306 -0
  52. clarent/cli.py +95 -0
  53. clarent/registry.py +175 -0
  54. clarent_methods-0.1.0.dist-info/METADATA +227 -0
  55. clarent_methods-0.1.0.dist-info/RECORD +59 -0
  56. clarent_methods-0.1.0.dist-info/WHEEL +4 -0
  57. clarent_methods-0.1.0.dist-info/entry_points.txt +2 -0
  58. clarent_methods-0.1.0.dist-info/licenses/LICENSE +202 -0
  59. clarent_methods-0.1.0.dist-info/licenses/NOTICE +12 -0
@@ -0,0 +1,174 @@
1
+ """Data model and validation for ACH (Analysis of Competing Hypotheses).
2
+
3
+ Stdlib only. Input format: JSON (see examples/flaky-test.json).
4
+
5
+ Key semantics
6
+ -------------
7
+ * Each *evidence* item is an observable statement ("the test fails only with -n 4").
8
+ * `ratings[h]` says how consistent that statement is with hypothesis h:
9
+ CC very consistent | C consistent | N neutral/not applicable | I inconsistent | II very inconsistent
10
+ * status="observed": already observed (enters the score).
11
+ * status="proposed": not observed yet; `ratings` are *predictions*
12
+ (which hypothesis predicts we would see this?). Only feeds `next`.
13
+ """
14
+ from __future__ import annotations
15
+
16
+ from dataclasses import dataclass, field
17
+
18
+ from .i18n import t
19
+
20
+ RATING_VALUE = {"CC": 2, "C": 1, "N": 0, "I": -1, "II": -2}
21
+ LEVEL_VALUE = {"low": 1, "medium": 2, "high": 3}
22
+ COST_VALUE = {"low": 1, "medium": 2, "high": 3}
23
+ STATUSES = ("observed", "proposed")
24
+
25
+ DEFAULT_REFUTE_THRESHOLD = 6
26
+
27
+
28
+ class ACHError(ValueError):
29
+ """Invalid input (reported to the user without a traceback)."""
30
+
31
+
32
+ @dataclass(frozen=True)
33
+ class Hypothesis:
34
+ id: str
35
+ text: str
36
+ catch_all: bool = False # "something else": never leads and is not used to separate tests
37
+
38
+
39
+ @dataclass(frozen=True)
40
+ class Evidence:
41
+ id: str
42
+ text: str
43
+ status: str
44
+ credibility: str
45
+ relevance: str
46
+ cost: str
47
+ ref: str
48
+ ratings: dict[str, str] = field(default_factory=dict)
49
+
50
+ @property
51
+ def weight(self) -> int:
52
+ """credibility x relevance, 1..9. Clarent's own parametrization."""
53
+ return LEVEL_VALUE[self.credibility] * LEVEL_VALUE[self.relevance]
54
+
55
+ def value(self, hid: str) -> int:
56
+ return RATING_VALUE[self.ratings.get(hid, "N")]
57
+
58
+
59
+ @dataclass(frozen=True)
60
+ class Analysis:
61
+ title: str
62
+ question: str
63
+ hypotheses: tuple[Hypothesis, ...]
64
+ evidence: tuple[Evidence, ...]
65
+ refute_threshold: int
66
+ warnings: tuple[str, ...]
67
+
68
+ @property
69
+ def observed(self) -> tuple[Evidence, ...]:
70
+ return tuple(e for e in self.evidence if e.status == "observed")
71
+
72
+ @property
73
+ def proposed(self) -> tuple[Evidence, ...]:
74
+ return tuple(e for e in self.evidence if e.status == "proposed")
75
+
76
+
77
+ def _need(d: dict, key: str, where: str) -> object:
78
+ if not isinstance(d, dict) or key not in d or d[key] in ("", None):
79
+ raise ACHError(t("missing_field", where=where, key=key))
80
+ return d[key]
81
+
82
+
83
+ def _level(d: dict, key: str, default: str, where: str, table: dict) -> str:
84
+ v = str(d.get(key, default)).lower()
85
+ if v not in table:
86
+ raise ACHError(t("bad_level", where=where, key=key, allowed=sorted(table), v=v))
87
+ return v
88
+
89
+
90
+ def parse(data: dict, *, strict: bool = False) -> Analysis:
91
+ """Validate `data` and return an Analysis. In strict mode warnings become errors."""
92
+ if not isinstance(data, dict):
93
+ raise ACHError(t("root_not_object"))
94
+ warnings: list[str] = []
95
+
96
+ raw_h = data.get("hypotheses")
97
+ if not isinstance(raw_h, list) or len(raw_h) < 2:
98
+ raise ACHError(t("need_2_hyp"))
99
+ hyps: list[Hypothesis] = []
100
+ for i, h in enumerate(raw_h):
101
+ where = f"hypotheses[{i}]"
102
+ hid = str(_need(h, "id", where))
103
+ if any(x.id == hid for x in hyps):
104
+ raise ACHError(t("dup_id", where=where, id=hid))
105
+ hyps.append(Hypothesis(hid, str(_need(h, "text", where)), bool(h.get("catch_all", False))))
106
+ hids = {h.id for h in hyps}
107
+
108
+ raw_e = data.get("evidence")
109
+ if not isinstance(raw_e, list) or not raw_e:
110
+ raise ACHError(t("need_1_ev"))
111
+ evs: list[Evidence] = []
112
+ for i, e in enumerate(raw_e):
113
+ where = f"evidence[{i}]"
114
+ eid = str(_need(e, "id", where))
115
+ if any(x.id == eid for x in evs):
116
+ raise ACHError(t("dup_id", where=where, id=eid))
117
+ status = str(e.get("status", "observed")).lower()
118
+ if status not in STATUSES:
119
+ raise ACHError(t("bad_status", where=where, allowed=STATUSES))
120
+ ratings_raw = e.get("ratings", {})
121
+ if not isinstance(ratings_raw, dict):
122
+ raise ACHError(t("ratings_not_obj", where=where))
123
+ ratings: dict[str, str] = {}
124
+ for hid, r in ratings_raw.items():
125
+ if hid not in hids:
126
+ raise ACHError(t("unknown_hyp", where=where, hid=hid))
127
+ r = str(r).upper()
128
+ if r not in RATING_VALUE:
129
+ raise ACHError(t("bad_rating", where=where, r=r, allowed=list(RATING_VALUE)))
130
+ ratings[hid] = r
131
+ missing = sorted(hids - set(ratings))
132
+ if missing:
133
+ warnings.append(t("w_missing_rating", eid=eid, ids=", ".join(missing)))
134
+ ref = str(e.get("ref", "")).strip()
135
+ if status == "observed" and not ref:
136
+ warnings.append(t("w_uncited", eid=eid))
137
+ evs.append(
138
+ Evidence(
139
+ id=eid,
140
+ text=str(_need(e, "text", where)),
141
+ status=status,
142
+ credibility=_level(e, "credibility", "medium", where, LEVEL_VALUE),
143
+ relevance=_level(e, "relevance", "medium", where, LEVEL_VALUE),
144
+ cost=_level(e, "cost", "medium", where, COST_VALUE),
145
+ ref=ref,
146
+ ratings=ratings,
147
+ )
148
+ )
149
+
150
+ if all(h.catch_all for h in hyps):
151
+ raise ACHError(t("all_catch_all"))
152
+ if len(hyps) < 3:
153
+ warnings.append(t("w_two_hyp"))
154
+ elif not any(h.catch_all for h in hyps):
155
+ warnings.append(t("w_no_catch_all"))
156
+ observed = [e for e in evs if e.status == "observed"]
157
+ if 0 < len(observed) < 4:
158
+ warnings.append(t("w_few_obs", n=len(observed)))
159
+ if observed and not any(
160
+ e.ratings.get(h.id) in ("I", "II") for e in observed for h in hyps
161
+ ):
162
+ warnings.append(t("w_only_confirms"))
163
+
164
+ threshold = int(data.get("refute_threshold", DEFAULT_REFUTE_THRESHOLD))
165
+ if strict and warnings:
166
+ raise ACHError(t("strict_fail") + "\n - " + "\n - ".join(warnings))
167
+ return Analysis(
168
+ title=str(data.get("title", "ACH analysis")),
169
+ question=str(data.get("question", "")),
170
+ hypotheses=tuple(hyps),
171
+ evidence=tuple(evs),
172
+ refute_threshold=threshold,
173
+ warnings=tuple(warnings),
174
+ )
@@ -0,0 +1,72 @@
1
+ """Markdown rendering of ACH results (meant to be pasted into a PR, issue or postmortem)."""
2
+ from __future__ import annotations
3
+
4
+ from .engine import Result
5
+ from .i18n import t
6
+ from .model import Analysis
7
+
8
+
9
+ def markdown(an: Analysis, res: Result) -> str:
10
+ L: list[str] = [f"# {t('h_title', title=an.title)}", ""]
11
+ if an.question:
12
+ L += [t("question", q=an.question), ""]
13
+
14
+ L += [f"## {t('h_conclusion')}", "", f"- {t('v_' + res.verdict)}"]
15
+ if res.verdict != "no-discrimination":
16
+ margin = t("margin", m=res.margin) if res.margin is not None else ""
17
+ L.append("- " + t("leaders", ids=", ".join(res.leaders)) + margin)
18
+ if res.fragile:
19
+ L.append(f"- {t('fragile_flag')}")
20
+ L += [f"- {t('not_probability')}", ""]
21
+
22
+ L += [f"## {t('h_ranking')}", "",
23
+ f"| # | {t('col_hyp')} | {t('col_incons')} | {t('col_state')} | {t('col_contra')} |",
24
+ "|---|-----------|---------------:|--------|-----------------|"]
25
+ for s in res.scores:
26
+ state = t("st_catch_all") if s.catch_all else (t("st_refuted") if s.refuted else t("st_alive"))
27
+ L.append(f"| {s.rank} | **{s.id}** {s.text} | {s.inconsistency} | {state} | "
28
+ f"{', '.join(s.contradicted_by) or '—'} |")
29
+ L.append("")
30
+
31
+ hyp_ids = [h.id for h in an.hypotheses]
32
+ L += [f"## {t('h_matrix')}", "",
33
+ f"| {t('col_evidence')} | {t('col_weight')} | " + " | ".join(hyp_ids) + " |",
34
+ "|-----------|-----:|" + "|".join(":-:" for _ in hyp_ids) + "|"]
35
+ for e in an.observed:
36
+ row = " | ".join(e.ratings.get(h, "N") for h in hyp_ids)
37
+ ref = f" _({e.ref})_" if e.ref else f" _{t('no_ref')}_"
38
+ L.append(f"| **{e.id}** {e.text}{ref} | {e.weight} | {row} |")
39
+ L.append("")
40
+
41
+ L += [f"## {t('h_diag')}", "",
42
+ f"| {t('col_evidence')} | {t('col_type')} | {t('col_spread')} | {t('col_spread_w')} |", "|---|---|--:|--:|"]
43
+ for d in res.diagnostics:
44
+ L.append(f"| {d.id} | {t('kind_' + d.kind)} | {d.spread} | {d.weighted} |")
45
+ non = [d.id for d in res.diagnostics if d.kind != "diagnostic"]
46
+ if non:
47
+ L += ["", t("non_diag", ids=", ".join(non))]
48
+ L.append("")
49
+
50
+ L += [f"## {t('h_sens')}", ""]
51
+ crit = [s for s in res.sensitivity if s.changes_leader]
52
+ if crit:
53
+ for s in crit:
54
+ L.append("- " + t("sens_item", eid=s.evidence_id, ids=", ".join(s.leaders_without)))
55
+ else:
56
+ L.append(f"- {t('sens_none')}")
57
+ L.append("")
58
+
59
+ L += [f"## {t('h_next')}", ""]
60
+ if res.next_tests:
61
+ L += [f"| {t('col_test')} | {t('col_priority')} | {t('col_for')} | {t('col_against')} |", "|---|--:|---|---|"]
62
+ for x in res.next_tests:
63
+ L.append(f"| **{x.id}** {x.text} | {x.priority} | {', '.join(x.separates) or '—'} | "
64
+ f"{', '.join(x.against) or '—'} |")
65
+ else:
66
+ L.append(f"- {t('no_next')}")
67
+ L.append("")
68
+
69
+ if res.warnings:
70
+ L += [f"## {t('h_warnings')}", ""] + [f"- {w}" for w in res.warnings] + [""]
71
+ L += ["---", t("footer"), ""]
72
+ return "\n".join(L)
@@ -0,0 +1,156 @@
1
+ {
2
+ "title": "test_checkout_total falla ~1 de cada 8 corridas de CI (EJEMPLO SINTÉTICO)",
3
+ "question": "¿Qué causa que test_checkout_total falle de forma intermitente en CI?",
4
+ "hypotheses": [
5
+ {
6
+ "id": "H1",
7
+ "text": "Condición de carrera entre workers xdist sobre un fixture de scope=session"
8
+ },
9
+ {
10
+ "id": "H2",
11
+ "text": "Dependencia del reloj/zona horaria (datetime.now cerca de un borde de día)"
12
+ },
13
+ {
14
+ "id": "H3",
15
+ "text": "Llamada de red real no mockeada que a veces responde lento o con error"
16
+ },
17
+ {
18
+ "id": "H4",
19
+ "text": "Orden no determinista de set/dict (PYTHONHASHSEED) altera una suma de floats"
20
+ },
21
+ {
22
+ "id": "H5",
23
+ "text": "Estado residual en la BD dejado por otro test que corre antes en el mismo worker"
24
+ },
25
+ {
26
+ "id": "H6",
27
+ "text": "Otra causa que no estoy considerando",
28
+ "catch_all": true
29
+ }
30
+ ],
31
+ "evidence": [
32
+ {
33
+ "id": "E1",
34
+ "text": "Con 'pytest -n 0' (serial) pasan 60/60 corridas; con '-n 4' falla 5/40",
35
+ "credibility": "high",
36
+ "relevance": "high",
37
+ "ref": "ci-runs.csv filas 1-100 (exportado de la UI de CI)",
38
+ "ratings": {
39
+ "H1": "CC",
40
+ "H2": "I",
41
+ "H3": "I",
42
+ "H4": "I",
43
+ "H5": "C",
44
+ "H6": "N"
45
+ }
46
+ },
47
+ {
48
+ "id": "E2",
49
+ "text": "Las 40 fallas están repartidas en las 24 horas del día, sin agruparse en un borde de día",
50
+ "credibility": "high",
51
+ "relevance": "medium",
52
+ "ref": "ci-runs.csv columna started_at",
53
+ "ratings": {
54
+ "H1": "N",
55
+ "H2": "II",
56
+ "H3": "N",
57
+ "H4": "N",
58
+ "H5": "N",
59
+ "H6": "N"
60
+ }
61
+ },
62
+ {
63
+ "id": "E3",
64
+ "text": "Con PYTHONHASHSEED=0 fijo y '-n 4' el test sigue fallando (3/40)",
65
+ "credibility": "high",
66
+ "relevance": "high",
67
+ "ref": "PYTHONHASHSEED=0 pytest -n 4 test_checkout.py (40 corridas)",
68
+ "ratings": {
69
+ "H1": "C",
70
+ "H2": "N",
71
+ "H3": "N",
72
+ "H4": "II",
73
+ "H5": "C",
74
+ "H6": "N"
75
+ }
76
+ },
77
+ {
78
+ "id": "E4",
79
+ "text": "Con red bloqueada (pytest-socket --disable-socket) y '-n 4' sigue fallando (4/40)",
80
+ "credibility": "high",
81
+ "relevance": "high",
82
+ "ref": "pytest --disable-socket -n 4 (40 corridas)",
83
+ "ratings": {
84
+ "H1": "C",
85
+ "H2": "N",
86
+ "H3": "II",
87
+ "H4": "N",
88
+ "H5": "C",
89
+ "H6": "N"
90
+ }
91
+ },
92
+ {
93
+ "id": "E5",
94
+ "text": "El assert falla porque order.items tiene 2 elementos en vez de 3 (falta uno), no por diferencia de centavos",
95
+ "credibility": "high",
96
+ "relevance": "medium",
97
+ "ref": "traceback de la falla del run #8812, línea 'assert total == 59.97'",
98
+ "ratings": {
99
+ "H1": "C",
100
+ "H2": "N",
101
+ "H3": "N",
102
+ "H4": "I",
103
+ "H5": "C",
104
+ "H6": "N"
105
+ }
106
+ },
107
+ {
108
+ "id": "T1",
109
+ "text": "Reproducir en serial con el mismo orden aleatorio de la falla (pytest-randomly --randomly-seed=<seed del run #8812>) también falla",
110
+ "status": "proposed",
111
+ "cost": "low",
112
+ "credibility": "high",
113
+ "relevance": "high",
114
+ "ratings": {
115
+ "H1": "II",
116
+ "H2": "N",
117
+ "H3": "N",
118
+ "H4": "N",
119
+ "H5": "CC",
120
+ "H6": "N"
121
+ }
122
+ },
123
+ {
124
+ "id": "T2",
125
+ "text": "Cambiar el fixture de scope=session a scope=function elimina las fallas en 200 corridas con '-n 4'",
126
+ "status": "proposed",
127
+ "cost": "medium",
128
+ "credibility": "high",
129
+ "relevance": "high",
130
+ "ratings": {
131
+ "H1": "CC",
132
+ "H2": "N",
133
+ "H3": "N",
134
+ "H4": "N",
135
+ "H5": "N",
136
+ "H6": "N"
137
+ }
138
+ },
139
+ {
140
+ "id": "T3",
141
+ "text": "Ejecutar el test 500 veces en serial dentro de un solo proceso falla al menos una vez",
142
+ "status": "proposed",
143
+ "cost": "low",
144
+ "credibility": "medium",
145
+ "relevance": "medium",
146
+ "ratings": {
147
+ "H1": "II",
148
+ "H2": "C",
149
+ "H3": "C",
150
+ "H4": "C",
151
+ "H5": "II",
152
+ "H6": "N"
153
+ }
154
+ }
155
+ ]
156
+ }
@@ -0,0 +1,156 @@
1
+ {
2
+ "title": "test_checkout_total fails ~1 in 8 CI runs (SYNTHETIC EXAMPLE)",
3
+ "question": "What makes test_checkout_total fail intermittently in CI?",
4
+ "hypotheses": [
5
+ {
6
+ "id": "H1",
7
+ "text": "Race condition between xdist workers on a session-scoped fixture"
8
+ },
9
+ {
10
+ "id": "H2",
11
+ "text": "Clock/timezone dependence (datetime.now near a day boundary)"
12
+ },
13
+ {
14
+ "id": "H3",
15
+ "text": "Real, unmocked network call that sometimes answers slowly or errors"
16
+ },
17
+ {
18
+ "id": "H4",
19
+ "text": "Non-deterministic set/dict ordering (PYTHONHASHSEED) changes a float sum"
20
+ },
21
+ {
22
+ "id": "H5",
23
+ "text": "Leftover DB state from another test that ran earlier on the same worker"
24
+ },
25
+ {
26
+ "id": "H6",
27
+ "text": "Something else I am not considering",
28
+ "catch_all": true
29
+ }
30
+ ],
31
+ "evidence": [
32
+ {
33
+ "id": "E1",
34
+ "text": "With 'pytest -n 0' (serial) 60/60 runs pass; with '-n 4' it fails 5/40",
35
+ "credibility": "high",
36
+ "relevance": "high",
37
+ "ref": "ci-runs.csv rows 1-100 (exported from the CI UI)",
38
+ "ratings": {
39
+ "H1": "CC",
40
+ "H2": "I",
41
+ "H3": "I",
42
+ "H4": "I",
43
+ "H5": "C",
44
+ "H6": "N"
45
+ }
46
+ },
47
+ {
48
+ "id": "E2",
49
+ "text": "The 40 failures are spread across all 24 hours of the day, not clustered at a day boundary",
50
+ "credibility": "high",
51
+ "relevance": "medium",
52
+ "ref": "ci-runs.csv column started_at",
53
+ "ratings": {
54
+ "H1": "N",
55
+ "H2": "II",
56
+ "H3": "N",
57
+ "H4": "N",
58
+ "H5": "N",
59
+ "H6": "N"
60
+ }
61
+ },
62
+ {
63
+ "id": "E3",
64
+ "text": "With PYTHONHASHSEED=0 fixed and '-n 4' the test still fails (3/40)",
65
+ "credibility": "high",
66
+ "relevance": "high",
67
+ "ref": "PYTHONHASHSEED=0 pytest -n 4 test_checkout.py (40 runs)",
68
+ "ratings": {
69
+ "H1": "C",
70
+ "H2": "N",
71
+ "H3": "N",
72
+ "H4": "II",
73
+ "H5": "C",
74
+ "H6": "N"
75
+ }
76
+ },
77
+ {
78
+ "id": "E4",
79
+ "text": "With the network blocked (pytest-socket --disable-socket) and '-n 4' it still fails (4/40)",
80
+ "credibility": "high",
81
+ "relevance": "high",
82
+ "ref": "pytest --disable-socket -n 4 (40 runs)",
83
+ "ratings": {
84
+ "H1": "C",
85
+ "H2": "N",
86
+ "H3": "II",
87
+ "H4": "N",
88
+ "H5": "C",
89
+ "H6": "N"
90
+ }
91
+ },
92
+ {
93
+ "id": "E5",
94
+ "text": "The assert fails because order.items has 2 elements instead of 3 (one is missing), not because of a cents difference",
95
+ "credibility": "high",
96
+ "relevance": "medium",
97
+ "ref": "traceback of the failure in run #8812, line 'assert total == 59.97'",
98
+ "ratings": {
99
+ "H1": "C",
100
+ "H2": "N",
101
+ "H3": "N",
102
+ "H4": "I",
103
+ "H5": "C",
104
+ "H6": "N"
105
+ }
106
+ },
107
+ {
108
+ "id": "T1",
109
+ "text": "Reproducing serially with the same random order as the failure (pytest-randomly --randomly-seed=<seed of run #8812>) also fails",
110
+ "status": "proposed",
111
+ "cost": "low",
112
+ "credibility": "high",
113
+ "relevance": "high",
114
+ "ratings": {
115
+ "H1": "II",
116
+ "H2": "N",
117
+ "H3": "N",
118
+ "H4": "N",
119
+ "H5": "CC",
120
+ "H6": "N"
121
+ }
122
+ },
123
+ {
124
+ "id": "T2",
125
+ "text": "Changing the fixture from scope=session to scope=function removes the failures in 200 runs with '-n 4'",
126
+ "status": "proposed",
127
+ "cost": "medium",
128
+ "credibility": "high",
129
+ "relevance": "high",
130
+ "ratings": {
131
+ "H1": "CC",
132
+ "H2": "N",
133
+ "H3": "N",
134
+ "H4": "N",
135
+ "H5": "N",
136
+ "H6": "N"
137
+ }
138
+ },
139
+ {
140
+ "id": "T3",
141
+ "text": "Running the test 500 times serially inside a single process fails at least once",
142
+ "status": "proposed",
143
+ "cost": "low",
144
+ "credibility": "medium",
145
+ "relevance": "medium",
146
+ "ratings": {
147
+ "H1": "II",
148
+ "H2": "C",
149
+ "H3": "C",
150
+ "H4": "C",
151
+ "H5": "II",
152
+ "H6": "N"
153
+ }
154
+ }
155
+ ]
156
+ }
@@ -0,0 +1,43 @@
1
+ id = "ach"
2
+ name = "Analysis of Competing Hypotheses"
3
+ version = "0.1.0"
4
+ family = "decision"
5
+ status = "reference" # spec | beta | stable | reference
6
+ summary = "Score competing causes by inconsistency, find non-discriminating evidence, and pick the next most informative test."
7
+
8
+ [python]
9
+ module = "clarent_ach" # importable package inside this folder; must expose register(subparsers) and main(argv)
10
+
11
+ [surfaces] # what this method ships today (the doctor checks that each 'true' exists)
12
+ cli = true
13
+ skill = true
14
+ agent = false
15
+ hook = false
16
+ mcp = false
17
+ action = false
18
+
19
+ # verification: read = opened and read | exists = confirmed to exist | blocked = exists, server blocks scripts | unverified = from memory
20
+ [[sources]]
21
+ title = "Heuer, Psychology of Intelligence Analysis (CIA/CSI, 1999)"
22
+ url = "https://www.cia.gov/resources/csi/books-monographs/psychology-of-intelligence-analysis-2/"
23
+ verification = "read"
24
+
25
+ [[sources]]
26
+ title = "Heuer, Psychology of Intelligence Analysis, full text (copy hosted by IALEIA): Chapter 8, Analysis of Competing Hypotheses, p. 95"
27
+ url = "https://www.ialeia.org/docs/Psychology_of_Intelligence_Analysis.pdf"
28
+ verification = "read"
29
+
30
+ [[sources]]
31
+ title = "UFMCS Red Team Handbook v5 (2011): ACH, p. 158; Key Assumptions Check, p. 151"
32
+ url = "https://newandimproved.com/wp-content/uploads/2014/04/ufmcs_red_team_handbook_apr2011.pdf"
33
+ verification = "read"
34
+
35
+ [[sources]]
36
+ title = "Heuer & Pherson, Structured Analytic Techniques for Intelligence Analysis (3rd ed.)"
37
+ citation = "ISBN-10 150636893X (as listed in web search results; not opened)"
38
+ verification = "exists"
39
+
40
+ [novelty]
41
+ checked_on = "2026-11-24"
42
+ status = "exists-but-weak" # none | exists-but-weak | exists-but-abandoned | well-covered
43
+ evidence = "Burton/Analysis-of-Competing-Hypotheses (112 stars, last push 2012); prompt-only ACH in product-on-purpose/thinking-framework-skills; no deterministic engine found"
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: ach
3
+ description: Diagnose a bug, flaky test or incident with competing hypotheses (Heuer's ACH). Use when several causes are plausible and you risk anchoring on the first one. Outputs a scored matrix and the most discriminating next test.
4
+ disable-model-invocation: true
5
+ argument-hint: [problem description]
6
+ ---
7
+
8
+ # ACH — Analysis of Competing Hypotheses
9
+
10
+ You are running a disciplined diagnosis. The goal is **to refute hypotheses, not to confirm them**. A bundled script does the scoring; your job is to supply honest, *cited* evidence and honest ratings.
11
+
12
+ Problem: $ARGUMENTS
13
+
14
+ ## Tooling
15
+
16
+ The engine is stdlib-only Python. Run it with whichever of `python3` / `python` exists:
17
+
18
+ ```bash
19
+ python3 "${CLAUDE_SKILL_DIR}/scripts/run.py" init .clarent/ach/<slug>.json
20
+ python3 "${CLAUDE_SKILL_DIR}/scripts/run.py" score .clarent/ach/<slug>.json
21
+ python3 "${CLAUDE_SKILL_DIR}/scripts/run.py" next .clarent/ach/<slug>.json
22
+ ```
23
+
24
+ Add `--lang es` before the subcommand for Spanish output. Use `--strict` once you believe the file is final.
25
+
26
+ ## Procedure
27
+
28
+ 1. **Frame.** `init` a file. Write the `question` as one sentence a stranger could answer.
29
+ 2. **Key assumptions.** List what you are currently assuming (e.g. "the test fails in the code under test, not in the harness"). Any assumption you cannot back with an observation becomes a hypothesis.
30
+ 3. **Hypotheses.** Write at least 4 distinct, falsifiable causes, plus one `"catch_all": true` ("something else"). Each must predict something *observable*. Do **not** rate anything yet.
31
+ 4. **Gather evidence by running commands** (tests, logs, `git log`, bisect, profiling). Every observation becomes an `observed` evidence item with:
32
+ - `text`: what was observed, stated neutrally;
33
+ - `ref`: the exact command, `file:line`, or log excerpt that produced it;
34
+ - `credibility` and `relevance`: `low | medium | high`.
35
+ If you only *believe* something, it is **not evidence**: either observe it or leave it out. Never invent a `ref`.
36
+ 5. **Rate row by row.** For each evidence item, rate it against **all** hypotheses before moving to the next item (never hypothesis by hypothesis — that anchors you). Ask: *"If this hypothesis were true, how surprised would I be to see this?"*
37
+
38
+ | Rating | Meaning |
39
+ |--------|---------|
40
+ | `CC` / `C` | very consistent / consistent |
41
+ | `N` | neutral or not applicable |
42
+ | `I` / `II` | inconsistent / very inconsistent |
43
+
44
+ Only inconsistency counts in the score. Consistent evidence rarely discriminates.
45
+ 6. **Score.** Run `score`. Read the **warnings first**: uncited evidence, fragile conclusions, and an un-refuted catch-all all matter.
46
+ 7. **Test the leaders.** Run `next`. Execute the top recommended test, then change its `status` to `observed`, add a `ref`, set its ratings to what actually happened, and re-score. Repeat.
47
+ 8. **Stop** when one hypothesis leads, the conclusion is not fragile, and its predictions have survived a test — or after 3 rounds without progress, in which case say the diagnosis is **unresolved** and ask the user.
48
+
49
+ ## Reporting
50
+
51
+ Paste the Markdown report. State the leader as a **working hypothesis**, never as a proven cause or a probability. Mention the catch-all warning if it appears.
52
+
53
+ ## Rules
54
+
55
+ - Do not adjust ratings to reach a preferred answer. Do not delete evidence that contradicts the leader.
56
+ - Mark evidence `observed` only if you ran something this session and can cite it.
57
+ - The score is a ranking of inconsistencies, **not a probability**.
58
+ - If a fix is requested, apply it only after step 8, then re-run the failing check as new evidence.