tempergraph 0.7.1__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.
- tempergraph/__init__.py +8 -0
- tempergraph/__main__.py +5 -0
- tempergraph/api.py +428 -0
- tempergraph/audit/__init__.py +305 -0
- tempergraph/audit/catalog.py +342 -0
- tempergraph/audit/definition.py +387 -0
- tempergraph/audit/history.py +414 -0
- tempergraph/audit/history_rules.py +268 -0
- tempergraph/audit/history_rules_more.py +244 -0
- tempergraph/audit/host.py +270 -0
- tempergraph/audit/owned.py +96 -0
- tempergraph/audit/prompts.py +89 -0
- tempergraph/audit/report.py +248 -0
- tempergraph/audit/revisit.py +220 -0
- tempergraph/audit/surface.py +224 -0
- tempergraph/audit/text_health.py +176 -0
- tempergraph/audit/tools.py +391 -0
- tempergraph/author/__init__.py +2 -0
- tempergraph/author/blueprint.py +346 -0
- tempergraph/author/compare.py +122 -0
- tempergraph/author/criteria_lint.py +200 -0
- tempergraph/author/draw.py +112 -0
- tempergraph/author/inventory.py +210 -0
- tempergraph/author/literals.py +138 -0
- tempergraph/author/scaffold.py +568 -0
- tempergraph/author/session.py +439 -0
- tempergraph/author/trial.py +391 -0
- tempergraph/author/verify.py +353 -0
- tempergraph/builtin/__init__.py +1 -0
- tempergraph/builtin/upgrade.py +288 -0
- tempergraph/catalog.py +134 -0
- tempergraph/check_helpers.py +99 -0
- tempergraph/cli/__init__.py +1 -0
- tempergraph/cli/audit.py +190 -0
- tempergraph/cli/author.py +361 -0
- tempergraph/cli/improve.py +564 -0
- tempergraph/cli/improve_review.py +111 -0
- tempergraph/cli/install.py +35 -0
- tempergraph/cli/main.py +1261 -0
- tempergraph/cli/observe_cli.py +544 -0
- tempergraph/cli/outcome.py +77 -0
- tempergraph/cli/schedule_cli.py +1090 -0
- tempergraph/cli/upgrade.py +126 -0
- tempergraph/cli/workflows.py +96 -0
- tempergraph/compiler/__init__.py +6 -0
- tempergraph/compiler/graph.py +305 -0
- tempergraph/compiler/state.py +229 -0
- tempergraph/constants.py +72 -0
- tempergraph/contracts.py +1025 -0
- tempergraph/data/executor_compat.json +11 -0
- tempergraph/data/promotion.json +35 -0
- tempergraph/data/release.json +20 -0
- tempergraph/detach.py +65 -0
- tempergraph/docs.py +90 -0
- tempergraph/durability/__init__.py +2 -0
- tempergraph/durability/alias.py +66 -0
- tempergraph/durability/carry.py +591 -0
- tempergraph/durability/checkpoint.py +179 -0
- tempergraph/durability/control.py +109 -0
- tempergraph/durability/engine_file.py +301 -0
- tempergraph/durability/lock.py +138 -0
- tempergraph/durability/status.py +390 -0
- tempergraph/engine_identity.py +42 -0
- tempergraph/executor_compat.py +56 -0
- tempergraph/executors/__init__.py +4 -0
- tempergraph/executors/binding.py +91 -0
- tempergraph/executors/capabilities.py +95 -0
- tempergraph/executors/claude.py +603 -0
- tempergraph/executors/launcher.py +394 -0
- tempergraph/executors/mcpconfig.py +156 -0
- tempergraph/executors/mcpproxy.py +216 -0
- tempergraph/executors/preflight.py +196 -0
- tempergraph/executors/registry.py +71 -0
- tempergraph/executors/scripted.py +18 -0
- tempergraph/executors/session.py +107 -0
- tempergraph/executors/standins.py +118 -0
- tempergraph/executors/summary.py +110 -0
- tempergraph/executors/viewcatalog.py +27 -0
- tempergraph/git.py +403 -0
- tempergraph/identity.py +65 -0
- tempergraph/improve/__init__.py +5 -0
- tempergraph/improve/analysis.py +437 -0
- tempergraph/improve/artifact.py +477 -0
- tempergraph/improve/autonomy.py +192 -0
- tempergraph/improve/bindings.py +191 -0
- tempergraph/improve/calibration.py +1016 -0
- tempergraph/improve/causes.py +416 -0
- tempergraph/improve/child.py +651 -0
- tempergraph/improve/codehost.py +520 -0
- tempergraph/improve/digest.py +472 -0
- tempergraph/improve/escape.py +100 -0
- tempergraph/improve/filing.py +1047 -0
- tempergraph/improve/harvest.py +158 -0
- tempergraph/improve/issue_context.py +192 -0
- tempergraph/improve/lenses.py +204 -0
- tempergraph/improve/lessons.py +233 -0
- tempergraph/improve/loop_report.py +138 -0
- tempergraph/improve/loop_summary.py +85 -0
- tempergraph/improve/lost.py +119 -0
- tempergraph/improve/measure.py +121 -0
- tempergraph/improve/params.py +98 -0
- tempergraph/improve/pause_facts.py +134 -0
- tempergraph/improve/pr_later.py +186 -0
- tempergraph/improve/prebinding.py +130 -0
- tempergraph/improve/promotion.py +413 -0
- tempergraph/improve/proposals.py +934 -0
- tempergraph/improve/record.py +322 -0
- tempergraph/improve/release.py +89 -0
- tempergraph/improve/reliability.py +457 -0
- tempergraph/improve/repeat.py +115 -0
- tempergraph/improve/review.py +910 -0
- tempergraph/improve/suites.py +586 -0
- tempergraph/improve/trials.py +525 -0
- tempergraph/install/__init__.py +11 -0
- tempergraph/install/bootstrap.py +133 -0
- tempergraph/install/environment.py +173 -0
- tempergraph/install/launch.py +37 -0
- tempergraph/install/python.py +53 -0
- tempergraph/install/reconcile.py +52 -0
- tempergraph/install/selfcheck.py +29 -0
- tempergraph/install/shim.py +81 -0
- tempergraph/install/update.py +400 -0
- tempergraph/model/__init__.py +0 -0
- tempergraph/model/diagram.py +185 -0
- tempergraph/model/flow.py +324 -0
- tempergraph/model/prompt_lint.py +203 -0
- tempergraph/model/retire.py +52 -0
- tempergraph/model/subworkflow.py +274 -0
- tempergraph/model/text.py +67 -0
- tempergraph/model/validate.py +1158 -0
- tempergraph/observe/__init__.py +1 -0
- tempergraph/observe/attention.py +196 -0
- tempergraph/observe/detail.py +773 -0
- tempergraph/observe/forget.py +138 -0
- tempergraph/observe/hooks.py +272 -0
- tempergraph/observe/labels.py +95 -0
- tempergraph/observe/overlay.py +46 -0
- tempergraph/observe/report.py +402 -0
- tempergraph/observe/risk_report.py +110 -0
- tempergraph/observe/rows.py +444 -0
- tempergraph/observe/sinks.py +793 -0
- tempergraph/observe/supervision_cost.py +797 -0
- tempergraph/observe/supervision_report.py +295 -0
- tempergraph/observe/switch_report.py +140 -0
- tempergraph/package/__init__.py +2 -0
- tempergraph/package/change_report.py +116 -0
- tempergraph/package/changelog.py +263 -0
- tempergraph/package/docs_check.py +115 -0
- tempergraph/package/importer.py +90 -0
- tempergraph/package/inventory.py +111 -0
- tempergraph/package/loader.py +250 -0
- tempergraph/package/manifest.py +256 -0
- tempergraph/package/readiness.py +124 -0
- tempergraph/package/registry.py +383 -0
- tempergraph/package/rules.py +128 -0
- tempergraph/package/scan.py +65 -0
- tempergraph/package/selftest.py +348 -0
- tempergraph/package/stamp.py +213 -0
- tempergraph/package/transforms.py +481 -0
- tempergraph/package/upgrade.py +625 -0
- tempergraph/provenance.py +183 -0
- tempergraph/py.typed +0 -0
- tempergraph/release.py +17 -0
- tempergraph/render/__init__.py +0 -0
- tempergraph/render/output.py +72 -0
- tempergraph/render/prompt.py +166 -0
- tempergraph/render/template.py +86 -0
- tempergraph/run/__init__.py +2 -0
- tempergraph/run/asking.py +233 -0
- tempergraph/run/audit.py +63 -0
- tempergraph/run/check_worker.py +167 -0
- tempergraph/run/checks.py +517 -0
- tempergraph/run/commands.py +210 -0
- tempergraph/run/complexity.py +268 -0
- tempergraph/run/contest.py +76 -0
- tempergraph/run/council.py +368 -0
- tempergraph/run/council_run.py +527 -0
- tempergraph/run/events.py +279 -0
- tempergraph/run/finalize.py +132 -0
- tempergraph/run/gate.py +747 -0
- tempergraph/run/guard.py +89 -0
- tempergraph/run/judging.py +357 -0
- tempergraph/run/ladder.py +230 -0
- tempergraph/run/log.py +600 -0
- tempergraph/run/mapping.py +183 -0
- tempergraph/run/nodes.py +2304 -0
- tempergraph/run/outcome.py +255 -0
- tempergraph/run/outcome_record.py +292 -0
- tempergraph/run/outcome_trust.py +99 -0
- tempergraph/run/rerun.py +351 -0
- tempergraph/run/reserve.py +85 -0
- tempergraph/run/resources.py +76 -0
- tempergraph/run/risk.py +231 -0
- tempergraph/run/runner.py +1579 -0
- tempergraph/run/scriptcache.py +178 -0
- tempergraph/run/selfcheck.py +105 -0
- tempergraph/run/session_record.py +72 -0
- tempergraph/run/subrun.py +278 -0
- tempergraph/run/supervision.py +125 -0
- tempergraph/run/tool_access.py +101 -0
- tempergraph/schedule/__init__.py +25 -0
- tempergraph/schedule/credentials.py +167 -0
- tempergraph/schedule/echo.py +169 -0
- tempergraph/schedule/exact.py +275 -0
- tempergraph/schedule/export.py +164 -0
- tempergraph/schedule/launch.py +89 -0
- tempergraph/schedule/ledger.py +133 -0
- tempergraph/schedule/loop.py +176 -0
- tempergraph/schedule/model.py +440 -0
- tempergraph/schedule/policies.py +414 -0
- tempergraph/schedule/store.py +150 -0
- tempergraph/schedule/tick.py +377 -0
- tempergraph/schedule/token.py +81 -0
- tempergraph/schedule/triggers.py +210 -0
- tempergraph/schedule/words.py +423 -0
- tempergraph/security/__init__.py +0 -0
- tempergraph/security/launch.py +25 -0
- tempergraph/security/scrub.py +58 -0
- tempergraph/settings.py +950 -0
- tempergraph/store/__init__.py +0 -0
- tempergraph/store/codelog.py +73 -0
- tempergraph/store/layout.py +198 -0
- tempergraph/store/logs.py +325 -0
- tempergraph/store/manifest.py +99 -0
- tempergraph/store/migrate.py +188 -0
- tempergraph/workspace.py +874 -0
- tempergraph-0.7.1.dist-info/METADATA +70 -0
- tempergraph-0.7.1.dist-info/RECORD +232 -0
- tempergraph-0.7.1.dist-info/WHEEL +5 -0
- tempergraph-0.7.1.dist-info/entry_points.txt +5 -0
- tempergraph-0.7.1.dist-info/top_level.txt +2 -0
- tempergraph_pytest_plugin.py +64 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""The effort ladder: climbing evidence, held causes and the rung of the next attempt (LAD-B10, LAD-B11). Pure.
|
|
2
|
+
|
|
3
|
+
A ladder never adds an attempt: it only chooses the effort of a retry the budget already allows, and only
|
|
4
|
+
the two kinds of evidence of LAD-B10 ever move it up.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
from collections.abc import Mapping
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from tempergraph.contracts import EFFORTS, STAGES, EscalationSpec, UnitSpec
|
|
16
|
+
|
|
17
|
+
TRUSTED_STATES = {"local-dev": ("accepted", "provisional"), "local-stable": ("accepted",), "pipeline": ("accepted",)}
|
|
18
|
+
PIN_KEYS = ("effort", "model")
|
|
19
|
+
TIER_UP = {"small": "medium", "medium": "large"} # LAD-B9: exactly one tier above
|
|
20
|
+
TIER_RANK = {"small": 0, "medium": 1, "large": 2}
|
|
21
|
+
TIER_FAMILY = {"small": "haiku", "medium": "sonnet", "large": "opus"} # the price row of a tier (OBS-B10 to OBS-B13)
|
|
22
|
+
MODES = ("off", "offer", "auto")
|
|
23
|
+
DEFAULT_STAGES = {"local-dev": "offer", "local-stable": "offer", "pipeline": "off"}
|
|
24
|
+
RECORD_MIN, RECORD_LB = 5, 0.5 # LAD-B13: escalated attempts graded by an accepted judge, Wilson lower bound
|
|
25
|
+
HELD_ERRORS = {"turn_cap": "turn_cap", "cap_reached": "cost_cap", "model": "model"}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def trusted(judge_state: str, stage: str) -> bool:
|
|
29
|
+
"""LAD-B10: a RETRY counts from an `accepted` binding, or a `provisional` one at stage `local-dev`. A
|
|
30
|
+
binding graded `unreliable` in production is `contradicted` (JCL-B17), so it is never trusted."""
|
|
31
|
+
return judge_state in TRUSTED_STATES.get(stage, ("accepted",))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True, kw_only=True)
|
|
35
|
+
class Classified:
|
|
36
|
+
evidence: str | None = None # `judge_blocker`, `check_fail` or None
|
|
37
|
+
held_by: str | None = None # the held cause of LAD-B11 when there is no evidence
|
|
38
|
+
criteria: tuple[str, ...] = field(default=())
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _held_attempt(att: Mapping[str, Any]) -> str | None:
|
|
42
|
+
"""Why the attempt did not end with a result (LAD-B11 rows 1 and 2), or None when it did."""
|
|
43
|
+
if att.get("timed_out"):
|
|
44
|
+
return "timeout"
|
|
45
|
+
if att.get("stalled"):
|
|
46
|
+
return "stall"
|
|
47
|
+
if att.get("infra_cause") or att.get("infra_spent"):
|
|
48
|
+
return "infra"
|
|
49
|
+
if att.get("error_kind") in HELD_ERRORS:
|
|
50
|
+
return HELD_ERRORS[str(att["error_kind"])]
|
|
51
|
+
if att.get("cut_off"):
|
|
52
|
+
return "cut_off"
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def classify(att: Mapping[str, Any], judged: Mapping[str, Any]) -> Classified:
|
|
57
|
+
"""The failed attempt's climbing evidence, or the cause that holds the rung."""
|
|
58
|
+
held = _held_attempt(att)
|
|
59
|
+
reason = judged.get("reason")
|
|
60
|
+
if reason == "check_fail":
|
|
61
|
+
check = att.get("check") or {}
|
|
62
|
+
failing = [f for f in check.get("findings") or [] if f.get("status") == "fail"]
|
|
63
|
+
if check.get("environmental"):
|
|
64
|
+
return Classified(held_by="environmental")
|
|
65
|
+
if held:
|
|
66
|
+
return Classified(held_by=held)
|
|
67
|
+
if any(f.get("kind") == "output_contract" for f in failing):
|
|
68
|
+
return Classified(held_by="output_contract")
|
|
69
|
+
ids = tuple(dict.fromkeys(str(f["criterion"]) for f in failing
|
|
70
|
+
if f.get("criterion") and f.get("kind") == "substance"))
|
|
71
|
+
return Classified(evidence="check_fail", criteria=ids) if ids else Classified(held_by="check_no_substance")
|
|
72
|
+
if reason == "blockers":
|
|
73
|
+
if held:
|
|
74
|
+
return Classified(held_by=held)
|
|
75
|
+
if judged.get("confidence_source") == "engine_placeholder":
|
|
76
|
+
return Classified(held_by="judge_placeholder")
|
|
77
|
+
ids = tuple(dict.fromkeys(str(b.get("criterion")) for b in judged.get("blockers") or []
|
|
78
|
+
if not b.get("no_change") and not b.get("defect_in")))
|
|
79
|
+
if not ids:
|
|
80
|
+
return Classified(held_by="no_substantive_blocker")
|
|
81
|
+
if not judged.get("trusted"):
|
|
82
|
+
return Classified(held_by="judge_not_trusted")
|
|
83
|
+
return Classified(evidence="judge_blocker", criteria=ids)
|
|
84
|
+
return Classified(held_by=held or str(reason or "step_failed"))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def rungs_of(u: UnitSpec, overrides: Mapping[str, Any] | None = None) -> tuple[tuple[str, ...], bool]:
|
|
88
|
+
"""The ladder in force for a unit, and whether an operator pin switches it off (LAD-B11 last row). An arm
|
|
89
|
+
in force may give its own ladder, or a fixed effort that replaces the step's ladder (SWM-B6)."""
|
|
90
|
+
st = u.step
|
|
91
|
+
if st is None:
|
|
92
|
+
return (), False
|
|
93
|
+
ov = overrides or {}
|
|
94
|
+
rungs = tuple(ov["effort_ladder"]) if ov.get("effort_ladder") else () if "effort" in ov else tuple(st.effort_ladder)
|
|
95
|
+
pinned = bool(rungs) and any(k in (u.extra.get("operator_set") or ()) for k in PIN_KEYS)
|
|
96
|
+
return rungs, pinned
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def held_rung(counters: Mapping[str, Any], visit: int, item: Any) -> int:
|
|
100
|
+
"""The rung this visit (and item) stands on; any other visit starts at rung 0 (LAD-B11)."""
|
|
101
|
+
held = counters.get("ladder") or {}
|
|
102
|
+
return int(held.get("rung", 0)) if held.get("visit") == visit and held.get("item") == item else 0
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def decide(u: UnitSpec, att: Mapping[str, Any], judged: Mapping[str, Any], counters: Mapping[str, Any],
|
|
106
|
+
overrides: Mapping[str, Any] | None = None) -> dict[str, Any] | None:
|
|
107
|
+
"""The `ladder_decision` of a gate that sends the unit to a retry: the rung of the next attempt and why.
|
|
108
|
+
None when the unit has neither a ladder nor an escalation."""
|
|
109
|
+
rungs, pinned = rungs_of(u, overrides)
|
|
110
|
+
esc = escalation_of(u, overrides)
|
|
111
|
+
if not rungs and esc is None:
|
|
112
|
+
return None
|
|
113
|
+
visit, item = int(att.get("visit", 1)), att.get("item")
|
|
114
|
+
rung = held_rung(counters, visit, item) if rungs else 0
|
|
115
|
+
got = Classified(held_by="operator_pin") if pinned else classify(att, judged)
|
|
116
|
+
nxt = min(rung + 1, len(rungs) - 1) if got.evidence and rungs else rung
|
|
117
|
+
prev = counters.get("ladder") or {}
|
|
118
|
+
same = prev if prev.get("visit") == visit and prev.get("item") == item else {}
|
|
119
|
+
trail = [*(same.get("trail") or []), {"rung": rung, "top": rung >= len(rungs) - 1, "evidence": got.evidence,
|
|
120
|
+
"criteria": list(got.criteria)}][-2:]
|
|
121
|
+
return {"visit": visit, "item": item, "from_rung": rung, "rung": nxt,
|
|
122
|
+
"effort": rungs[nxt] if rungs and not pinned else None,
|
|
123
|
+
"evidence": got.evidence, "held_by": got.held_by if not got.evidence else None,
|
|
124
|
+
"criteria": list(got.criteria), "judge_state": judged.get("judge_state"), "trail": trail,
|
|
125
|
+
"escalated": bool(same.get("escalated"))}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def escalation_of(u: UnitSpec, overrides: Mapping[str, Any] | None = None) -> EscalationSpec | None:
|
|
129
|
+
"""The escalation in force: the arm's when it gives one (SWM-B6), else the step's; none under a pin."""
|
|
130
|
+
st = u.step
|
|
131
|
+
if st is None or any(k in (u.extra.get("operator_set") or ()) for k in PIN_KEYS):
|
|
132
|
+
return None
|
|
133
|
+
got = (overrides or {}).get("escalation")
|
|
134
|
+
if isinstance(got, Mapping):
|
|
135
|
+
return EscalationSpec(to=str(got.get("to")), stages=dict(got.get("stages") or {}), effort=got.get("effort"))
|
|
136
|
+
return got if isinstance(got, EscalationSpec) else st.escalation
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def mode(esc: EscalationSpec, stage: str, record_met: bool) -> str:
|
|
140
|
+
"""LAD-B13: what the stage allows. `auto` is an offer in local-dev and, without a met escalation record,
|
|
141
|
+
in local-stable; a pipeline never waits on an offer, and its `auto` needs a promotion stamp (PRO-B10)."""
|
|
142
|
+
m = {**DEFAULT_STAGES, **dict(esc.stages)}.get(stage, "off")
|
|
143
|
+
if stage == "pipeline":
|
|
144
|
+
return "off"
|
|
145
|
+
if m == "auto" and (stage == "local-dev" or not record_met):
|
|
146
|
+
return "offer"
|
|
147
|
+
return m if m in MODES else "off"
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def tier(alias: object) -> str:
|
|
151
|
+
return str(alias or "").rsplit(":", 1)[-1]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _judge_rank(judge: Any) -> int:
|
|
155
|
+
"""The strongest tier the gate's judge can grade on: its own, or its highest risk level's (JRK-B8 floor)."""
|
|
156
|
+
from tempergraph.run.risk import top_rank
|
|
157
|
+
|
|
158
|
+
return top_rank(judge)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def escalation(u: UnitSpec, step: Mapping[str, Any], judged: Mapping[str, Any], *, retry_left: bool,
|
|
162
|
+
rearm_available: bool, overrides: Mapping[str, Any] | None = None) -> dict[str, Any] | None:
|
|
163
|
+
"""LAD-B12: whether the next attempt is escalated. None when the unit declares no escalation or the failed
|
|
164
|
+
attempt carried no `judge_blocker` evidence; else `take` (`auto`, `offer` or None) and, when not taken,
|
|
165
|
+
`held_by` naming the first condition that failed."""
|
|
166
|
+
esc = escalation_of(u, overrides)
|
|
167
|
+
if esc is None or step.get("evidence") != "judge_blocker":
|
|
168
|
+
return None
|
|
169
|
+
facts = judged.get("escalation") or {}
|
|
170
|
+
trail = list(step.get("trail") or [])
|
|
171
|
+
rungs, _ = rungs_of(u, overrides)
|
|
172
|
+
st = u.step
|
|
173
|
+
assert st is not None
|
|
174
|
+
effort = esc.effort or (rungs[-1] if rungs else (st.session_options.effort if st.session_options else None))
|
|
175
|
+
out: dict[str, Any] = {"to": esc.to, "effort": effort, "take": None, "held_by": None,
|
|
176
|
+
"criteria": [], "judge_state": judged.get("judge_state")}
|
|
177
|
+
allowed = mode(esc, str(facts.get("stage") or "local-dev"), bool(facts.get("record_met")))
|
|
178
|
+
last = trail[-2:]
|
|
179
|
+
shared = sorted(set(last[0]["criteria"]) & set(last[1]["criteria"])) if len(last) == 2 else []
|
|
180
|
+
judge = u.gate.judge
|
|
181
|
+
estimate, left = facts.get("estimate_usd"), facts.get("cap_left_usd")
|
|
182
|
+
failed = next((name for name, bad in (
|
|
183
|
+
("E1", allowed == "off"),
|
|
184
|
+
("E2", len(last) < 2 or not all(t["top"] for t in last)),
|
|
185
|
+
("E3", len(last) < 2 or any(t["evidence"] != "judge_blocker" for t in last) or not shared),
|
|
186
|
+
("E4", _judge_rank(judge) < TIER_RANK.get(tier(esc.to), 9) or judged.get("judge_state") != "accepted"),
|
|
187
|
+
("E5", not retry_left),
|
|
188
|
+
("E6_unmeasured", estimate is None),
|
|
189
|
+
("E6", estimate is not None and left is not None and float(estimate) > float(left)),
|
|
190
|
+
("E7", facts.get("bound") is False),
|
|
191
|
+
("E8", rearm_available),
|
|
192
|
+
("E9", bool(step.get("escalated"))),
|
|
193
|
+
) if bad), None)
|
|
194
|
+
if failed:
|
|
195
|
+
return {**out, "held_by": failed}
|
|
196
|
+
return {**out, "take": allowed, "criteria": shared}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def record_escalation(root: Path, *, workflow: str, version: str | None, unit: str, thread: str, passed: bool,
|
|
200
|
+
judge_state: str | None, to: str) -> None:
|
|
201
|
+
"""One row of the escalation record (LAD-B16, LAD-B17): an escalated attempt, how it ended and who graded it."""
|
|
202
|
+
from tempergraph.run.log import Ledger
|
|
203
|
+
|
|
204
|
+
Ledger(path=root / "ledger.jsonl").append({"kind": "escalation", "workflow": workflow, "version": version,
|
|
205
|
+
"unit": unit, "thread_id": thread, "passed": bool(passed),
|
|
206
|
+
"judge_state": judge_state, "to": to})
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def record_met(root: Path, workflow: str, version: str | None, unit: str) -> bool:
|
|
210
|
+
"""LAD-B13: at least five escalated attempts of this step and workflow version graded by an `accepted`
|
|
211
|
+
judge, with a pass rate whose Wilson lower bound is at least 0.5. An unreadable record is not met."""
|
|
212
|
+
from tempergraph.improve.calibration import wilson_lb
|
|
213
|
+
|
|
214
|
+
try:
|
|
215
|
+
rows = [json.loads(ln) for ln in (root / "ledger.jsonl").read_text(encoding="utf-8").splitlines() if ln]
|
|
216
|
+
except (OSError, ValueError):
|
|
217
|
+
return False
|
|
218
|
+
mine = [r for r in rows if isinstance(r, dict) and r.get("kind") == "escalation" and r.get("workflow") == workflow
|
|
219
|
+
and r.get("version") == version and r.get("unit") == unit and r.get("judge_state") == "accepted"]
|
|
220
|
+
n, x = len(mine), sum(1 for r in mine if r.get("passed"))
|
|
221
|
+
return n >= RECORD_MIN and wilson_lb(x, n) >= RECORD_LB
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def stages_ok(esc: EscalationSpec) -> bool:
|
|
225
|
+
return all(k in STAGES and v in MODES for k, v in dict(esc.stages).items())
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def ascending(rungs: tuple[str, ...]) -> bool:
|
|
229
|
+
return all(r in EFFORTS for r in rungs) and all(
|
|
230
|
+
EFFORTS.index(a) < EFFORTS.index(b) for a, b in zip(rungs, rungs[1:], strict=False))
|