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,250 @@
|
|
|
1
|
+
"""Loading a workflow package (PKG-B15, PKG-B16, PKG-B17): read-only, calls no model (OVR-B15).
|
|
2
|
+
|
|
3
|
+
Steps: 1 manifests, 2 interface level, then the dependency gate and the source scan before any import,
|
|
4
|
+
3 import under the private name, 4 build, 5 attach `outcome.json`, 6 validation (WFM `validate`, whose
|
|
5
|
+
last step is :func:`package_findings`). The Python half is imported from the package folder, never
|
|
6
|
+
installed (PKG-B15, PKG-B16, PKG-B17).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import dataclasses
|
|
12
|
+
import importlib
|
|
13
|
+
import json
|
|
14
|
+
import traceback
|
|
15
|
+
from dataclasses import dataclass, field
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Any, Literal
|
|
18
|
+
|
|
19
|
+
from tempergraph.constants import LOADS_WORKFLOW_API_FROM, WORKFLOW_API
|
|
20
|
+
from tempergraph.contracts import Criterion, GateSpec, WorkflowSpec
|
|
21
|
+
from tempergraph.model.validate import Finding
|
|
22
|
+
from tempergraph.package import docs_check, importer, rules
|
|
23
|
+
from tempergraph.package.inventory import (
|
|
24
|
+
PackageInventory,
|
|
25
|
+
content_digest,
|
|
26
|
+
docs_digest,
|
|
27
|
+
package_files,
|
|
28
|
+
workflow_version,
|
|
29
|
+
)
|
|
30
|
+
from tempergraph.package.manifest import (
|
|
31
|
+
Manifests,
|
|
32
|
+
Pyproject,
|
|
33
|
+
gate_dependencies,
|
|
34
|
+
read_manifests,
|
|
35
|
+
read_pyproject,
|
|
36
|
+
)
|
|
37
|
+
from tempergraph.package.scan import scan
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PackageNotLoaded(Exception):
|
|
41
|
+
"""`not_loaded: <reason>` (PKG-B15, PKG-B16, PKG-B17, PKG-B11, PKG-B13, PKG-B14, PKG-B18, PKG-B19, PKG-B20, PKG-B23); `findings` carry the codes behind it."""
|
|
42
|
+
|
|
43
|
+
def __init__(self, reason: str, detail: str = "", findings: list[Finding] | None = None,
|
|
44
|
+
remedy: str = "") -> None:
|
|
45
|
+
super().__init__(f"not_loaded: {reason}" + (f" ({detail})" if detail else ""))
|
|
46
|
+
self.reason = reason
|
|
47
|
+
self.detail = detail
|
|
48
|
+
self.findings = findings or []
|
|
49
|
+
self.remedy = remedy
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass(kw_only=True)
|
|
53
|
+
class LoadedPackage:
|
|
54
|
+
root: Path
|
|
55
|
+
manifests: Manifests
|
|
56
|
+
pyproject: Pyproject | None
|
|
57
|
+
spec: WorkflowSpec
|
|
58
|
+
inventory: PackageInventory
|
|
59
|
+
content_digest: str
|
|
60
|
+
docs_digest: str
|
|
61
|
+
findings: list[Finding] = field(default_factory=list) # load-time findings (scan, pyproject, outcome)
|
|
62
|
+
outcome_pending: bool = False # PKG-B15, PKG-B16, PKG-B17 step 5 waits on OUT's reader (plan T5.8.1)
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def workflow_version(self) -> str:
|
|
66
|
+
return workflow_version(self.spec.version, self.content_digest)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# The workflow version with its content digest, by package root, as of the last load in this process (VER-B14, VER-B15).
|
|
70
|
+
_VERSIONS: dict[Path, str] = {}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def full_version(spec: WorkflowSpec) -> str:
|
|
74
|
+
"""`<version>+<digest>` of a loaded package, else the spec's declared version."""
|
|
75
|
+
root = spec.package_root
|
|
76
|
+
if root is None:
|
|
77
|
+
return spec.version
|
|
78
|
+
if root not in _VERSIONS:
|
|
79
|
+
try:
|
|
80
|
+
load_package(root)
|
|
81
|
+
except PackageNotLoaded:
|
|
82
|
+
return spec.version
|
|
83
|
+
return _VERSIONS.get(root, spec.version)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# Load-time findings by package root, so the one validation function reports them (WFM-AC2).
|
|
87
|
+
_LOAD_FINDINGS: dict[Path, list[Finding]] = {}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _detail(exc: BaseException) -> str:
|
|
91
|
+
"""WFM-B7: an exception's type only, unless an engine builder raised it (its text names the field)."""
|
|
92
|
+
frames = traceback.extract_tb(exc.__traceback__)
|
|
93
|
+
if isinstance(exc, TypeError) and frames and frames[-1].filename.endswith(("tempergraph/api.py",)):
|
|
94
|
+
return f"TypeError: {exc}"
|
|
95
|
+
return type(exc).__name__
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _stamp_engine(root: Path) -> str | None:
|
|
99
|
+
"""`verified_engine` mirrors the stamp's `engine_version` (VER-B16)."""
|
|
100
|
+
try:
|
|
101
|
+
doc = json.loads((root / "stamp.json").read_text(encoding="utf-8"))
|
|
102
|
+
except (OSError, ValueError):
|
|
103
|
+
return None
|
|
104
|
+
return str(doc["engine_version"]) if isinstance(doc, dict) and doc.get("engine_version") else None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _interface(api: int, engine_api: int, loads_from: int) -> None:
|
|
108
|
+
if api > engine_api:
|
|
109
|
+
raise PackageNotLoaded("workflow_api_newer", f"package level {api}, engine {engine_api}",
|
|
110
|
+
remedy="update the engine (`tempergraph update`)")
|
|
111
|
+
if api < loads_from:
|
|
112
|
+
raise PackageNotLoaded("workflow_api_retired", f"package level {api}, engine loads from {loads_from}",
|
|
113
|
+
remedy="upgrade the workflow (`tempergraph upgrade`)")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _behind(api: int, engine_api: int) -> list[Finding]:
|
|
117
|
+
"""PKG-B6 row 2: a package below the engine's level loads, with a warning when the changelog has breaking
|
|
118
|
+
`workflow` entries it has not met."""
|
|
119
|
+
if api >= engine_api:
|
|
120
|
+
return []
|
|
121
|
+
from tempergraph.package.changelog import breaking_since_level
|
|
122
|
+
|
|
123
|
+
ids = breaking_since_level(api)
|
|
124
|
+
if not ids:
|
|
125
|
+
return []
|
|
126
|
+
return [Finding("workflow_api_behind", None, f"package level {api}, engine {engine_api}: breaking workflow "
|
|
127
|
+
f"entries {', '.join(ids)} since; run `tempergraph upgrade-check <workflow>`", "warning")]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _attach_outcome(spec: WorkflowSpec, root: Path) -> tuple[WorkflowSpec, list[Finding], bool]:
|
|
131
|
+
"""Step 5: read `outcome.json` and fill each gate's criteria (OUT-B13, OUT-B14). Pending until OUT's reader exists."""
|
|
132
|
+
try:
|
|
133
|
+
outcome_mod: Any = importlib.import_module("tempergraph.run.outcome")
|
|
134
|
+
read_outcome = outcome_mod.read_outcome
|
|
135
|
+
gate_criteria = outcome_mod.gate_criteria
|
|
136
|
+
except (ImportError, AttributeError):
|
|
137
|
+
return spec, [], True
|
|
138
|
+
got = read_outcome(root)
|
|
139
|
+
if isinstance(got, list):
|
|
140
|
+
return spec, list(got), False
|
|
141
|
+
inline = {u: {c.id for c in unit.gate.criteria if c.id} for u, unit in spec.units.items()}
|
|
142
|
+
units = {}
|
|
143
|
+
for name, unit in spec.units.items():
|
|
144
|
+
extra: list[Criterion] = list(gate_criteria(got, name))
|
|
145
|
+
gate: GateSpec = dataclasses.replace(unit.gate, criteria=(*unit.gate.criteria, *(
|
|
146
|
+
c for c in extra if c.id not in inline[name])))
|
|
147
|
+
units[name] = dataclasses.replace(unit, gate=gate)
|
|
148
|
+
spec = dataclasses.replace(spec, outcome=got, units=units)
|
|
149
|
+
return spec, rules.criteria_twice(spec, inline) + list(outcome_mod.check_against(got, spec)), False
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def load_package(package_path: Path, *, engine_api: int = WORKFLOW_API,
|
|
153
|
+
loads_from: int = LOADS_WORKFLOW_API_FROM) -> LoadedPackage:
|
|
154
|
+
root = package_path.resolve()
|
|
155
|
+
got = read_manifests(root)
|
|
156
|
+
if isinstance(got, list):
|
|
157
|
+
raise PackageNotLoaded("manifest", "; ".join(f.message for f in got if f.severity == "error"), got)
|
|
158
|
+
m = got
|
|
159
|
+
_interface(m.engine.workflow_api, engine_api, loads_from)
|
|
160
|
+
findings: list[Finding] = _behind(m.engine.workflow_api, engine_api)
|
|
161
|
+
py = read_pyproject(root)
|
|
162
|
+
pyproject = py if isinstance(py, Pyproject) else None
|
|
163
|
+
if not isinstance(py, Pyproject):
|
|
164
|
+
findings.append(py)
|
|
165
|
+
deps = pyproject.dependencies if pyproject else ()
|
|
166
|
+
refused = gate_dependencies(deps)
|
|
167
|
+
if refused:
|
|
168
|
+
raise PackageNotLoaded("dependency_refused", refused[0].message, refused)
|
|
169
|
+
entry_dir = root / "workflow" / m.module
|
|
170
|
+
if not (entry_dir / "__init__.py").is_file():
|
|
171
|
+
raise PackageNotLoaded("build", f"workflow/{m.module}/__init__.py is missing")
|
|
172
|
+
scanned = scan(root, m.module, deps)
|
|
173
|
+
blocking = [f for f in scanned if f.severity == "error"]
|
|
174
|
+
if blocking:
|
|
175
|
+
raise PackageNotLoaded(blocking[0].code, blocking[0].message, scanned)
|
|
176
|
+
findings += scanned
|
|
177
|
+
try:
|
|
178
|
+
module = importer.import_entry(m.engine.name, entry_dir)
|
|
179
|
+
except Exception as exc: # noqa: BLE001 - WFM-B7: the exception type only
|
|
180
|
+
raise PackageNotLoaded("import", type(exc).__name__) from exc
|
|
181
|
+
builder = getattr(module, m.function, None)
|
|
182
|
+
if builder is None or not callable(builder):
|
|
183
|
+
raise PackageNotLoaded("build", f"{m.engine.entry} is not a function of the entry module")
|
|
184
|
+
try:
|
|
185
|
+
spec = builder()
|
|
186
|
+
except Exception as exc: # noqa: BLE001
|
|
187
|
+
raise PackageNotLoaded("build", _detail(exc)) from exc
|
|
188
|
+
if not isinstance(spec, WorkflowSpec):
|
|
189
|
+
raise PackageNotLoaded("build", "the entry did not return a WorkflowSpec")
|
|
190
|
+
stamp = _stamp_engine(root)
|
|
191
|
+
spec = dataclasses.replace(spec, name=m.engine.name, version=m.version, package_root=root,
|
|
192
|
+
verified_engine=stamp or spec.verified_engine)
|
|
193
|
+
spec, outcome_findings, pending = _attach_outcome(spec, root)
|
|
194
|
+
findings += outcome_findings
|
|
195
|
+
inventory = package_files(root)
|
|
196
|
+
_LOAD_FINDINGS[root] = list(findings)
|
|
197
|
+
lp = LoadedPackage(root=root, manifests=m, pyproject=pyproject, spec=spec, inventory=inventory,
|
|
198
|
+
content_digest=content_digest(spec, inventory, deps), docs_digest=docs_digest(inventory),
|
|
199
|
+
findings=findings, outcome_pending=pending)
|
|
200
|
+
_VERSIONS[root] = lp.workflow_version
|
|
201
|
+
return lp
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def load(package_path: Path) -> WorkflowSpec:
|
|
205
|
+
"""The PKG-B13, PKG-B15 contract (WFM-B7 `load()`)."""
|
|
206
|
+
return load_package(package_path).spec
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def package_findings(spec: WorkflowSpec, mode: Literal["dev", "stable"] | None = None) -> list[Finding]:
|
|
210
|
+
"""The package rules of PKG, run as the last step of WFM `validate` for a spec loaded from a package."""
|
|
211
|
+
root = spec.package_root
|
|
212
|
+
if root is None:
|
|
213
|
+
return []
|
|
214
|
+
root = root.resolve()
|
|
215
|
+
got = read_manifests(root)
|
|
216
|
+
if isinstance(got, list):
|
|
217
|
+
return got
|
|
218
|
+
out = list(_LOAD_FINDINGS.get(root, []))
|
|
219
|
+
out += rules.plugin_parts(root, got)
|
|
220
|
+
py = read_pyproject(root)
|
|
221
|
+
inventory = package_files(root)
|
|
222
|
+
if isinstance(py, Pyproject):
|
|
223
|
+
out += rules.layout(root, got, py, inventory)
|
|
224
|
+
out += rules.text_refs(spec, root)
|
|
225
|
+
out += rules.change_files(root)
|
|
226
|
+
from tempergraph.package.manifest import over_budget
|
|
227
|
+
|
|
228
|
+
out += [Finding("text-over-budget", None, f"{f} holds {n} characters, over its budget of {most} in " # PKG-B26
|
|
229
|
+
"tempergraph.json `text_budgets`") for f, n, most in over_budget(root, got.engine.text_budgets)]
|
|
230
|
+
out += rules.check_cases(spec, root)
|
|
231
|
+
out += docs_check.docs_check(spec, root, mode)
|
|
232
|
+
from tempergraph.package.readiness import stable_findings
|
|
233
|
+
|
|
234
|
+
out += stable_findings(spec)
|
|
235
|
+
from tempergraph.author.criteria_lint import lint, package_doc
|
|
236
|
+
|
|
237
|
+
doc = package_doc(root) # AUT-B12, AUT-B15, AUT-B19, AUT-B24, AUT-B25: in validation every criteria lint code is a warning
|
|
238
|
+
out += [Finding(f.code, f.unit, f.message, "warning") for f in (lint(doc) if doc is not None else [])]
|
|
239
|
+
from tempergraph.audit.report import parse_ignores
|
|
240
|
+
|
|
241
|
+
out += [Finding("audit-ignore-invalid", None, f"tempergraph.json: {p}") # AUD-AC7
|
|
242
|
+
for p in parse_ignores(got.engine.audit.get("ignore"))[1]]
|
|
243
|
+
seen: set[tuple[str, str | None, str]] = set()
|
|
244
|
+
unique = []
|
|
245
|
+
for f in out:
|
|
246
|
+
key = (f.code, f.unit, f.message)
|
|
247
|
+
if key not in seen:
|
|
248
|
+
seen.add(key)
|
|
249
|
+
unique.append(f)
|
|
250
|
+
return unique
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
"""The two manifests and the Python half's `pyproject.toml` (PKG-B11, PKG-B12, PKG-B13); read without import or model."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
import tomllib
|
|
8
|
+
from collections.abc import Iterable, Mapping
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from tempergraph.contracts import PackageManifest
|
|
14
|
+
from tempergraph.model.validate import Finding
|
|
15
|
+
|
|
16
|
+
# A workflow package's plugin name is its workflow name plus PLUGIN_SUFFIX (PKG-B13, ADR `a-workflow-plugin-name-is-the-workflow-name-plus-tgraph`), so a
|
|
17
|
+
# tempergraph workflow is recognisable by name wherever Claude Code lists plugins. The workflow name stays short:
|
|
18
|
+
# it is what `run` takes, the registry key, the run folder and the `tgwf-<name>` distribution.
|
|
19
|
+
PLUGIN_SUFFIX = "-tgraph"
|
|
20
|
+
PLUGIN_NAME_MAX = 64 # the plugin name is part of namespaced tool and skill names; kept well inside their caps
|
|
21
|
+
NAME_RE = re.compile(r"^[a-z0-9][a-z0-9-]*$") # a workflow name, kebab-case
|
|
22
|
+
RESERVED_PREFIXES = ("claude-", "anthropic-", "anthropics-", "cc-plugin-") # Claude Code reserves these
|
|
23
|
+
ENTRY_RE = re.compile(r"^([A-Za-z_][A-Za-z0-9_]*):([A-Za-z_][A-Za-z0-9_]*)$")
|
|
24
|
+
DOCS_RE = re.compile(r"^(provisional|[a-z0-9][a-z0-9._-]{0,63})$")
|
|
25
|
+
PLUGIN_JSON = Path(".claude-plugin") / "plugin.json"
|
|
26
|
+
ENGINE_JSON = Path("tempergraph.json")
|
|
27
|
+
PYPROJECT = Path("workflow") / "pyproject.toml"
|
|
28
|
+
|
|
29
|
+
# The dependency gate (PKG-B18): a PEP 508 name, optional extras, optional version specifiers and an
|
|
30
|
+
# optional environment marker. Direct references (`@ url`), paths and installer options are refused.
|
|
31
|
+
_REQ_NAME = r"[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?"
|
|
32
|
+
_REQ_SPEC = r"(?:===|==|!=|~=|>=|<=|<|>)\s*[A-Za-z0-9.*+!_-]+"
|
|
33
|
+
REQUIREMENT_RE = re.compile(
|
|
34
|
+
rf"^\s*(?P<name>{_REQ_NAME})\s*(?:\[\s*{_REQ_NAME}(?:\s*,\s*{_REQ_NAME})*\s*\])?\s*"
|
|
35
|
+
rf"(?:\(?\s*{_REQ_SPEC}(?:\s*,\s*{_REQ_SPEC})*\s*\)?)?\s*"
|
|
36
|
+
r"(?:;\s*[A-Za-z0-9_.\s'\"<>=!~()-]+)?$"
|
|
37
|
+
)
|
|
38
|
+
ENGINE_DISTRIBUTIONS = frozenset({"tempergraph"})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(frozen=True, kw_only=True)
|
|
42
|
+
class Manifests:
|
|
43
|
+
plugin: dict[str, Any]
|
|
44
|
+
engine: PackageManifest
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def module(self) -> str:
|
|
48
|
+
return self.engine.entry.partition(":")[0]
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def function(self) -> str:
|
|
52
|
+
return self.engine.entry.partition(":")[2]
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def version(self) -> str:
|
|
56
|
+
return str(self.plugin.get("version") or "0.0.0")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@dataclass(frozen=True, kw_only=True)
|
|
60
|
+
class Pyproject:
|
|
61
|
+
name: str
|
|
62
|
+
requires_python: str
|
|
63
|
+
dependencies: tuple[str, ...]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def plugin_name(workflow: str) -> str:
|
|
67
|
+
"""The plugin name of the workflow package for `workflow` (ADR `a-workflow-plugin-name-is-the-workflow-name-plus-tgraph`)."""
|
|
68
|
+
return workflow + PLUGIN_SUFFIX
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def workflow_name(name: str) -> str:
|
|
72
|
+
"""The workflow name a person may also type as its plugin name: `notes-tgraph` -> `notes`."""
|
|
73
|
+
return name[: -len(PLUGIN_SUFFIX)] if name.endswith(PLUGIN_SUFFIX) and len(name) > len(PLUGIN_SUFFIX) else name
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def name_problem(name: str) -> str | None:
|
|
77
|
+
"""Why `name` cannot be a workflow name, or None (PKG-B13)."""
|
|
78
|
+
if not NAME_RE.match(name):
|
|
79
|
+
return f"workflow name {name!r} is not kebab-case (lower-case letters, digits and hyphens)"
|
|
80
|
+
if name.endswith(PLUGIN_SUFFIX):
|
|
81
|
+
return (f"workflow name {name!r} ends in {PLUGIN_SUFFIX!r}; the suffix belongs to the plugin name only, "
|
|
82
|
+
f"so name the workflow {workflow_name(name)!r}")
|
|
83
|
+
if len(plugin_name(name)) > PLUGIN_NAME_MAX:
|
|
84
|
+
return (f"workflow name {name!r} is too long: its plugin name {plugin_name(name)!r} must be at most "
|
|
85
|
+
f"{PLUGIN_NAME_MAX} characters")
|
|
86
|
+
if name.startswith(RESERVED_PREFIXES):
|
|
87
|
+
return f"workflow name {name!r} starts with a prefix Claude Code reserves ({', '.join(RESERVED_PREFIXES)})"
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _err(code: str, message: str, severity: str = "error") -> Finding:
|
|
92
|
+
return Finding(code, None, message, severity) # type: ignore[arg-type]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _object(path: Path) -> dict[str, Any] | Finding:
|
|
96
|
+
try:
|
|
97
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
98
|
+
except FileNotFoundError:
|
|
99
|
+
return _err("manifest", f"{path.name} is missing")
|
|
100
|
+
except (OSError, ValueError) as exc:
|
|
101
|
+
return _err("manifest", f"{path.name}: {type(exc).__name__}")
|
|
102
|
+
if not isinstance(data, dict):
|
|
103
|
+
return _err("manifest", f"{path.name} is not a JSON object")
|
|
104
|
+
return data
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _step_pattern(p: Any) -> bool:
|
|
108
|
+
return isinstance(p, str) and bool(p.strip()) and not p.startswith(("/", "\\")) and ".." not in p.split("/")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def step_files(package_path: Path, patterns: Iterable[str]) -> dict[str, bytes]:
|
|
112
|
+
"""PKG-B13: the files a package declares that its steps read at run time, by package-relative path."""
|
|
113
|
+
out: dict[str, bytes] = {}
|
|
114
|
+
root = Path(package_path)
|
|
115
|
+
for pattern in patterns:
|
|
116
|
+
if not _step_pattern(pattern):
|
|
117
|
+
continue
|
|
118
|
+
for p in sorted(root.glob(pattern)):
|
|
119
|
+
if p.is_file():
|
|
120
|
+
out[p.relative_to(root).as_posix()] = p.read_bytes()
|
|
121
|
+
return out
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def declared_step_files(package_path: Path | None) -> tuple[str, ...]:
|
|
125
|
+
"""The `step_files` patterns of a package's `tempergraph.json`, or none when it cannot be read."""
|
|
126
|
+
if package_path is None:
|
|
127
|
+
return ()
|
|
128
|
+
got = read_manifest(Path(package_path))
|
|
129
|
+
return () if isinstance(got, list) else tuple(got.step_files)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def over_budget(package_path: Path | None, budgets: Mapping[str, int] | None = None) -> list[tuple[str, int, int]]:
|
|
133
|
+
"""PKG-B26: (file, characters, budget) for each package file above the smallest budget whose glob matches it."""
|
|
134
|
+
if package_path is None:
|
|
135
|
+
return []
|
|
136
|
+
if budgets is None:
|
|
137
|
+
got = read_manifest(Path(package_path))
|
|
138
|
+
budgets = {} if isinstance(got, list) else got.text_budgets
|
|
139
|
+
limits: dict[str, int] = {}
|
|
140
|
+
for pattern, most in budgets.items():
|
|
141
|
+
for p in Path(package_path).glob(pattern):
|
|
142
|
+
if p.is_file():
|
|
143
|
+
rel = p.relative_to(package_path).as_posix()
|
|
144
|
+
limits[rel] = min(most, limits.get(rel, most))
|
|
145
|
+
out = []
|
|
146
|
+
for rel, most in sorted(limits.items()):
|
|
147
|
+
try:
|
|
148
|
+
n = len((Path(package_path) / rel).read_text(encoding="utf-8"))
|
|
149
|
+
except (OSError, UnicodeDecodeError):
|
|
150
|
+
continue
|
|
151
|
+
if n > most:
|
|
152
|
+
out.append((rel, n, most))
|
|
153
|
+
return out
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def read_manifests(package_path: Path) -> Manifests | list[Finding]:
|
|
157
|
+
"""Step 1 of PKG-B15, PKG-B16, PKG-B17: both manifests, the plugin name is the workflow name plus `-tgraph`,
|
|
158
|
+
`schema_version` known; no import, no model."""
|
|
159
|
+
plugin = _object(package_path / PLUGIN_JSON)
|
|
160
|
+
engine = _object(package_path / ENGINE_JSON)
|
|
161
|
+
found = [f for f in (plugin, engine) if isinstance(f, Finding)]
|
|
162
|
+
if found:
|
|
163
|
+
return found
|
|
164
|
+
assert isinstance(plugin, dict) and isinstance(engine, dict)
|
|
165
|
+
out: list[Finding] = []
|
|
166
|
+
if engine.get("schema_version") != 1:
|
|
167
|
+
out.append(_err("manifest", f"tempergraph.json schema_version {engine.get('schema_version')!r} is unknown"))
|
|
168
|
+
name = engine.get("name")
|
|
169
|
+
problem = name_problem(name) if isinstance(name, str) else f"tempergraph.json name {name!r} is not a string"
|
|
170
|
+
if problem:
|
|
171
|
+
out.append(_err("manifest", f"tempergraph.json: {problem}"))
|
|
172
|
+
elif plugin.get("name") != plugin_name(str(name)):
|
|
173
|
+
out.append(_err("plugin-name-suffix", f"plugin.json name is {plugin.get('name')!r}; a workflow package's "
|
|
174
|
+
f"plugin name is its workflow name plus {PLUGIN_SUFFIX!r}: {plugin_name(str(name))!r} "
|
|
175
|
+
f"(tempergraph.json name {name!r})"))
|
|
176
|
+
entry = engine.get("entry")
|
|
177
|
+
if not isinstance(entry, str) or not ENTRY_RE.match(entry):
|
|
178
|
+
out.append(_err("manifest", f"entry {entry!r} must be <module>:<function>"))
|
|
179
|
+
api = engine.get("workflow_api")
|
|
180
|
+
if not isinstance(api, int) or isinstance(api, bool) or api < 1:
|
|
181
|
+
out.append(_err("manifest", f"workflow_api {api!r} must be a positive integer"))
|
|
182
|
+
docs = engine.get("docs", "provisional")
|
|
183
|
+
if not isinstance(docs, str) or not DOCS_RE.match(docs):
|
|
184
|
+
out.append(_err("manifest", f"docs {docs!r} must be 'provisional' or a rule set id"))
|
|
185
|
+
surfaces = engine.get("surfaces", {})
|
|
186
|
+
if not isinstance(surfaces, dict):
|
|
187
|
+
out.append(_err("manifest", "surfaces must map an executor to a surface form"))
|
|
188
|
+
audit = engine.get("audit", {})
|
|
189
|
+
if not isinstance(audit, dict):
|
|
190
|
+
out.append(_err("manifest", "audit must be an object, such as {\"ignore\": [...]} (AUD-B14)"))
|
|
191
|
+
step_files = engine.get("step_files", [])
|
|
192
|
+
if not isinstance(step_files, list) or not all(_step_pattern(p) for p in step_files):
|
|
193
|
+
out.append(_err("manifest", "step_files must be a list of package-relative glob patterns, such as "
|
|
194
|
+
"[\"rules/*.rule.md\"], with no absolute path and no `..`"))
|
|
195
|
+
budgets = engine.get("text_budgets", {})
|
|
196
|
+
if not isinstance(budgets, dict) or not all(
|
|
197
|
+
isinstance(k, str) and _step_pattern(k) and isinstance(v, int) and not isinstance(v, bool) and v > 0
|
|
198
|
+
for k, v in budgets.items()):
|
|
199
|
+
out.append(_err("manifest", "text_budgets must map a package-relative glob to a positive number of "
|
|
200
|
+
"characters, such as {\"prompts/*.md\": 12000}"))
|
|
201
|
+
unknown = set(engine) - {"schema_version", "name", "entry", "workflow_api", "docs", "surfaces", "audit",
|
|
202
|
+
"step_files", "text_budgets"}
|
|
203
|
+
if unknown:
|
|
204
|
+
out.append(_err("manifest-field-unknown", f"tempergraph.json fields {sorted(unknown)} are unknown "
|
|
205
|
+
"(the version comes from plugin.json)", "warning"))
|
|
206
|
+
if any(f.severity == "error" for f in out):
|
|
207
|
+
return out
|
|
208
|
+
return Manifests(plugin=plugin, engine=PackageManifest(
|
|
209
|
+
schema_version=1, name=str(name), entry=str(entry), workflow_api=int(api or 0), docs=str(docs),
|
|
210
|
+
surfaces=dict(surfaces), audit=dict(audit), step_files=tuple(step_files), text_budgets=dict(budgets)))
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def read_manifest(package_path: Path) -> PackageManifest | list[Finding]:
|
|
214
|
+
"""The PKG-B13, PKG-B15 contract: the engine manifest, or the findings that stop it loading."""
|
|
215
|
+
got = read_manifests(package_path)
|
|
216
|
+
return got if isinstance(got, list) else got.engine
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def read_pyproject(package_path: Path) -> Pyproject | Finding:
|
|
220
|
+
path = package_path / PYPROJECT
|
|
221
|
+
try:
|
|
222
|
+
data = tomllib.loads(path.read_text(encoding="utf-8"))
|
|
223
|
+
except FileNotFoundError:
|
|
224
|
+
return _err("pyproject-missing", "workflow/pyproject.toml is missing")
|
|
225
|
+
except (OSError, ValueError) as exc:
|
|
226
|
+
return _err("pyproject-invalid", f"workflow/pyproject.toml: {type(exc).__name__}")
|
|
227
|
+
project = data.get("project")
|
|
228
|
+
if not isinstance(project, dict):
|
|
229
|
+
return _err("pyproject-invalid", "workflow/pyproject.toml has no [project] table")
|
|
230
|
+
deps = project.get("dependencies", [])
|
|
231
|
+
if not isinstance(deps, list) or not all(isinstance(d, str) for d in deps):
|
|
232
|
+
return _err("pyproject-invalid", "[project].dependencies must be a list of strings")
|
|
233
|
+
return Pyproject(name=str(project.get("name") or ""), requires_python=str(project.get("requires-python") or ""),
|
|
234
|
+
dependencies=tuple(deps))
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def requirement_name(line: str) -> str | None:
|
|
238
|
+
m = REQUIREMENT_RE.match(line)
|
|
239
|
+
return None if m is None else m.group("name")
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def normalized(name: str) -> str:
|
|
243
|
+
return re.sub(r"[-_.]+", "-", name).lower()
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def gate_dependencies(deps: tuple[str, ...]) -> list[Finding]:
|
|
247
|
+
"""The dependency gate (PKG-B18): a refusal makes the package `not_loaded: dependency_refused`."""
|
|
248
|
+
out = []
|
|
249
|
+
for line in deps:
|
|
250
|
+
name = requirement_name(line)
|
|
251
|
+
if name is None:
|
|
252
|
+
out.append(_err("dependency_refused", f"{line!r} is not a plain requirement (name, extras, "
|
|
253
|
+
"version specifiers, marker); direct references and options are refused"))
|
|
254
|
+
elif normalized(name) in ENGINE_DISTRIBUTIONS:
|
|
255
|
+
out.append(_err("dependency_refused", f"{line!r}: the engine is not a workflow dependency"))
|
|
256
|
+
return out
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""The structural judge readiness report (LIF-B7 to LIF-B16, LIF-B6): per judged gate, model-free.
|
|
2
|
+
|
|
3
|
+
Grades: `ready` (structure clean and the judge binding `accepted` under JCL), `needs cases` (structure clean,
|
|
4
|
+
not accepted), `needs work` (a structural finding). Acceptance is read from the package's calibration scores
|
|
5
|
+
(JCL-B17, `improve/calibration.py`), so a workflow in `stable` mode is refused with `gate-not-ready` until
|
|
6
|
+
every judged gate is `accepted` (LIF-B6).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections.abc import Callable, Iterable
|
|
12
|
+
from dataclasses import dataclass, field
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from tempergraph.contracts import Criterion, WorkflowSpec
|
|
17
|
+
from tempergraph.model import flow
|
|
18
|
+
from tempergraph.model.prompt_lint import VAGUE
|
|
19
|
+
from tempergraph.model.validate import Finding
|
|
20
|
+
|
|
21
|
+
SCALE_FIELDS = ("met", "unmet", "evidence")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(kw_only=True)
|
|
25
|
+
class GateReadiness:
|
|
26
|
+
gate: str
|
|
27
|
+
grade: str
|
|
28
|
+
findings: list[str] = field(default_factory=list)
|
|
29
|
+
criteria: int = 0
|
|
30
|
+
blockers: int = 0
|
|
31
|
+
calibration_cases: int = 0
|
|
32
|
+
acceptance: str = "unscored"
|
|
33
|
+
|
|
34
|
+
def to_json(self) -> dict[str, Any]:
|
|
35
|
+
return {"gate": self.gate, "grade": self.grade, "findings": self.findings, "criteria": self.criteria,
|
|
36
|
+
"blockers": self.blockers, "calibration_cases": self.calibration_cases, "acceptance": self.acceptance}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _structural(c: Criterion) -> list[str]:
|
|
40
|
+
out: list[str] = []
|
|
41
|
+
if c.mechanical or c.verified_by in ("check", "person", "none"):
|
|
42
|
+
return out
|
|
43
|
+
if not c.check_method.strip():
|
|
44
|
+
out.append(f"{c.id or c.text[:30]}: no check method")
|
|
45
|
+
if c.verified_by == "judge":
|
|
46
|
+
scale = dict((c.verifier or {}).get("scale") or {})
|
|
47
|
+
missing = [f for f in SCALE_FIELDS if not str(scale.get(f) or "").strip()]
|
|
48
|
+
if c.severity == "blocker" and not str(scale.get("partial") or "").strip():
|
|
49
|
+
missing.append("partial")
|
|
50
|
+
if missing:
|
|
51
|
+
out.append(f"{c.id}: scale lacks {', '.join(missing)} (OUT-B11)")
|
|
52
|
+
low = c.text.lower()
|
|
53
|
+
vague = [w for w in VAGUE if w in low]
|
|
54
|
+
if vague:
|
|
55
|
+
out.append(f"{c.id or c.text[:30]}: vague wording {', '.join(repr(w) for w in vague)}")
|
|
56
|
+
return out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _cases(root: Path | None, gate: str) -> int:
|
|
60
|
+
folder = root / "evals" / "calibration" / gate if root is not None else None
|
|
61
|
+
return sum(1 for p in folder.iterdir() if not p.name.startswith(".") and p.name != "scores.jsonl"
|
|
62
|
+
) if folder and folder.is_dir() else 0
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _gates(spec: WorkflowSpec) -> Iterable[tuple[str, list[Criterion]]]:
|
|
66
|
+
for name in spec.order:
|
|
67
|
+
u = spec.units.get(name)
|
|
68
|
+
if u is not None and u.gate.judge is not None:
|
|
69
|
+
yield name, list(u.gate.criteria)
|
|
70
|
+
if spec.outcome is not None and spec.outcome.final:
|
|
71
|
+
yield flow.OUTCOME_UNIT, list(spec.outcome.final)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def readiness(spec: WorkflowSpec, accepted: Callable[[str], bool] | None = None,
|
|
75
|
+
state_of: Callable[[str], str] | None = None) -> list[GateReadiness]:
|
|
76
|
+
"""`accepted(gate)` answers whether the gate's judge binding is `accepted` (JCL-B17); by default it is
|
|
77
|
+
read from the package's calibration scores (`improve/calibration.py`), as is `state_of(gate)`."""
|
|
78
|
+
from tempergraph.author.criteria_lint import lint, package_doc
|
|
79
|
+
|
|
80
|
+
if accepted is None:
|
|
81
|
+
from tempergraph.improve import calibration
|
|
82
|
+
|
|
83
|
+
accepted = calibration.accepted_for(spec)
|
|
84
|
+
state_of = state_of or calibration.state_name_for(spec)
|
|
85
|
+
|
|
86
|
+
doc = package_doc(spec.package_root)
|
|
87
|
+
linted = lint(doc) if doc is not None else []
|
|
88
|
+
out = []
|
|
89
|
+
for gate, criteria in _gates(spec):
|
|
90
|
+
notes = [n for c in criteria for n in _structural(c)]
|
|
91
|
+
mine = [f for f in linted if (f.unit or flow.OUTCOME_UNIT) == gate and f.criterion is not None]
|
|
92
|
+
notes += [f"{f.code}: {f.message}" for f in mine if f.code != "criterion-no-seed"]
|
|
93
|
+
seedless = [f.criterion for f in mine if f.code == "criterion-no-seed"]
|
|
94
|
+
judged = [c for c in criteria if not c.mechanical and c.verified_by not in ("check", "person", "none")]
|
|
95
|
+
blockers = sum(1 for c in judged if c.severity == "blocker")
|
|
96
|
+
if judged and not blockers:
|
|
97
|
+
notes.append("no judged criterion is a blocker, so the judge can never send the work back")
|
|
98
|
+
ok = accepted(gate)
|
|
99
|
+
grade = "needs work" if notes else ("ready" if ok else "needs cases")
|
|
100
|
+
# AUT-B12, AUT-B15, AUT-B19, AUT-B24, AUT-B25: a missing seed is a calibration gap, shown but not graded as structural
|
|
101
|
+
notes += [f"criterion-no-seed: {c} has no met and unmet seed" for c in seedless]
|
|
102
|
+
out.append(GateReadiness(gate=gate, grade=grade, findings=notes, criteria=len(criteria), blockers=blockers,
|
|
103
|
+
calibration_cases=_cases(spec.package_root, gate),
|
|
104
|
+
acceptance=state_of(gate) if state_of else ("accepted" if ok else "unscored")))
|
|
105
|
+
return out
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def stable_findings(spec: WorkflowSpec) -> list[Finding]:
|
|
109
|
+
"""LIF-B6: a `stable` workflow needs every judged gate `ready`."""
|
|
110
|
+
if spec.improvement_mode != "stable":
|
|
111
|
+
return []
|
|
112
|
+
from tempergraph.improve import calibration
|
|
113
|
+
|
|
114
|
+
def why(g: GateReadiness) -> str:
|
|
115
|
+
if g.findings:
|
|
116
|
+
return f": {'; '.join(g.findings)}"
|
|
117
|
+
raised = calibration.unaccepted_levels(spec, g.gate) # JRK-B5: every routed level, with what fixes it
|
|
118
|
+
if raised and g.acceptance == "accepted":
|
|
119
|
+
return "; " + "; ".join(f"risk level {lv!r} is {st}: run `tempergraph evals score {spec.name} {g.gate} "
|
|
120
|
+
f"--level {lv}`" for lv, st in raised)
|
|
121
|
+
return " (no accepted judge binding)"
|
|
122
|
+
|
|
123
|
+
return [Finding("gate-not-ready", g.gate, f"`stable` needs the gate `ready`; it is {g.grade!r}" + why(g))
|
|
124
|
+
for g in readiness(spec) if g.grade != "ready"]
|