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,324 @@
|
|
|
1
|
+
"""Where each unit can go: the one answer the compiler, validation and the diagram share (CMP-B8).
|
|
2
|
+
|
|
3
|
+
``successors`` lists, per routing token, the target nodes. Node names come from ``node_names``.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
|
|
10
|
+
from tempergraph.contracts import WorkflowSpec
|
|
11
|
+
|
|
12
|
+
FINALIZER = "finalizer"
|
|
13
|
+
END = "__end__"
|
|
14
|
+
OUTCOME_UNIT = "outcome" # reserved (OUT-B15, OUT-B16, OUT-B17, CMP-B10 to CMP-B16)
|
|
15
|
+
|
|
16
|
+
TOKENS = ("PROCEED", "RETRY", "BACK", "ESCALATE", "STOP")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def node_names(unit: str) -> tuple[str, str, str, str]:
|
|
20
|
+
return (f"{unit}.step", f"{unit}.judge", f"{unit}.gate", f"{unit}.human")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def step_node(unit: str) -> str:
|
|
24
|
+
return node_names(unit)[0]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
ITEM_KINDS = ("step", "judge", "gate", "human")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def item_node(unit: str, kind: str) -> str:
|
|
31
|
+
"""The node every item of a concurrent map passes through for `kind` (MAP-B9): one static node per kind, an item
|
|
32
|
+
reaching it by a `Send` that carries its id."""
|
|
33
|
+
return f"{unit}.item_{kind}"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def effective_order(spec: WorkflowSpec) -> tuple[str, ...]:
|
|
37
|
+
"""The units in order, with the reserved outcome gate last when the workflow has an outcome."""
|
|
38
|
+
order = tuple(spec.order)
|
|
39
|
+
if spec.outcome is not None and spec.outcome.final and OUTCOME_UNIT not in order:
|
|
40
|
+
order = order + (OUTCOME_UNIT,)
|
|
41
|
+
return order
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def target_node(target: str) -> str:
|
|
45
|
+
return FINALIZER if target == FINALIZER else step_node(target)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def fork_node(join: str) -> str:
|
|
49
|
+
return f"{join}.fork"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def done_node(branch: str) -> str:
|
|
53
|
+
return f"{branch}.done"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def block_of(spec: WorkflowSpec, unit: str) -> str | None:
|
|
57
|
+
"""The parallel block (its join unit) that `unit` is a branch of, if any (CMP-B10 to CMP-B16)."""
|
|
58
|
+
for name, u in spec.units.items():
|
|
59
|
+
if u.kind == "parallel" and unit in u.branches:
|
|
60
|
+
return name
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
WRITER_TOOLS = frozenset({"write", "edit"}) # `shell` alone makes no writer branch (WSP-B11)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def writer_branches(spec: WorkflowSpec, block: str) -> tuple[str, ...]:
|
|
68
|
+
"""The branches of the parallel block `block` that declare `write` or `edit`, in the order its parallel unit names
|
|
69
|
+
them (WSP-B11); empty for a block of read-only branches or a unit that is no block."""
|
|
70
|
+
u = spec.units.get(block)
|
|
71
|
+
if u is None or u.kind != "parallel":
|
|
72
|
+
return ()
|
|
73
|
+
return tuple(b for b in u.branches
|
|
74
|
+
if (bu := spec.units.get(b)) is not None and bu.step is not None and WRITER_TOOLS & set(bu.step.tools))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def has_writer_branch(spec: WorkflowSpec) -> bool:
|
|
78
|
+
return any(writer_branches(spec, name) for name in spec.units)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def concurrent_map(spec: WorkflowSpec, unit: str) -> bool:
|
|
82
|
+
"""`unit` is a map of `mode: concurrent` (MAP-B7, MAP-B9)."""
|
|
83
|
+
u = spec.units.get(unit)
|
|
84
|
+
return u is not None and u.kind == "map" and u.map is not None and u.map.mode == "concurrent"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def writer_map(spec: WorkflowSpec, unit: str) -> bool:
|
|
88
|
+
"""`unit` is a concurrent map whose step declares `write` or `edit`: each item works in its own worktree and the
|
|
89
|
+
items are merged when all have passed (WSP-B11, MAP-B12)."""
|
|
90
|
+
u = spec.units.get(unit)
|
|
91
|
+
return concurrent_map(spec, unit) and u is not None and u.step is not None and bool(WRITER_TOOLS & set(u.step.tools))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def has_writer_map(spec: WorkflowSpec) -> bool:
|
|
95
|
+
return any(writer_map(spec, name) for name in spec.units)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def is_contest(spec: WorkflowSpec, unit: str) -> bool:
|
|
99
|
+
"""`unit` is a contest: its slots are items that run the unit's step (CTS-B6)."""
|
|
100
|
+
u = spec.units.get(unit)
|
|
101
|
+
return u is not None and u.kind == "contest" and u.contest is not None
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def writer_contest(spec: WorkflowSpec, unit: str) -> bool:
|
|
105
|
+
"""`unit` is a contest of `writes: true`: each slot works in its own worktree and only the winner is merged (CTS-B5,
|
|
106
|
+
CTS-B7, WSP-B11)."""
|
|
107
|
+
u = spec.units.get(unit)
|
|
108
|
+
return is_contest(spec, unit) and u is not None and u.contest is not None and bool(u.contest.writes)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def has_writer_contest(spec: WorkflowSpec) -> bool:
|
|
112
|
+
return any(writer_contest(spec, name) for name in spec.units)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def slot_names(spec: WorkflowSpec, unit: str) -> tuple[str, ...]:
|
|
116
|
+
"""The slot names of a contest, in declared order: `s1` to `sN` for a count (CTS-B6); empty for a unit that is none."""
|
|
117
|
+
u = spec.units.get(unit)
|
|
118
|
+
if u is None or u.contest is None:
|
|
119
|
+
return ()
|
|
120
|
+
slots = u.contest.slots
|
|
121
|
+
if isinstance(slots, tuple | list):
|
|
122
|
+
return tuple(s.name for s in slots)
|
|
123
|
+
return tuple(f"s{n}" for n in range(1, slots + 1)) if isinstance(slots, int) and slots > 0 else ()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def in_map_item(spec: WorkflowSpec, unit: str) -> bool:
|
|
127
|
+
"""A contest that sits in a map item: the unit is a map whose item step is a contest (CTS-B10)."""
|
|
128
|
+
u = spec.units.get(unit)
|
|
129
|
+
return u is not None and u.contest is not None and (u.kind == "map" or u.map is not None)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def in_branch(spec: WorkflowSpec, unit: str) -> bool:
|
|
133
|
+
"""`unit` is a branch of a parallel block (CTS-B10 refuses a contest there)."""
|
|
134
|
+
return block_of(spec, unit) is not None
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def entry_node(spec: WorkflowSpec, target: str) -> str:
|
|
138
|
+
"""The node that enters `target`: a parallel block, named by its join or by a branch, is entered at its
|
|
139
|
+
fork, which starts every branch."""
|
|
140
|
+
if target == FINALIZER:
|
|
141
|
+
return FINALIZER
|
|
142
|
+
u = spec.units.get(target)
|
|
143
|
+
if u is not None and u.kind == "parallel":
|
|
144
|
+
return fork_node(target)
|
|
145
|
+
block = block_of(spec, target)
|
|
146
|
+
return fork_node(block) if block else step_node(target)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def entry_unit(node: str) -> str | None:
|
|
150
|
+
"""The unit a target node belongs to; None for the finalizer and the end."""
|
|
151
|
+
return node.rsplit(".", 1)[0] if "." in node else None
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@dataclass
|
|
155
|
+
class SuccessorSet:
|
|
156
|
+
proceed: list[str] = field(default_factory=list) # target nodes
|
|
157
|
+
retry: list[str] = field(default_factory=list)
|
|
158
|
+
back: list[str] = field(default_factory=list)
|
|
159
|
+
escalate: list[str] = field(default_factory=list)
|
|
160
|
+
stop: list[str] = field(default_factory=list)
|
|
161
|
+
rewind: list[str] = field(default_factory=list) # human node only (RRN-B16)
|
|
162
|
+
|
|
163
|
+
def by_token(self) -> dict[str, list[str]]:
|
|
164
|
+
return {"PROCEED": self.proceed, "RETRY": self.retry, "BACK": self.back, "ESCALATE": self.escalate,
|
|
165
|
+
"STOP": self.stop}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def next_unit(spec: WorkflowSpec, unit: str) -> str:
|
|
169
|
+
order = effective_order(spec)
|
|
170
|
+
flow = spec.flow.get(unit)
|
|
171
|
+
if flow is not None and flow.next:
|
|
172
|
+
return flow.next
|
|
173
|
+
block = block_of(spec, unit)
|
|
174
|
+
if block is not None:
|
|
175
|
+
return block # a branch's pass goes to its block's join
|
|
176
|
+
i = order.index(unit)
|
|
177
|
+
return order[i + 1] if i + 1 < len(order) else FINALIZER
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def proceed_targets(spec: WorkflowSpec, unit: str) -> list[str]:
|
|
181
|
+
"""Unit names (or `finalizer`) a pass may go to."""
|
|
182
|
+
if unit == OUTCOME_UNIT and (unit not in spec.units or spec.units[unit].extra.get("outcome")):
|
|
183
|
+
return [FINALIZER]
|
|
184
|
+
u = spec.units[unit]
|
|
185
|
+
targets: list[str]
|
|
186
|
+
if u.switch is not None:
|
|
187
|
+
targets = list(dict.fromkeys(list(u.switch.arms.values())))
|
|
188
|
+
elif u.route is not None:
|
|
189
|
+
targets = list(dict.fromkeys(u.route_targets))
|
|
190
|
+
else:
|
|
191
|
+
targets = [next_unit(spec, unit)]
|
|
192
|
+
return [through_outcome(spec, t) for t in targets]
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def through_outcome(spec: WorkflowSpec, target: str) -> str:
|
|
196
|
+
"""Every path to the finalizer passes the outcome gate (OUT-B15, OUT-B16, OUT-B17)."""
|
|
197
|
+
if target == FINALIZER and OUTCOME_UNIT in effective_order(spec):
|
|
198
|
+
return OUTCOME_UNIT
|
|
199
|
+
return target
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def back_targets(spec: WorkflowSpec, unit: str) -> list[str]:
|
|
203
|
+
if unit == OUTCOME_UNIT and unit not in spec.units:
|
|
204
|
+
return outcome_back_targets(spec)
|
|
205
|
+
return list(spec.units[unit].gate.back_targets)
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def outcome_back_targets(spec: WorkflowSpec) -> list[str]:
|
|
209
|
+
"""Derived from `serves` links: units whose intermediate criteria serve a final criterion (OUT-B15, OUT-B16, OUT-B17)."""
|
|
210
|
+
if spec.outcome is None:
|
|
211
|
+
return []
|
|
212
|
+
finals = {c.id for c in spec.outcome.final}
|
|
213
|
+
out = []
|
|
214
|
+
for name in spec.order:
|
|
215
|
+
inter = spec.outcome.intermediate.get(name)
|
|
216
|
+
if inter and any(set(c.serves) & finals for c in inter.criteria):
|
|
217
|
+
out.append(name)
|
|
218
|
+
return out
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def successors(spec: WorkflowSpec, unit: str) -> SuccessorSet:
|
|
222
|
+
order = effective_order(spec)
|
|
223
|
+
step, _, _, human = node_names(unit)
|
|
224
|
+
s = SuccessorSet()
|
|
225
|
+
if block_of(spec, unit) is not None:
|
|
226
|
+
s.proceed = [done_node(unit)] # the join fires when every branch's `done` has (CMP-B4)
|
|
227
|
+
else:
|
|
228
|
+
s.proceed = [entry_node(spec, t) for t in proceed_targets(spec, unit)]
|
|
229
|
+
s.retry = [step]
|
|
230
|
+
s.back = [entry_node(spec, t) for t in back_targets(spec, unit)]
|
|
231
|
+
s.escalate = [human]
|
|
232
|
+
s.stop = [END]
|
|
233
|
+
own = block_of(spec, unit) or unit
|
|
234
|
+
before = [u for u in order[: order.index(unit)] if block_of(spec, u) != block_of(spec, unit) or
|
|
235
|
+
block_of(spec, u) is None]
|
|
236
|
+
s.rewind = list(dict.fromkeys(entry_node(spec, u) for u in before if u != own))
|
|
237
|
+
return s
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def human_targets(spec: WorkflowSpec, unit: str) -> list[str]:
|
|
241
|
+
s = successors(spec, unit)
|
|
242
|
+
extra: list[str] = [node_names(unit)[1]] # a usage-limit pause reruns the judge session the limit ended (DUR-B12)
|
|
243
|
+
if deadline_of(spec, unit) is not None: # an applied deadline re-enters the human node, or goes forward
|
|
244
|
+
extra += [node_names(unit)[3]] + ([n] if (n := deadline_node(spec, unit)) else [])
|
|
245
|
+
return list(dict.fromkeys(s.proceed + s.retry + s.back + s.rewind + s.stop + extra))
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def rearm_targets(spec: WorkflowSpec, unit: str) -> list[str]:
|
|
249
|
+
"""Entry nodes a re-arm can send `unit`'s gate to: the entry of arm `to` of every entry listing it (SWM-B7)."""
|
|
250
|
+
out: list[str] = []
|
|
251
|
+
for u in spec.units.values():
|
|
252
|
+
sw = u.switch
|
|
253
|
+
for r in (sw.rearm if sw is not None else ()):
|
|
254
|
+
entry = sw.arms.get(r.to) if sw is not None else None
|
|
255
|
+
if unit in r.units and entry and entry != FINALIZER and entry in spec.units:
|
|
256
|
+
out.append(entry_node(spec, entry))
|
|
257
|
+
return list(dict.fromkeys(out))
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def arm_units(spec: WorkflowSpec, entry: str) -> set[str]:
|
|
261
|
+
"""Units a pass can reach from an arm's entry, the entry included."""
|
|
262
|
+
seen: set[str] = set()
|
|
263
|
+
todo = [entry]
|
|
264
|
+
while todo:
|
|
265
|
+
u = todo.pop()
|
|
266
|
+
if u in seen or u == FINALIZER or u not in spec.units:
|
|
267
|
+
continue
|
|
268
|
+
seen.add(u)
|
|
269
|
+
todo.extend(proceed_targets(spec, u))
|
|
270
|
+
return seen
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def fallback_node(spec: WorkflowSpec, unit: str) -> str | None:
|
|
274
|
+
"""The node a gate's fallback target leads to (FLX-B9); the finalizer is reached through the outcome gate."""
|
|
275
|
+
fb = spec.units[unit].gate.fallback if unit in spec.units else None
|
|
276
|
+
return entry_node(spec, through_outcome(spec, fb)) if fb else None
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def deadline_of(spec: WorkflowSpec, unit: str) -> tuple[int, str] | None:
|
|
280
|
+
"""`(deadline_s, on_deadline)` of a wait or an ask that declares a deadline (FLX-B8)."""
|
|
281
|
+
u = spec.units.get(unit)
|
|
282
|
+
d = (u.ask or u.wait) if u is not None else None
|
|
283
|
+
return (int(d.deadline_s), str(d.on_deadline)) if d is not None and d.deadline_s else None
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def deadline_node(spec: WorkflowSpec, unit: str) -> str | None:
|
|
287
|
+
"""The forward unit's node when `on_deadline` names one; `escalate`, `stop` and `defaults` are words."""
|
|
288
|
+
d = deadline_of(spec, unit)
|
|
289
|
+
if d is None or d[1] in ("escalate", "stop", "defaults"):
|
|
290
|
+
return None
|
|
291
|
+
return entry_node(spec, through_outcome(spec, d[1]))
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def gate_targets(spec: WorkflowSpec, unit: str) -> list[str]:
|
|
295
|
+
s = successors(spec, unit)
|
|
296
|
+
fb = fallback_node(spec, unit)
|
|
297
|
+
return list(dict.fromkeys(s.proceed + s.retry + s.back + s.escalate + s.stop + rearm_targets(spec, unit)
|
|
298
|
+
+ ([fb] if fb else [])))
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
def reachable_units(spec: WorkflowSpec) -> set[str]:
|
|
302
|
+
order = effective_order(spec)
|
|
303
|
+
if not order:
|
|
304
|
+
return set()
|
|
305
|
+
seen: set[str] = set()
|
|
306
|
+
todo = [order[0]]
|
|
307
|
+
while todo:
|
|
308
|
+
u = todo.pop()
|
|
309
|
+
if u in seen or u == FINALIZER or u not in order:
|
|
310
|
+
continue
|
|
311
|
+
seen.add(u)
|
|
312
|
+
for t in list(proceed_targets(spec, u)): # entering a block reaches each of its branches
|
|
313
|
+
tu = spec.units.get(t)
|
|
314
|
+
todo.extend(tu.branches if tu is not None and tu.kind == "parallel" else
|
|
315
|
+
spec.units[b].branches if (b := block_of(spec, t)) else ())
|
|
316
|
+
fb = spec.units[u].gate.fallback if u in spec.units else None
|
|
317
|
+
dl = deadline_of(spec, u)
|
|
318
|
+
todo.extend(proceed_targets(spec, u) + back_targets(spec, u) + ([fb] if fb else [])
|
|
319
|
+
+ ([dl[1]] if dl and dl[1] not in ("escalate", "stop", "defaults") else []))
|
|
320
|
+
return seen
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def finalizer_reachable(spec: WorkflowSpec) -> bool:
|
|
324
|
+
return any(FINALIZER in proceed_targets(spec, u) for u in reachable_units(spec))
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"""Prompt lint (LIF-B7 to LIF-B16, LIF-AC6): model-free, text-style rules over templates, judge briefs and stances,
|
|
2
|
+
and the skills and agents a package ships. Part of `validate` (warnings) and shown by `audit` (PRA
|
|
3
|
+
`prompt-lint`). The name reader, :func:`names`, is the one the prompt audit and the tool-surface audit
|
|
4
|
+
reuse (PRA-AC3).
|
|
5
|
+
|
|
6
|
+
Rules and codes (LIF-B12): `lint-vague-word`, `lint-self-grading`, `lint-rule-branching`,
|
|
7
|
+
`lint-human-wait`, `lint-accepting-brief`, `lint-tool-name-foreign`, `lint-ref-missing`, `lint-oversized`, and
|
|
8
|
+
the one error, `lint-skill-undeclared` (LIF-B19): a step prompt names a package skill its step does not declare.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import contextlib
|
|
14
|
+
import re
|
|
15
|
+
from collections.abc import Iterator
|
|
16
|
+
from dataclasses import dataclass
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Literal
|
|
19
|
+
|
|
20
|
+
from tempergraph.contracts import TextRef, WorkflowSpec
|
|
21
|
+
from tempergraph.executors.capabilities import DECLARED
|
|
22
|
+
from tempergraph.model.text import TextUnreadable, load_text, split_judge_file
|
|
23
|
+
|
|
24
|
+
Role = Literal["step", "judge", "skill", "agent"]
|
|
25
|
+
|
|
26
|
+
TEMPLATE_LIMIT = 32_000
|
|
27
|
+
SKILL_LIMIT = 40_000
|
|
28
|
+
CELL_LIMIT = 2_000
|
|
29
|
+
|
|
30
|
+
VAGUE = ("as appropriate", "as needed", "if necessary", "where relevant", "and so on", "etc.", "appropriately",
|
|
31
|
+
"properly", "reasonable", "sufficiently", "adequate", "nice", "user-friendly", "robust", "high quality",
|
|
32
|
+
"high-quality", "as much as possible", "best possible")
|
|
33
|
+
SELF_GRADING = re.compile(r"\b(rate|grade|score|evaluate|assess|judge)\s+(your|its)\s+(own\s+)?(work|answer|output|"
|
|
34
|
+
r"result|response|quality)|\bself[- ]assess|\bhow confident are you|\bconfirm (that )?you "
|
|
35
|
+
r"(have|did|met)|\bdeclare (it|the task) (done|complete)", re.I)
|
|
36
|
+
BRANCH = re.compile(r"\bif\b[^.\n]{1,160}\b(otherwise|else)\b", re.I)
|
|
37
|
+
HUMAN_WAIT = re.compile(r"\b(ask|check with|confirm with|wait for|consult)\s+(the\s+)?(user|person|human|operator|"
|
|
38
|
+
r"reviewer|me|approval)\b|\bwait until (the )?(user|person)", re.I)
|
|
39
|
+
ACCEPTING = re.compile(r"\b(trust|accept|take)\s+(the\s+)?(step'?s|agent'?s|author'?s|worker'?s)\s+(word|claim|"
|
|
40
|
+
r"report|summary|statement)|\bassume (that )?(the step|it) (is|was|did) (correct|right|done)|"
|
|
41
|
+
r"\bif the (step|agent) says\b", re.I)
|
|
42
|
+
SKILL_REF = re.compile(r"(?:\bskill\s+`([A-Za-z0-9_.:-]+)`|(?<![\w/])/([a-z][a-z0-9-]{2,})(?:\b|$))")
|
|
43
|
+
AGENT_REF = re.compile(r"\b(?:sub)?agent\s+`([A-Za-z0-9_.-]+)`", re.I)
|
|
44
|
+
FILE_FOLDERS = ("prompts", "judges", "skills", "agents", "lessons")
|
|
45
|
+
FILE_REF = re.compile(r"`((?:" + "|".join(FILE_FOLDERS) + r")/[A-Za-z0-9_./-]+)`")
|
|
46
|
+
TICKED = re.compile(r"`([A-Za-z_][A-Za-z0-9_]*)`")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass(frozen=True)
|
|
50
|
+
class Names:
|
|
51
|
+
skills: tuple[str, ...]
|
|
52
|
+
agents: tuple[str, ...]
|
|
53
|
+
files: tuple[str, ...]
|
|
54
|
+
tools: tuple[str, ...] # backticked identifiers that are some executor's tool name
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class LintFinding:
|
|
59
|
+
code: str
|
|
60
|
+
unit: str | None
|
|
61
|
+
where: str # file path or `inline:<unit>`, with a line when known
|
|
62
|
+
message: str
|
|
63
|
+
severity: Literal["error", "warning"] = "warning"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _tool_names() -> dict[str, set[str]]:
|
|
67
|
+
"""Tool name -> executors whose tool map holds it."""
|
|
68
|
+
out: dict[str, set[str]] = {}
|
|
69
|
+
for name, caps in DECLARED.items():
|
|
70
|
+
for tools in caps.tool_map.values():
|
|
71
|
+
for t in tools:
|
|
72
|
+
if "{" not in t:
|
|
73
|
+
out.setdefault(t, set()).add(name)
|
|
74
|
+
return out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def names(text: str) -> Names:
|
|
78
|
+
"""Everything a model-facing text names: skills, agents, package files, tool names (PRA-B6)."""
|
|
79
|
+
tools = _tool_names()
|
|
80
|
+
skills = [a or b for a, b in SKILL_REF.findall(text)]
|
|
81
|
+
return Names(skills=tuple(dict.fromkeys(skills)), agents=tuple(dict.fromkeys(AGENT_REF.findall(text))),
|
|
82
|
+
files=tuple(dict.fromkeys(FILE_REF.findall(text))),
|
|
83
|
+
tools=tuple(dict.fromkeys(t for t in TICKED.findall(text) if t in tools)))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _line(text: str, pos: int) -> int:
|
|
87
|
+
return text.count("\n", 0, pos) + 1
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _texts(spec: WorkflowSpec) -> Iterator[tuple[str, Role, str, str]]:
|
|
91
|
+
"""(unit, role, where, text) for every template, stance and brief, then package skills and agents."""
|
|
92
|
+
for unit in spec.order:
|
|
93
|
+
u = spec.units.get(unit)
|
|
94
|
+
if u is None:
|
|
95
|
+
continue
|
|
96
|
+
if u.step is not None and u.step.prompt != "default":
|
|
97
|
+
src = u.step.prompt
|
|
98
|
+
where = src.path if isinstance(src, TextRef) else f"inline:{unit}"
|
|
99
|
+
with contextlib.suppress(TextUnreadable): # template-unreadable and PKG text-ref own this
|
|
100
|
+
yield unit, "step", where, load_text(spec, src)
|
|
101
|
+
j = u.gate.judge
|
|
102
|
+
if j is not None:
|
|
103
|
+
stance, brief = j.stance, j.brief
|
|
104
|
+
where = j.file or f"inline:{unit}:judge"
|
|
105
|
+
if j.file and spec.package_root is not None:
|
|
106
|
+
try:
|
|
107
|
+
stance, brief = split_judge_file(load_text(spec, TextRef(path=j.file)))
|
|
108
|
+
except TextUnreadable:
|
|
109
|
+
continue
|
|
110
|
+
yield unit, "judge", where, f"{stance}\n\n{brief}"
|
|
111
|
+
root = spec.package_root
|
|
112
|
+
if root is not None:
|
|
113
|
+
for p in sorted((root / "skills").glob("*/SKILL.md")):
|
|
114
|
+
yield None, "skill", p.relative_to(root).as_posix(), p.read_text(encoding="utf-8") # type: ignore[misc]
|
|
115
|
+
for p in sorted((root / "agents").glob("*.md")):
|
|
116
|
+
yield None, "agent", p.relative_to(root).as_posix(), p.read_text(encoding="utf-8") # type: ignore[misc]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _exists(root: Path | None, kind: str, name: str) -> bool:
|
|
120
|
+
if root is None:
|
|
121
|
+
return True # no package: nothing to resolve against (PRA resolves on the host)
|
|
122
|
+
if kind == "skill":
|
|
123
|
+
return (root / "skills" / name.split(":")[-1] / "SKILL.md").is_file()
|
|
124
|
+
if kind == "agent":
|
|
125
|
+
return (root / "agents" / f"{name}.md").is_file()
|
|
126
|
+
return (root / name).exists()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _declared_refs(root: Path | None) -> re.Pattern[str] | None:
|
|
130
|
+
"""A package path in backticks under a folder of the package's `step_files` (PKG-B13), which must resolve too."""
|
|
131
|
+
from tempergraph.package.manifest import declared_step_files
|
|
132
|
+
|
|
133
|
+
folders = sorted({p.split("/", 1)[0] for p in declared_step_files(root) if "/" in p} - set(FILE_FOLDERS))
|
|
134
|
+
folders = [f for f in folders if re.fullmatch(r"[A-Za-z0-9_.-]+", f) and "*" not in f]
|
|
135
|
+
return re.compile(r"`((?:" + "|".join(map(re.escape, folders)) + r")/[A-Za-z0-9_./-]+)`") if folders else None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def lint(spec: WorkflowSpec) -> list[LintFinding]:
|
|
139
|
+
out: list[LintFinding] = []
|
|
140
|
+
root = spec.package_root
|
|
141
|
+
tools = _tool_names()
|
|
142
|
+
seen: set[str] = set()
|
|
143
|
+
declared = _declared_refs(root)
|
|
144
|
+
for unit, role, where, text in _texts(spec):
|
|
145
|
+
key = f"{role}:{where}"
|
|
146
|
+
if key in seen:
|
|
147
|
+
continue # a file shared by several units is reported once
|
|
148
|
+
seen.add(key)
|
|
149
|
+
|
|
150
|
+
def add(code: str, pos: int | None, message: str, unit: str | None = unit, where: str = where,
|
|
151
|
+
text: str = text) -> None:
|
|
152
|
+
out.append(LintFinding(code, unit, f"{where}:{_line(text, pos)}" if pos is not None else where, message))
|
|
153
|
+
|
|
154
|
+
low = text.lower()
|
|
155
|
+
if role in ("step", "judge"):
|
|
156
|
+
for word in VAGUE:
|
|
157
|
+
at = low.find(word)
|
|
158
|
+
if at >= 0 and re.match(r"\W|$", low[at + len(word):at + len(word) + 1] or " "):
|
|
159
|
+
add("lint-vague-word", at, f"vague wording {word!r}: say what to do or what counts, observably")
|
|
160
|
+
if role == "step":
|
|
161
|
+
if m := SELF_GRADING.search(text):
|
|
162
|
+
add("lint-self-grading", m.start(), "the step is asked to grade its own work; the gate's check "
|
|
163
|
+
"and judge grade it")
|
|
164
|
+
branches = list(BRANCH.finditer(text))
|
|
165
|
+
if len(branches) >= 2:
|
|
166
|
+
add("lint-rule-branching", branches[0].start(), f"{len(branches)} if/otherwise rules: decisions "
|
|
167
|
+
"a function can make belong in a route or switch, not the prompt")
|
|
168
|
+
if m := HUMAN_WAIT.search(text):
|
|
169
|
+
add("lint-human-wait", m.start(), "a step runs unattended; a person is reached through the "
|
|
170
|
+
"gate's approval or a pause, never by asking from the step")
|
|
171
|
+
st = spec.units[unit].step if unit else None
|
|
172
|
+
executor = st.executor if st is not None else None
|
|
173
|
+
own = {t for ts in DECLARED.get(executor or spec.default_executor, DECLARED["claude"]).tool_map.values()
|
|
174
|
+
for t in ts}
|
|
175
|
+
declared_skills = {t.split(":")[-1] for t in ((st.tools or ()) if st is not None else ()) if t.startswith("skill:")}
|
|
176
|
+
for ref in names(text).skills:
|
|
177
|
+
if ref.split(":")[-1] not in declared_skills and root is not None and _exists(root, "skill", ref):
|
|
178
|
+
out.append(LintFinding("lint-skill-undeclared", unit, f"{where}:{_line(text, text.find(ref))}",
|
|
179
|
+
f"the prompt names skill {ref!r}, which the step does not declare as "
|
|
180
|
+
"`skill:`; an undeclared skill is denied, so the method would be lost "
|
|
181
|
+
"(LIF-B19)", "error"))
|
|
182
|
+
for t in names(text).tools:
|
|
183
|
+
if t not in own:
|
|
184
|
+
add("lint-tool-name-foreign", text.find(f"`{t}`"), f"`{t}` is a tool name of "
|
|
185
|
+
f"{', '.join(sorted(tools[t]))}, not of this step's executor; name the capability instead")
|
|
186
|
+
if role == "judge" and (m := ACCEPTING.search(text)):
|
|
187
|
+
add("lint-accepting-brief", m.start(), "the brief tells the judge to accept the step's word; the "
|
|
188
|
+
"judge reads the artifacts, or the criterion is marked `unverified_system`")
|
|
189
|
+
n = names(text)
|
|
190
|
+
files = (*n.files, *(m for m in (declared.findall(text) if declared else []) if m not in n.files))
|
|
191
|
+
for kind, refs in (("skill", n.skills), ("agent", n.agents), ("file", files)):
|
|
192
|
+
for ref in refs:
|
|
193
|
+
if not _exists(root, kind, ref):
|
|
194
|
+
add("lint-ref-missing", text.find(ref), f"{kind} {ref!r} is not in the package")
|
|
195
|
+
limit = TEMPLATE_LIMIT if role in ("step", "judge") else SKILL_LIMIT
|
|
196
|
+
if len(text) > limit:
|
|
197
|
+
add("lint-oversized", None, f"{len(text)} characters, over {limit}; split it into a core and "
|
|
198
|
+
"references read on demand")
|
|
199
|
+
for i, line in enumerate(text.splitlines(), 1):
|
|
200
|
+
if line.lstrip().startswith("|") and any(len(c) > CELL_LIMIT for c in line.split("|")):
|
|
201
|
+
out.append(LintFinding("lint-oversized", unit, f"{where}:{i}", f"a table cell over {CELL_LIMIT} "
|
|
202
|
+
"characters"))
|
|
203
|
+
return out
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Retirement of release 1's retry-count model list (LAD-B18). Pure, model-free.
|
|
2
|
+
|
|
3
|
+
A list of aliases in a step's `model` is refused from release 2. The transform here rewrites it by rule; what no
|
|
4
|
+
rule can decide becomes an owner item of the workflow upgrade (WUP-B15, WUP-B16).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from tempergraph.contracts import WorkflowSpec
|
|
13
|
+
from tempergraph.run.ladder import TIER_UP
|
|
14
|
+
|
|
15
|
+
TRANSFORM = "model_list_to_escalation"
|
|
16
|
+
OWNER_ITEM = "choose an `escalation.to`, or none"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def model_list_to_escalation(model: Sequence[str]) -> dict[str, Any]:
|
|
20
|
+
"""The release 2 form of a release 1 `model` list: `{model, escalation, owner_item}`."""
|
|
21
|
+
rungs = [str(m) for m in model]
|
|
22
|
+
if not rungs:
|
|
23
|
+
return {"model": None, "escalation": None, "owner_item": None}
|
|
24
|
+
first = rungs[0]
|
|
25
|
+
if len(rungs) == 1:
|
|
26
|
+
return {"model": first, "escalation": None, "owner_item": None}
|
|
27
|
+
if len(rungs) == 2 and TIER_UP.get(first) == rungs[1]:
|
|
28
|
+
return {"model": first, "escalation": {"to": rungs[1]}, "owner_item": None}
|
|
29
|
+
return {"model": first, "escalation": None, "owner_item": OWNER_ITEM}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def detect(spec: WorkflowSpec) -> dict[str, dict[str, Any]]:
|
|
33
|
+
"""Every place of a workflow that still holds a model list, with its rewrite: `units.<name>.model` and
|
|
34
|
+
`model_profile.<key>`."""
|
|
35
|
+
out: dict[str, dict[str, Any]] = {}
|
|
36
|
+
for name, u in spec.units.items():
|
|
37
|
+
if u.step is not None and not isinstance(u.step.model, str) and u.step.model is not None:
|
|
38
|
+
out[f"units.{name}.model"] = model_list_to_escalation(tuple(u.step.model))
|
|
39
|
+
for key, val in spec.model_profile.items():
|
|
40
|
+
if not isinstance(val, str) and val is not None:
|
|
41
|
+
out[f"model_profile.{key}"] = model_list_to_escalation(tuple(val))
|
|
42
|
+
return out
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def describe(got: dict[str, Any]) -> str:
|
|
46
|
+
"""The rewrite in one line, for the refusal's message."""
|
|
47
|
+
text = f"`model: {got['model']}`"
|
|
48
|
+
if got["escalation"]:
|
|
49
|
+
text += f" with `escalation: {{to: {got['escalation']['to']}}}`"
|
|
50
|
+
if got["owner_item"]:
|
|
51
|
+
text += f"; then {got['owner_item']}"
|
|
52
|
+
return text
|