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,229 @@
|
|
|
1
|
+
"""Run state: JSON one level deep, merged by reducers (CMP-B17, DUR OVR-B9).
|
|
2
|
+
|
|
3
|
+
Channels written by units that can run in one superstep are keyed by unit. One reducer deletes: a key
|
|
4
|
+
written as ``None`` is removed, which is how a trip back clears artifacts, values, facts and judgements.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import functools
|
|
10
|
+
from collections.abc import Mapping
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from typing import Annotated, Any, TypedDict
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def merge_units(old: dict[str, Any] | None, new: dict[str, Any] | None) -> dict[str, Any]:
|
|
16
|
+
"""Two-level merge: ``{unit: None}`` deletes a unit; ``{unit: {key: None}}`` deletes a key."""
|
|
17
|
+
out: dict[str, Any] = dict(old or {})
|
|
18
|
+
for unit, val in (new or {}).items():
|
|
19
|
+
if val is None:
|
|
20
|
+
out.pop(unit, None)
|
|
21
|
+
elif isinstance(val, dict) and isinstance(out.get(unit), dict):
|
|
22
|
+
merged = dict(out[unit])
|
|
23
|
+
for k, v in val.items():
|
|
24
|
+
if v is None:
|
|
25
|
+
merged.pop(k, None)
|
|
26
|
+
else:
|
|
27
|
+
merged[k] = v
|
|
28
|
+
out[unit] = merged
|
|
29
|
+
else:
|
|
30
|
+
out[unit] = val
|
|
31
|
+
return out
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def merge_maps(old: dict[str, Any] | None, new: dict[str, Any] | None) -> dict[str, Any]:
|
|
35
|
+
"""The reducer of the `maps` channel (MAP-B9, MAP-B10, CMP-AC9): `merge_units`, safe for two items of a concurrent map
|
|
36
|
+
ending in one superstep. Each item writes keys of its own (`n:<id>`, `st:<id>`), which merge by item id, and the
|
|
37
|
+
ids that passed are a union; a write that carries a list (it starts a visit, or rewrites the record whole) is
|
|
38
|
+
taken as it is, so a new visit forgets the passed ids of the last."""
|
|
39
|
+
out: dict[str, Any] = dict(old or {})
|
|
40
|
+
for unit, val in (new or {}).items():
|
|
41
|
+
held = out.get(unit)
|
|
42
|
+
if isinstance(val, dict) and isinstance(held, dict) and "items" not in val and isinstance(val.get("passed"), list):
|
|
43
|
+
union = list(dict.fromkeys(list(held.get("passed") or []) + val["passed"]))
|
|
44
|
+
out.update(merge_units({unit: held}, {unit: {**val, "passed": union}}))
|
|
45
|
+
else:
|
|
46
|
+
out.update(merge_units({unit: held} if unit in out else {}, {unit: val}))
|
|
47
|
+
if val is None:
|
|
48
|
+
out.pop(unit, None)
|
|
49
|
+
return out
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def merge_run(old: dict[str, Any] | None, new: dict[str, Any] | None) -> dict[str, Any]:
|
|
53
|
+
"""`merge_units` for the run-level facts, safe for two branches of a parallel block writing in one superstep:
|
|
54
|
+
the path's units are a union in arrival order, and a cost total is added as the delta its writer made on
|
|
55
|
+
the total it read (`_base`), so neither branch's sessions are lost."""
|
|
56
|
+
new = dict(new or {})
|
|
57
|
+
out = dict(old or {})
|
|
58
|
+
path, cost = new.pop("path", None), new.pop("cost", None)
|
|
59
|
+
if isinstance(path, dict) and isinstance(path.get("units"), list):
|
|
60
|
+
have = list((out.get("path") or {}).get("units") or [])
|
|
61
|
+
out["path"] = {**(out.get("path") or {}), **path, "units": have + [u for u in path["units"] if u not in have]}
|
|
62
|
+
elif path is not None:
|
|
63
|
+
new["path"] = path
|
|
64
|
+
if isinstance(cost, dict):
|
|
65
|
+
base = cost.get("_base")
|
|
66
|
+
cost = {k: v for k, v in cost.items() if k != "_base"}
|
|
67
|
+
held = (out.get("cost") or {}).get("counters")
|
|
68
|
+
if isinstance(base, dict) and isinstance(held, dict) and held != base:
|
|
69
|
+
from tempergraph.run.log import CostTotals
|
|
70
|
+
|
|
71
|
+
t = CostTotals.from_json(out.get("cost"))
|
|
72
|
+
for k, v in (cost.get("counters") or {}).items():
|
|
73
|
+
setattr(t, k, getattr(t, k) + v - (base.get(k) or 0))
|
|
74
|
+
cost = t.to_json()
|
|
75
|
+
out["cost"] = {k: v for k, v in cost.items() if v is not None} # an absent figure is an absent key
|
|
76
|
+
return merge_units(out, new)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def replace(old: Any, new: Any) -> Any:
|
|
80
|
+
return new if new is not None else old
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def council_answers(state: Mapping[str, Any], unit: str) -> dict[str, Any]:
|
|
84
|
+
"""The members' answers a council attempt left in the state (`council` channel), as written: `stages` (a list of
|
|
85
|
+
`{member name: answer}` per round) and `ranks` (a ranking pass's answers); empty when the unit has none."""
|
|
86
|
+
held = (state.get("council") or {}).get(unit)
|
|
87
|
+
return dict(held) if isinstance(held, dict) else {}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# A sub-workflow's child (SWF-B1, SWF-B8) runs on a run state of its own: the same channels, keyed by the child's own
|
|
91
|
+
# unit names, so a child `work` never meets the parent's `work`. The parent sees only what its unit exposes.
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def child_input(parent: Mapping[str, Any], inputs: Mapping[str, str], options: Mapping[str, Any] | None = None
|
|
95
|
+
) -> dict[str, Any]:
|
|
96
|
+
"""The first state of a child: the parent's task and workspace, the inputs the unit mapped, the operator layers as
|
|
97
|
+
the child reads them (for a child of its own), and the parent's cost so far, so one run cost cap holds across both
|
|
98
|
+
(SWF-B4)."""
|
|
99
|
+
req = parent.get("request") or {}
|
|
100
|
+
out: dict[str, Any] = {"request": {"task_id": req.get("task_id"), "inputs": dict(inputs)},
|
|
101
|
+
"workspace": dict(parent.get("workspace") or {})}
|
|
102
|
+
run: dict[str, Any] = {}
|
|
103
|
+
cost = (parent.get("run") or {}).get("cost")
|
|
104
|
+
if cost:
|
|
105
|
+
run["cost"] = {k: v for k, v in cost.items() if k != "_base"}
|
|
106
|
+
if options:
|
|
107
|
+
run["options"] = dict(options)
|
|
108
|
+
if run:
|
|
109
|
+
out["run"] = run
|
|
110
|
+
return out
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def flat(channel: Mapping[str, Any] | None) -> dict[str, Any]:
|
|
114
|
+
"""Every unit's keys of one channel as one mapping, a later unit's key replacing an earlier one's."""
|
|
115
|
+
out: dict[str, Any] = {}
|
|
116
|
+
for vals in (channel or {}).values():
|
|
117
|
+
if isinstance(vals, dict):
|
|
118
|
+
out.update(vals)
|
|
119
|
+
return out
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def fold(state: Mapping[str, Any], writes: Mapping[str, Any]) -> dict[str, Any]:
|
|
123
|
+
"""`state` as it reads once `writes` are applied through each channel's own reducer: what a node of a concurrent
|
|
124
|
+
map's item hands to the next node of the same item (a `Send` carries a state of its own, not the channels)."""
|
|
125
|
+
out = dict(state)
|
|
126
|
+
for channel, value in writes.items():
|
|
127
|
+
reducer = _reducers().get(channel)
|
|
128
|
+
out[channel] = reducer(out.get(channel), value) if reducer is not None else value
|
|
129
|
+
return out
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
ITEM = "__item" # the key a node of a concurrent map's item finds in the state it is sent: `{unit, id, slot}`
|
|
133
|
+
SLOT_CHANNELS = ("attempts", "judgements", "feedback", "counters", "route", "pause") # an item's are keyed by its slot
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def slot(unit: str, item: str) -> str:
|
|
137
|
+
"""`<unit>.<item id>`: how an item of a concurrent map, or a slot of a contest, is addressed (an item id holds no dot;
|
|
138
|
+
a slot name is a slug, which holds none either)."""
|
|
139
|
+
return f"{unit}.{item}"
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def item_view(state: Mapping[str, Any], unit: str, item: str) -> dict[str, Any]:
|
|
143
|
+
"""`state` as an item's node reads it: the slot's own record in the place the unit's own would be, so the step,
|
|
144
|
+
judge, gate and human bodies run on an item as they run on a unit."""
|
|
145
|
+
at = slot(unit, item)
|
|
146
|
+
view = dict(state)
|
|
147
|
+
for channel in SLOT_CHANNELS:
|
|
148
|
+
held = dict(state.get(channel) or {})
|
|
149
|
+
if at in held:
|
|
150
|
+
held[unit] = held[at]
|
|
151
|
+
else:
|
|
152
|
+
held.pop(unit, None)
|
|
153
|
+
view[channel] = held
|
|
154
|
+
view[ITEM] = {"unit": unit, "id": item, "slot": at}
|
|
155
|
+
return view
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def slot_writes(writes: Mapping[str, Any], unit: str, item: str) -> dict[str, Any]:
|
|
159
|
+
"""What a body wrote for the unit, moved to the item's slot so that items finishing in one superstep never share a key."""
|
|
160
|
+
out = dict(writes)
|
|
161
|
+
at = slot(unit, item)
|
|
162
|
+
for channel in SLOT_CHANNELS:
|
|
163
|
+
got = out.get(channel)
|
|
164
|
+
if isinstance(got, dict) and unit in got:
|
|
165
|
+
out[channel] = {(at if k == unit else k): v for k, v in got.items()}
|
|
166
|
+
return out
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def own_keys(held: Mapping[str, Any] | None, item: str) -> dict[str, Any]:
|
|
170
|
+
"""One item's keys of a unit's artifacts, values or facts as plain keys: `<key>[<item>]` read as `<key>`. A contest's
|
|
171
|
+
judge sees these only, so one slot's judge holds no other slot's artifact (CTS-B3)."""
|
|
172
|
+
tail = f"[{item}]"
|
|
173
|
+
return {k[: -len(tail)]: v for k, v in (held or {}).items() if k.endswith(tail)}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def item_end(unit: str, item: str, token: str, node: str) -> dict[str, Any]:
|
|
177
|
+
"""The `maps` write of an item's turn: it goes on (a retry), has passed, waits for a person (parked) or has stopped
|
|
178
|
+
the map, naming where the map then goes (a stop, a fallback or a person's rewind)."""
|
|
179
|
+
key = f"st:{item}"
|
|
180
|
+
if token == "RETRY":
|
|
181
|
+
return {"maps": {unit: {key: "started"}}}
|
|
182
|
+
if token in ("NEXT", "PROCEED"):
|
|
183
|
+
return {"maps": {unit: {key: "passed"}}}
|
|
184
|
+
if token == "ESCALATE":
|
|
185
|
+
return {"maps": {unit: {key: "parked"}}}
|
|
186
|
+
return {"maps": {unit: {key: "stopped", "exit": {"token": token, "node": node, "item": item}}}}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@dataclass
|
|
190
|
+
class Move:
|
|
191
|
+
"""What a concurrent map's own step node does next: the state it writes, the items it sends to an item node (`kind`
|
|
192
|
+
is `step` or `human`), or the node it goes to; with none of these it waits for the items that are running."""
|
|
193
|
+
|
|
194
|
+
writes: dict[str, Any]
|
|
195
|
+
items: list[str] = field(default_factory=list)
|
|
196
|
+
kind: str = "step"
|
|
197
|
+
goto: str | None = None
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@functools.lru_cache(maxsize=1)
|
|
201
|
+
def _reducers() -> dict[str, Any]:
|
|
202
|
+
from typing import get_type_hints
|
|
203
|
+
|
|
204
|
+
return {name: m for name, hint in get_type_hints(RunState, include_extras=True).items()
|
|
205
|
+
for m in getattr(hint, "__metadata__", ()) if callable(m)}
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class RunState(TypedDict, total=False):
|
|
209
|
+
request: Annotated[dict[str, Any], replace] # {task_id, inputs, text_ref, chars}
|
|
210
|
+
# WorkspaceRecord, writer worktrees included (its `children`). Written by the fork and by the join, each alone in
|
|
211
|
+
# its superstep, never by a branch node, so `replace` is the reducer CMP-AC9 asks of every channel.
|
|
212
|
+
workspace: Annotated[dict[str, Any], replace]
|
|
213
|
+
artifacts: Annotated[dict[str, Any], merge_units] # unit -> key -> pointer
|
|
214
|
+
values: Annotated[dict[str, Any], merge_units] # unit -> key -> value
|
|
215
|
+
facts: Annotated[dict[str, Any], merge_units] # unit -> key -> str
|
|
216
|
+
attempts: Annotated[dict[str, Any], merge_units] # unit -> {attempt, visit, last result summary}
|
|
217
|
+
judgements: Annotated[dict[str, Any], merge_units] # unit -> outcome of the judge node
|
|
218
|
+
route: Annotated[dict[str, Any], merge_units] # unit -> {token, node, ...}
|
|
219
|
+
pause: Annotated[dict[str, Any], merge_units] # unit -> pause payload
|
|
220
|
+
feedback: Annotated[dict[str, Any], merge_units] # unit -> one-time feedback for the next attempt
|
|
221
|
+
counters: Annotated[dict[str, Any], merge_units] # unit -> budget counters
|
|
222
|
+
visits: Annotated[dict[str, Any], merge_units] # unit -> {visit, reason, from}
|
|
223
|
+
maps: Annotated[dict[str, Any], merge_maps] # map unit -> {visit, items, passed, n:<id>, st:<id>} (MAP-B8 to MAP-B10)
|
|
224
|
+
# council unit -> {attempt, labels, stages, ranks}: each member's answer of every round and its ranking, as a council
|
|
225
|
+
# attempt ended (CNL-B7, CNL-B10, CNL-B14). Written once by the unit's step node, which is the one writer of a unit's key.
|
|
226
|
+
council: Annotated[dict[str, Any], merge_units]
|
|
227
|
+
rulings: Annotated[dict[str, Any], merge_units] # id -> ruling (own reducer, never cleared by a trip back)
|
|
228
|
+
finalized: Annotated[dict[str, Any], replace]
|
|
229
|
+
run: Annotated[dict[str, Any], merge_run] # run-level facts: {"stopped": {...}, "path": [...]}
|
tempergraph/constants.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Engine-wide constants: exit codes, schema versions, release, reserved words.
|
|
2
|
+
|
|
3
|
+
The exit-code table is the caller contract of CON-B12, CON-B13; ``tests/test_contract_tables.py`` checks it
|
|
4
|
+
against the table in ``docs/specs/contracts.spec.md`` (CON-AC6, CLI-AC4).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from enum import IntEnum
|
|
10
|
+
|
|
11
|
+
ENGINE_VERSION = "0.7.1"
|
|
12
|
+
RELEASE = 2 # the release this engine builds (ADR `first-release-is-simple-trusted-workflows-on-one-machine`, ADR `release-two-adds-upgrade-ladders-judge-risk-and-complexity-routing`)
|
|
13
|
+
WORKFLOW_API = 1 # the declaration interface level (PKG-B13, VER-B8)
|
|
14
|
+
LOADS_WORKFLOW_API_FROM = 1
|
|
15
|
+
STORE_LAYOUT = 1 # LOS-B7, LOS-B8, LOS-B9 layout version
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ExitCode(IntEnum):
|
|
19
|
+
"""CON-B12, CON-B13 ``ExitCode``."""
|
|
20
|
+
|
|
21
|
+
FINISHED = 0
|
|
22
|
+
INTERNAL = 1
|
|
23
|
+
USAGE = 2 # usage or preflight refusal, nothing spent or created
|
|
24
|
+
PAUSED = 3 # paused for a person
|
|
25
|
+
STOPPED = 4
|
|
26
|
+
BUDGET_OR_INFRA = 5 # budget spent or infra failure
|
|
27
|
+
ADVISORY = 6 # an advisory verb found issues at the level asked for
|
|
28
|
+
NOT_INSTALLED = 127 # engine not installed (shim)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# Schema versions of persisted documents (CON-B14, CON-B1, CON-B15).
|
|
32
|
+
SCHEMA = {
|
|
33
|
+
"run_log": 1,
|
|
34
|
+
"status": 1,
|
|
35
|
+
"findings": 1,
|
|
36
|
+
"ledger": 1,
|
|
37
|
+
"catalog": 1,
|
|
38
|
+
"diagram_model": 1,
|
|
39
|
+
"detail": 1,
|
|
40
|
+
"activity": 1,
|
|
41
|
+
"store_manifest": 1,
|
|
42
|
+
"settings": 1,
|
|
43
|
+
"lineage": 1,
|
|
44
|
+
"package_manifest": 1,
|
|
45
|
+
"outcome": 1,
|
|
46
|
+
"facts": 1,
|
|
47
|
+
"bindings": 1,
|
|
48
|
+
"audit_report": 1,
|
|
49
|
+
"proposal": 1,
|
|
50
|
+
"trial": 1,
|
|
51
|
+
"labels": 1,
|
|
52
|
+
"stamp": 1,
|
|
53
|
+
"registry": 1,
|
|
54
|
+
"engine_pointers": 1,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# Verb words are reserved and refused as run input (CLI-B2, CLI-AC3).
|
|
58
|
+
RESERVED_VERBS = frozenset(
|
|
59
|
+
{
|
|
60
|
+
"run", "resume", "rerun", "config", "status", "events", "logs", "wait", "attention", "list",
|
|
61
|
+
"graph", "report", "validate", "audit", "executors", "batch", "orchestrate", "schedule", "stop",
|
|
62
|
+
"worktree", "update", "install", "workflows", "upgrade", "upgrade-check", "facts", "stats",
|
|
63
|
+
"store", "hooks", "improve", "label", "labels", "evals", "supervision", "author", "blueprint",
|
|
64
|
+
"literals", "scaffold", "outcome", "self-check",
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Executor names are constants, registered in this order (EXI-B16, EXI-B17).
|
|
69
|
+
EXECUTOR_NAMES = ("claude", "agent-sdk", "messages-api", "antigravity")
|
|
70
|
+
SHIPPED_EXECUTORS = ("claude",) # ADR `first-release-ships-the-claude-executor-only`: release 1 and 2 ship claude only
|
|
71
|
+
|
|
72
|
+
MISSING_MARKER = "⟨missing:{name}⟩" # CON-B8
|