flow-semantics 0.1.3__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.
@@ -0,0 +1,403 @@
1
+ """flowsemantics.configuration.portable - Portable IR and expression subset.
2
+
3
+ Layer: Composition
4
+ Module: flowsemantics.configuration.portable
5
+ Since: 0.4.0
6
+ Implements: SPEC.md section 14.2 (Portable IR), 5.1 (pure conditions)
7
+ Depends on: stdlib only
8
+ Used by: Flow.when_expr, FlowContract.to_ir/from_ir, conformance
9
+ See also: SPEC.md sections 14.2, 5.1
10
+
11
+ Notes:
12
+ - The portable expression subset is deliberately small and inspectable
13
+ (SPEC 14.2): named field access, six comparisons, and/or/not,
14
+ is-null/is-not-null, in/not-in. Nothing else.
15
+ - The IR MUST NOT carry host-language lambdas, serialized code, or
16
+ host types outside the subset.
17
+ - Schema: spec/ir.schema.json.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import datetime
23
+ import json
24
+ from collections.abc import Mapping
25
+ from dataclasses import dataclass
26
+ from typing import Any
27
+
28
+ from flowsemantics.errors import StructureError
29
+
30
+ # -- IR hardening limits (SPEC 9.2) ---------------------------------------------
31
+ #
32
+ # Documented in docs/threat-model.md. A depth greater than 100 MUST be
33
+ # rejected; 10 is the recommended minimum supported depth.
34
+ MAX_EXPR_DEPTH = 100
35
+ MAX_IR_BYTES = 1_000_000 # 1 MiB serialized IR
36
+ MAX_RULES = 10_000
37
+
38
+ # -- expression subset ---------------------------------------------------------
39
+
40
+
41
+ @dataclass(frozen=True)
42
+ class PExpr:
43
+ """A node in the portable expression subset (SPEC 14.2).
44
+
45
+ op is one of: field, const, eq, ne, lt, le, gt, ge, and, or, not,
46
+ is_null, is_not_null, in, not_in.
47
+ """
48
+
49
+ op: str
50
+ args: tuple[Any, ...] = ()
51
+ value: Any = None
52
+
53
+
54
+ OPS: frozenset[str] = frozenset(
55
+ {
56
+ "field",
57
+ "const",
58
+ "eq",
59
+ "ne",
60
+ "lt",
61
+ "le",
62
+ "gt",
63
+ "ge",
64
+ "and",
65
+ "or",
66
+ "not",
67
+ "is_null",
68
+ "is_not_null",
69
+ "in",
70
+ "not_in",
71
+ }
72
+ )
73
+
74
+
75
+ def pfield(name: str) -> PExpr:
76
+ """Named field access (read-only)."""
77
+ return PExpr(op="field", value=name)
78
+
79
+
80
+ def pconst(value: Any) -> PExpr:
81
+ """Literal constant."""
82
+ return PExpr(op="const", value=value)
83
+
84
+
85
+ def peq(a: PExpr, b: PExpr) -> PExpr:
86
+ """Equality comparison."""
87
+ return PExpr(op="eq", args=(a, b))
88
+
89
+
90
+ def pne(a: PExpr, b: PExpr) -> PExpr:
91
+ """Inequality comparison."""
92
+ return PExpr(op="ne", args=(a, b))
93
+
94
+
95
+ def plt(a: PExpr, b: PExpr) -> PExpr:
96
+ """Less-than comparison."""
97
+ return PExpr(op="lt", args=(a, b))
98
+
99
+
100
+ def ple(a: PExpr, b: PExpr) -> PExpr:
101
+ """Less-than-or-equal comparison."""
102
+ return PExpr(op="le", args=(a, b))
103
+
104
+
105
+ def pgt(a: PExpr, b: PExpr) -> PExpr:
106
+ """Greater-than comparison."""
107
+ return PExpr(op="gt", args=(a, b))
108
+
109
+
110
+ def pge(a: PExpr, b: PExpr) -> PExpr:
111
+ """Greater-than-or-equal comparison."""
112
+ return PExpr(op="ge", args=(a, b))
113
+
114
+
115
+ def pand(*args: PExpr) -> PExpr:
116
+ """Boolean AND over all arguments."""
117
+ return PExpr(op="and", args=tuple(args))
118
+
119
+
120
+ def por(*args: PExpr) -> PExpr:
121
+ """Boolean OR over all arguments."""
122
+ return PExpr(op="or", args=tuple(args))
123
+
124
+
125
+ def pnot(a: PExpr) -> PExpr:
126
+ """Boolean NOT."""
127
+ return PExpr(op="not", args=(a,))
128
+
129
+
130
+ def pis_null(a: PExpr) -> PExpr:
131
+ """Null check (is None)."""
132
+ return PExpr(op="is_null", args=(a,))
133
+
134
+
135
+ def pis_not_null(a: PExpr) -> PExpr:
136
+ """Non-null check."""
137
+ return PExpr(op="is_not_null", args=(a,))
138
+
139
+
140
+ def pin(a: PExpr, values: list[Any]) -> PExpr:
141
+ """Enum membership (in)."""
142
+ return PExpr(op="in", args=(a,), value=tuple(values))
143
+
144
+
145
+ def pnot_in(a: PExpr, values: list[Any]) -> PExpr:
146
+ """Enum non-membership (not in)."""
147
+ return PExpr(op="not_in", args=(a,), value=tuple(values))
148
+
149
+
150
+ def eval_expr(expr: PExpr, input: Any) -> Any:
151
+ """Evaluate a portable expression against the input (SPEC 14.2).
152
+
153
+ Field access requires the input to be a mapping; anything else
154
+ raises StructureError at evaluation time.
155
+ """
156
+ op = expr.op
157
+ if op == "field":
158
+ if not isinstance(input, Mapping):
159
+ raise StructureError("portable field access requires a mapping input")
160
+ return input.get(expr.value)
161
+ if op == "const":
162
+ return expr.value
163
+ if op == "and":
164
+ return all(bool(eval_expr(a, input)) for a in expr.args)
165
+ if op == "or":
166
+ return any(bool(eval_expr(a, input)) for a in expr.args)
167
+ if op == "not":
168
+ return not bool(eval_expr(expr.args[0], input))
169
+ if op == "is_null":
170
+ return eval_expr(expr.args[0], input) is None
171
+ if op == "is_not_null":
172
+ return eval_expr(expr.args[0], input) is not None
173
+ if op == "in":
174
+ return eval_expr(expr.args[0], input) in (expr.value or ())
175
+ if op == "not_in":
176
+ return eval_expr(expr.args[0], input) not in (expr.value or ())
177
+ # binary comparisons
178
+ left = eval_expr(expr.args[0], input)
179
+ right = eval_expr(expr.args[1], input)
180
+ if op == "eq":
181
+ return left == right
182
+ if op == "ne":
183
+ return left != right
184
+ if op == "lt":
185
+ return left < right
186
+ if op == "le":
187
+ return left <= right
188
+ if op == "gt":
189
+ return left > right
190
+ if op == "ge":
191
+ return left >= right
192
+ raise StructureError(f"unknown portable expression op: {op!r}")
193
+
194
+
195
+ def expr_to_dict(expr: PExpr) -> dict[str, Any]:
196
+ """Serialize a PExpr to a JSON-safe dict."""
197
+ if expr.op in ("field", "const"):
198
+ return {"op": expr.op, "value": expr.value}
199
+ if expr.op in ("in", "not_in"):
200
+ return {
201
+ "op": expr.op,
202
+ "args": [expr_to_dict(expr.args[0])],
203
+ "value": list(expr.value or ()),
204
+ }
205
+ if expr.op in ("and", "or"):
206
+ return {"op": expr.op, "args": [expr_to_dict(a) for a in expr.args]}
207
+ if expr.op in ("not", "is_null", "is_not_null"):
208
+ return {"op": expr.op, "args": [expr_to_dict(expr.args[0])]}
209
+ return {
210
+ "op": expr.op,
211
+ "args": [expr_to_dict(expr.args[0]), expr_to_dict(expr.args[1])],
212
+ }
213
+
214
+
215
+ def expr_from_dict(data: dict[str, Any], _depth: int = 0) -> PExpr:
216
+ """Deserialize a PExpr from its dict form.
217
+
218
+ Rejects nesting deeper than MAX_EXPR_DEPTH (SPEC 9.2).
219
+ """
220
+ if _depth > MAX_EXPR_DEPTH:
221
+ raise StructureError(
222
+ f"portable expression nesting exceeds maximum depth {MAX_EXPR_DEPTH} (SPEC 9.2)"
223
+ )
224
+ op = data["op"]
225
+ if op not in OPS:
226
+ raise StructureError(f"unknown portable expression op in IR: {op!r}")
227
+ if op in ("field", "const"):
228
+ return PExpr(op=op, value=data.get("value"))
229
+ if op in ("in", "not_in"):
230
+ args = [expr_from_dict(a, _depth + 1) for a in data.get("args", [])]
231
+ return PExpr(op=op, args=tuple(args), value=tuple(data.get("value", [])))
232
+ if op in ("and", "or"):
233
+ return PExpr(
234
+ op=op,
235
+ args=tuple(expr_from_dict(a, _depth + 1) for a in data["args"]),
236
+ )
237
+ if op in ("not", "is_null", "is_not_null"):
238
+ return PExpr(op=op, args=(expr_from_dict(data["args"][0], _depth + 1),))
239
+ return PExpr(
240
+ op=op,
241
+ args=(
242
+ expr_from_dict(data["args"][0], _depth + 1),
243
+ expr_from_dict(data["args"][1], _depth + 1),
244
+ ),
245
+ )
246
+
247
+
248
+ # -- IR types -------------------------------------------------------------------
249
+
250
+
251
+ @dataclass(frozen=True)
252
+ class PortableRule:
253
+ """One rule in the Portable IR (SPEC 14.2)."""
254
+
255
+ rule_id: str
256
+ kind: str # "when" | "when_not" | "then"
257
+ condition: PExpr | None = None
258
+ guard: PExpr | None = None
259
+ transform: PExpr | None = None
260
+ priority: int = 0
261
+ effective_from: str | None = None
262
+ effective_until: str | None = None
263
+ effects: tuple[dict[str, Any], ...] = ()
264
+
265
+
266
+ @dataclass(frozen=True)
267
+ class PortableFlow:
268
+ """Canonical Portable IR document (SPEC 14.2)."""
269
+
270
+ spec_version: str
271
+ flow_id: str
272
+ portability: str # "PORTABLE"
273
+ mode: str
274
+ rules: tuple[PortableRule, ...]
275
+ fallback: dict[str, Any] | None = None
276
+ contract_version: str = ""
277
+
278
+ def to_dict(self) -> dict[str, Any]:
279
+ """Serialize to a JSON-safe dict."""
280
+ return {
281
+ "spec_version": self.spec_version,
282
+ "flow_id": self.flow_id,
283
+ "portability": self.portability,
284
+ "mode": self.mode,
285
+ "rules": [
286
+ {
287
+ "rule_id": r.rule_id,
288
+ "kind": r.kind,
289
+ "condition": (expr_to_dict(r.condition) if r.condition else None),
290
+ "guard": expr_to_dict(r.guard) if r.guard else None,
291
+ "transform": (expr_to_dict(r.transform) if r.transform else None),
292
+ "priority": r.priority,
293
+ "effective_from": r.effective_from,
294
+ "effective_until": r.effective_until,
295
+ "effects": [dict(e) for e in r.effects],
296
+ }
297
+ for r in self.rules
298
+ ],
299
+ "fallback": self.fallback,
300
+ "contract_version": self.contract_version,
301
+ }
302
+
303
+ def to_json(self) -> str:
304
+ """Serialize to a canonical JSON string."""
305
+ return json.dumps(self.to_dict(), sort_keys=True)
306
+
307
+ @classmethod
308
+ def from_dict(cls, data: dict[str, Any]) -> PortableFlow:
309
+ """Deserialize from a dict.
310
+
311
+ Enforces SPEC 9.2 hardening: maximum rule count and duplicate
312
+ RuleId rejection at deserialization time.
313
+ """
314
+ if not isinstance(data, dict):
315
+ raise StructureError("portable IR must be a JSON object")
316
+ raw_rules = data.get("rules", [])
317
+ if not isinstance(raw_rules, list):
318
+ raise StructureError("portable IR 'rules' must be an array")
319
+ if len(raw_rules) > MAX_RULES:
320
+ raise StructureError(
321
+ f"portable IR rule count {len(raw_rules)} exceeds maximum {MAX_RULES} (SPEC 9.2)"
322
+ )
323
+ seen: set[str] = set()
324
+ for r in raw_rules:
325
+ if not isinstance(r, dict):
326
+ raise StructureError("portable IR rule entries must be objects")
327
+ rid = r.get("rule_id")
328
+ if not isinstance(rid, str) or not rid:
329
+ raise StructureError("portable IR rule_id must be a non-empty string")
330
+ if rid in seen:
331
+ raise StructureError(f"duplicate RuleId in portable IR: {rid!r} (SPEC 9.2)")
332
+ seen.add(rid)
333
+ rules = tuple(
334
+ PortableRule(
335
+ rule_id=r["rule_id"],
336
+ kind=r["kind"],
337
+ condition=(expr_from_dict(r["condition"]) if r.get("condition") else None),
338
+ guard=(expr_from_dict(r["guard"]) if r.get("guard") else None),
339
+ transform=(expr_from_dict(r["transform"]) if r.get("transform") else None),
340
+ priority=r.get("priority", 0),
341
+ effective_from=r.get("effective_from"),
342
+ effective_until=r.get("effective_until"),
343
+ effects=tuple(dict(e) for e in r.get("effects", [])),
344
+ )
345
+ for r in data.get("rules", [])
346
+ )
347
+ return cls(
348
+ spec_version=data["spec_version"],
349
+ flow_id=data["flow_id"],
350
+ portability=data["portability"],
351
+ mode=data["mode"],
352
+ rules=rules,
353
+ fallback=data.get("fallback"),
354
+ contract_version=data.get("contract_version", ""),
355
+ )
356
+
357
+ @classmethod
358
+ def from_json(cls, text: str) -> PortableFlow:
359
+ """Deserialize from a JSON string.
360
+
361
+ Rejects payloads larger than MAX_IR_BYTES (SPEC 9.2).
362
+ """
363
+ if len(text.encode("utf-8")) > MAX_IR_BYTES:
364
+ raise StructureError(
365
+ f"portable IR exceeds maximum size {MAX_IR_BYTES} bytes (SPEC 9.2)"
366
+ )
367
+ return cls.from_dict(json.loads(text))
368
+
369
+
370
+ def _parse_dt(value: str | None) -> datetime.datetime | None:
371
+ if value is None:
372
+ return None
373
+ return datetime.datetime.fromisoformat(value)
374
+
375
+
376
+ __all__: list[str] = [
377
+ "MAX_EXPR_DEPTH",
378
+ "MAX_IR_BYTES",
379
+ "MAX_RULES",
380
+ "OPS",
381
+ "PExpr",
382
+ "PortableFlow",
383
+ "PortableRule",
384
+ "_parse_dt",
385
+ "eval_expr",
386
+ "expr_from_dict",
387
+ "expr_to_dict",
388
+ "pand",
389
+ "pconst",
390
+ "peq",
391
+ "pfield",
392
+ "pge",
393
+ "pgt",
394
+ "pin",
395
+ "pis_not_null",
396
+ "pis_null",
397
+ "ple",
398
+ "plt",
399
+ "pne",
400
+ "pnot",
401
+ "pnot_in",
402
+ "por",
403
+ ]
@@ -0,0 +1,81 @@
1
+ """flowsemantics.configuration.rule - RuleId and Rule (SPEC.md sections 2.1, 10.1).
2
+
3
+ Layer: Composition
4
+ Module: flowsemantics.configuration.rule
5
+ Since: 0.1.0
6
+ Implements: SPEC.md section 10.1 (rule is a 4-tuple plus identity)
7
+ Depends on: stdlib only
8
+ Used by: Flow builder, FlowContract, conformance runner
9
+ See also: SPEC.md section 10
10
+
11
+ Notes:
12
+ - RuleId is readonly and has implicit string conversion via __str__.
13
+ - A Rule is immutable once registered: the builder stores it in a tuple
14
+ inside the compiled FlowContract.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import datetime
20
+ from collections.abc import Awaitable, Callable
21
+ from dataclasses import dataclass
22
+ from typing import Any, Literal
23
+
24
+ from flowsemantics.execution.outcome import Effect
25
+
26
+ RuleKind = Literal["when", "when_not", "then"]
27
+
28
+ ConditionFn = Callable[[Any], bool | Awaitable[bool]]
29
+ GuardFn = Callable[[Any], bool | Awaitable[bool]]
30
+ ActionFn = Callable[..., Any]
31
+
32
+
33
+ @dataclass(frozen=True)
34
+ class RuleId:
35
+ """Stable, readonly rule identity with implicit string conversion.
36
+
37
+ Feature 8 of the v5 baseline. The value is validated non-empty at
38
+ construction; compile() additionally enforces uniqueness (SPEC 4.3).
39
+ """
40
+
41
+ value: str
42
+
43
+ def __post_init__(self) -> None:
44
+ """Validate the RuleId value is non-empty."""
45
+ if not self.value:
46
+ raise ValueError("RuleId must be non-empty")
47
+
48
+ def __str__(self) -> str:
49
+ """Return the underlying string value (implicit string conversion)."""
50
+ return self.value
51
+
52
+
53
+ @dataclass(frozen=True)
54
+ class Rule:
55
+ """One rule in a flow: identity, kind, condition, guard, action.
56
+
57
+ kind is "when" (match on true), "when_not" (match on false), or
58
+ "then" (sequential stage; condition is None and action receives
59
+ (input, previous_output)).
60
+ """
61
+
62
+ id: RuleId
63
+ kind: RuleKind
64
+ condition: ConditionFn | None
65
+ guard: GuardFn | None
66
+ action: ActionFn
67
+ priority: int = 0
68
+ effective_from: datetime.datetime | None = None
69
+ effective_until: datetime.datetime | None = None
70
+ effects: tuple[Effect, ...] = ()
71
+
72
+
73
+ __all__: list[str] = [
74
+ "ActionFn",
75
+ "ConditionFn",
76
+ "Effect",
77
+ "GuardFn",
78
+ "Rule",
79
+ "RuleId",
80
+ "RuleKind",
81
+ ]
@@ -0,0 +1,109 @@
1
+ """flowsemantics.configuration.table - DecisionTable (SPEC.md section 10.8).
2
+
3
+ Layer: Composition
4
+ Module: flowsemantics.configuration.table
5
+ Since: 0.1.0
6
+ Implements: SPEC.md section 10.8 (column-based, DMN-aligned hit policies)
7
+ Depends on: flowsemantics.configuration.{flow,rule}, stdlib only
8
+ Used by: Flow.from_table, consumers authoring rules as tables
9
+ See also: SPEC.md section 10.8
10
+
11
+ Notes:
12
+ - A decision table compiles to the same rule list as the fluent API.
13
+ - Hit policies map to EvaluationMode: FIRST->FirstMatch,
14
+ COLLECT->AllMatch, PRIORITY->Priority, UNIQUE->FirstMatch plus a
15
+ compile-time exclusivity check where statically provable.
16
+ - For opaque callables, UNIQUE exclusivity cannot be proven; the table
17
+ records a validation warning rather than claiming a guarantee
18
+ (SPEC 10.8).
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from collections.abc import Sequence
24
+ from dataclasses import dataclass, field
25
+ from typing import Any
26
+
27
+ from flowsemantics.configuration.flow import EvaluationMode, Flow
28
+ from flowsemantics.configuration.rule import ActionFn, ConditionFn
29
+
30
+ HitPolicy = str # "FIRST" | "COLLECT" | "PRIORITY" | "UNIQUE"
31
+
32
+ _HIT_POLICY_TO_MODE: dict[str, EvaluationMode] = {
33
+ "FIRST": EvaluationMode.FIRST_MATCH,
34
+ "COLLECT": EvaluationMode.ALL_MATCH,
35
+ "PRIORITY": EvaluationMode.PRIORITY,
36
+ "UNIQUE": EvaluationMode.FIRST_MATCH,
37
+ }
38
+
39
+
40
+ @dataclass(frozen=True)
41
+ class DecisionTableRow:
42
+ """One row of a decision table.
43
+
44
+ Attributes:
45
+ id: Stable RuleId for the compiled rule.
46
+ conditions: Predicates that must ALL be true for the row to match.
47
+ action: The transformation executed on match.
48
+ priority: Priority for PRIORITY hit policy (higher first).
49
+ """
50
+
51
+ id: str
52
+ conditions: tuple[ConditionFn, ...]
53
+ action: ActionFn
54
+ priority: int = 0
55
+
56
+
57
+ @dataclass(frozen=True)
58
+ class DecisionTable:
59
+ """A column-based decision table that compiles to a rule list."""
60
+
61
+ rows: tuple[DecisionTableRow, ...]
62
+ hit_policy: HitPolicy = "FIRST"
63
+ input_fields: tuple[str, ...] = field(default_factory=tuple)
64
+ warnings: tuple[str, ...] = field(default_factory=tuple)
65
+
66
+ def __post_init__(self) -> None:
67
+ """Validate hit policy and row count at construction."""
68
+ if self.hit_policy not in _HIT_POLICY_TO_MODE:
69
+ raise ValueError(f"unknown hit policy: {self.hit_policy!r}")
70
+ if not self.rows:
71
+ raise ValueError("decision table must have at least one row")
72
+
73
+ @property
74
+ def evaluation_mode(self) -> EvaluationMode:
75
+ """The EvaluationMode this hit policy maps to (SPEC 10.8)."""
76
+ return _HIT_POLICY_TO_MODE[self.hit_policy]
77
+
78
+
79
+ def _all_conditions(conditions: Sequence[ConditionFn]) -> ConditionFn:
80
+ def _combined(input: Any) -> bool:
81
+ return all(condition(input) for condition in conditions)
82
+
83
+ return _combined
84
+
85
+
86
+ def table_to_flow(table: DecisionTable) -> Flow:
87
+ """Compile a DecisionTable into a Flow builder (SPEC 10.8).
88
+
89
+ The resulting flow is equivalent to one built with the fluent API:
90
+ each row becomes a when rule whose condition is the conjunction of
91
+ the row's column predicates.
92
+ """
93
+ flow = Flow().with_mode(table.evaluation_mode)
94
+ for row in table.rows:
95
+ flow.when(
96
+ _all_conditions(row.conditions),
97
+ then=row.action,
98
+ id=row.id,
99
+ priority=row.priority,
100
+ )
101
+ return flow
102
+
103
+
104
+ __all__: list[str] = [
105
+ "DecisionTable",
106
+ "DecisionTableRow",
107
+ "HitPolicy",
108
+ "table_to_flow",
109
+ ]
@@ -0,0 +1,54 @@
1
+ """flowsemantics.errors - Exception hierarchy for FlowSemantics.
2
+
3
+ Layer: Contracts
4
+ Module: flowsemantics.errors
5
+ Since: 0.1.0
6
+ Implements: SPEC.md section 5.2 naming (StructureError, PortabilityError,
7
+ EvaluationError, FinalizationBudgetExceeded)
8
+ Depends on: stdlib only
9
+ Used by: configuration, execution, finalization, portable
10
+ See also: SPEC.md sections 4.3, 10.9, 11.4, 16.7
11
+
12
+ Notes:
13
+ - All library-raised exceptions derive from FlowSemanticsError so callers
14
+ can distinguish library contract violations from application exceptions.
15
+ - These are NOT outcome exceptions. An exception raised inside a user
16
+ condition or action is an application exception and is handled by the
17
+ Section 11 catch rules, never by this hierarchy.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+
23
+ class FlowSemanticsError(Exception):
24
+ """Base class for every exception raised by the FlowSemantics library."""
25
+
26
+
27
+ class StructureError(FlowSemanticsError):
28
+ """Raised by compile() when the flow structure is invalid (SPEC 4.3)."""
29
+
30
+
31
+ class PortabilityError(FlowSemanticsError):
32
+ """Raised by export_portable() on a NATIVE contract (SPEC 4.4)."""
33
+
34
+
35
+ class EvaluationError(FlowSemanticsError):
36
+ """Raised for an evaluation-time failure not otherwise classified."""
37
+
38
+
39
+ class FinalizationBudgetExceeded(FlowSemanticsError): # noqa: N818 - name locked by SPEC.md section 5.2
40
+ """Recorded when cleanup exceeds its WithFinallyTimeout budget (SPEC 16.7)."""
41
+
42
+
43
+ class AsyncOnlyContractError(FlowSemanticsError):
44
+ """Raised when execute() is called on an async-only contract (SPEC 11.7)."""
45
+
46
+
47
+ __all__: list[str] = [
48
+ "AsyncOnlyContractError",
49
+ "EvaluationError",
50
+ "FinalizationBudgetExceeded",
51
+ "FlowSemanticsError",
52
+ "PortabilityError",
53
+ "StructureError",
54
+ ]
@@ -0,0 +1,55 @@
1
+ """flowsemantics.execution - Outcome model, context, clocks, executor.
2
+
3
+ Layer: Domain
4
+ Module: flowsemantics.execution
5
+ Since: 0.0.0
6
+ Implements: SPEC.md sections 3, 4.1.3, 6.2, 7
7
+ Depends on: flowsemantics.execution.{clock,context,outcome}
8
+ Used by: parent package; populated from Phase 1.0
9
+ See also: SPEC.md sections 3, 6, 7
10
+
11
+ Notes:
12
+ - __all__ grows as features are implemented. Currently exports the
13
+ canonical outcome types (SPEC.md section 3) and the clock/context
14
+ primitives (sections 4.1.3, 6.2).
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from flowsemantics.execution.clock import Clock, FakeClock, SystemClock
20
+ from flowsemantics.execution.context import FlowContext
21
+ from flowsemantics.execution.outcome import (
22
+ DecisionStatus,
23
+ Effect,
24
+ ExecutionStatus,
25
+ FinalizationInfo,
26
+ FlowOutcome,
27
+ InterruptionInfo,
28
+ RecoveryInfo,
29
+ )
30
+ from flowsemantics.execution.trace import (
31
+ EVENT_TYPES,
32
+ REASONS,
33
+ ExecutionTrace,
34
+ TraceEvent,
35
+ TraceRecorder,
36
+ )
37
+
38
+ __all__: list[str] = [
39
+ "EVENT_TYPES",
40
+ "REASONS",
41
+ "Clock",
42
+ "DecisionStatus",
43
+ "Effect",
44
+ "ExecutionStatus",
45
+ "ExecutionTrace",
46
+ "FakeClock",
47
+ "FinalizationInfo",
48
+ "FlowContext",
49
+ "FlowOutcome",
50
+ "InterruptionInfo",
51
+ "RecoveryInfo",
52
+ "SystemClock",
53
+ "TraceEvent",
54
+ "TraceRecorder",
55
+ ]