function-sequence 0.2.0__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.
- function_sequence/__init__.py +26 -0
- function_sequence/__main__.py +3 -0
- function_sequence/_budget.py +66 -0
- function_sequence/_validation.py +125 -0
- function_sequence/application.py +33 -0
- function_sequence/cli.py +146 -0
- function_sequence/control.py +31 -0
- function_sequence/definitions.py +191 -0
- function_sequence/errors.py +58 -0
- function_sequence/expressions.py +114 -0
- function_sequence/operations.py +191 -0
- function_sequence/pipeline.py +279 -0
- function_sequence/py.typed +0 -0
- function_sequence/runtime.py +302 -0
- function_sequence/storage.py +164 -0
- function_sequence/terminal.py +193 -0
- function_sequence/values.py +77 -0
- function_sequence/workflow.py +135 -0
- function_sequence/workflow_cli.py +108 -0
- function_sequence-0.2.0.dist-info/METADATA +101 -0
- function_sequence-0.2.0.dist-info/RECORD +24 -0
- function_sequence-0.2.0.dist-info/WHEEL +4 -0
- function_sequence-0.2.0.dist-info/entry_points.txt +3 -0
- function_sequence-0.2.0.dist-info/licenses/LICENSE.md +22 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"""Bounded passive JSON values; no object reconstruction or implicit coercion."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import math
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .errors import InvalidValueError
|
|
8
|
+
|
|
9
|
+
MAX_BYTES = 4 * 1024 * 1024
|
|
10
|
+
MAX_DEPTH = 64
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def copy_json(value: Any, depth: int = 0, *, max_depth: int = MAX_DEPTH, portable: bool = False) -> Any:
|
|
14
|
+
"""Copy exact JSON types, rejecting custom objects and excessive nesting."""
|
|
15
|
+
if depth > max_depth:
|
|
16
|
+
raise InvalidValueError("JSON nesting exceeds the supported limit")
|
|
17
|
+
kind = type(value)
|
|
18
|
+
if value is None or kind in (bool, int):
|
|
19
|
+
if portable and kind is int and abs(value) > 2**53 - 1:
|
|
20
|
+
raise InvalidValueError("Integer exceeds the portable exact range")
|
|
21
|
+
return value
|
|
22
|
+
if kind is str:
|
|
23
|
+
try:
|
|
24
|
+
value.encode("utf-8")
|
|
25
|
+
except UnicodeError:
|
|
26
|
+
raise InvalidValueError("JSON text must be valid Unicode") from None
|
|
27
|
+
return value
|
|
28
|
+
if kind is float and math.isfinite(value):
|
|
29
|
+
return value
|
|
30
|
+
if kind is list:
|
|
31
|
+
return [copy_json(item, depth + 1, max_depth=max_depth, portable=portable) for item in value]
|
|
32
|
+
if kind is dict:
|
|
33
|
+
if any(type(key) is not str for key in value):
|
|
34
|
+
raise InvalidValueError("JSON object keys must be strings")
|
|
35
|
+
return {copy_json(key, depth + 1, max_depth=max_depth, portable=portable): copy_json(item, depth + 1, max_depth=max_depth, portable=portable)
|
|
36
|
+
for key, item in value.items()}
|
|
37
|
+
raise InvalidValueError("Expected strict JSON data")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def encode_json(value: Any, *, max_bytes: int = MAX_BYTES, max_depth: int = MAX_DEPTH, portable: bool = False) -> bytes:
|
|
41
|
+
copied = copy_json(value, max_depth=max_depth, portable=portable)
|
|
42
|
+
try:
|
|
43
|
+
payload = json.dumps(copied, ensure_ascii=False, allow_nan=False,
|
|
44
|
+
sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
45
|
+
except (ValueError, UnicodeError, RecursionError):
|
|
46
|
+
raise InvalidValueError("JSON value cannot be encoded") from None
|
|
47
|
+
if len(payload) > max_bytes:
|
|
48
|
+
raise InvalidValueError("JSON document exceeds the supported size")
|
|
49
|
+
return payload
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def decode_json(payload: bytes, *, max_bytes: int = MAX_BYTES, max_depth: int = MAX_DEPTH, portable: bool = False) -> Any:
|
|
53
|
+
if len(payload) > max_bytes:
|
|
54
|
+
raise InvalidValueError("JSON document exceeds the supported size")
|
|
55
|
+
|
|
56
|
+
def pairs(items):
|
|
57
|
+
result = {}
|
|
58
|
+
for key, value in items:
|
|
59
|
+
if key in result:
|
|
60
|
+
raise InvalidValueError("Duplicate JSON object key")
|
|
61
|
+
result[key] = value
|
|
62
|
+
return result
|
|
63
|
+
|
|
64
|
+
def constant(_value):
|
|
65
|
+
raise InvalidValueError("Non-finite JSON number")
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
value = json.loads(payload.decode("utf-8"), object_pairs_hook=pairs,
|
|
69
|
+
parse_constant=constant)
|
|
70
|
+
# Also rejects floats that overflow to infinity, and unpaired surrogates.
|
|
71
|
+
return copy_json(value, max_depth=max_depth, portable=portable)
|
|
72
|
+
except json.JSONDecodeError as error:
|
|
73
|
+
invalid = InvalidValueError("Invalid bounded JSON document")
|
|
74
|
+
invalid.lineno, invalid.colno = error.lineno, error.colno
|
|
75
|
+
raise invalid from None
|
|
76
|
+
except (UnicodeError, ValueError, RecursionError):
|
|
77
|
+
raise InvalidValueError("Invalid bounded JSON document") from None
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Strict schema-1 JSON/TOML without imports, evaluation or provider activation."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import tomllib
|
|
6
|
+
|
|
7
|
+
from .pipeline import Pipeline
|
|
8
|
+
from .expressions import Input, Ref
|
|
9
|
+
from .pipeline import Step
|
|
10
|
+
from .errors import PipelineError
|
|
11
|
+
from .expressions import MAX_BYTES, MAX_DEPTH, copy_json
|
|
12
|
+
from .values import decode_json as _decode_json
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DocumentError(ValueError):
|
|
16
|
+
"""A source-labelled passive document error."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _error(source, location, message):
|
|
20
|
+
return DocumentError(f"{source}:{location}: {message}")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def decode_json(data: str | bytes, *, source="<memory>"):
|
|
24
|
+
"""Decode through the shared strict parser and retain source locations."""
|
|
25
|
+
try:
|
|
26
|
+
return _decode_json(_text(data).encode("utf-8"), max_bytes=MAX_BYTES, max_depth=MAX_DEPTH)
|
|
27
|
+
except (ValueError, TypeError, UnicodeError, RecursionError) as error:
|
|
28
|
+
location = f"{error.lineno}:{error.colno}" if hasattr(error, "lineno") else "$"
|
|
29
|
+
raise _error(source, location, str(error)) from error
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _text(data):
|
|
33
|
+
if type(data) not in (str, bytes):
|
|
34
|
+
raise ValueError("Expected UTF-8 text or bytes")
|
|
35
|
+
if len(data) > MAX_BYTES:
|
|
36
|
+
raise ValueError(f"Document exceeds {MAX_BYTES} bytes")
|
|
37
|
+
if type(data) is bytes:
|
|
38
|
+
data = data.decode("utf-8")
|
|
39
|
+
if len(data.encode("utf-8")) > MAX_BYTES:
|
|
40
|
+
raise ValueError(f"Document exceeds {MAX_BYTES} bytes")
|
|
41
|
+
return data
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _object(value, required, optional, source, location):
|
|
45
|
+
if type(value) is not dict or not required <= value.keys() or value.keys() - required - optional:
|
|
46
|
+
raise _error(source, location, f"Expected object with keys {sorted(required)}, optional {sorted(optional)}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _expression(value, source, location, depth=0):
|
|
50
|
+
if depth > MAX_DEPTH:
|
|
51
|
+
raise _error(source, location, "Expression nesting limit exceeded")
|
|
52
|
+
if type(value) is not dict or len(value) != 1:
|
|
53
|
+
raise _error(source, location, "Expression requires exactly one tag")
|
|
54
|
+
tag, payload = next(iter(value.items()))
|
|
55
|
+
try:
|
|
56
|
+
if tag == "value":
|
|
57
|
+
return copy_json(payload)
|
|
58
|
+
if tag in ("input", "ref"):
|
|
59
|
+
key = "name" if tag == "input" else "step"
|
|
60
|
+
_object(payload, {key}, {"path"}, source, location)
|
|
61
|
+
path = payload.get("path", [])
|
|
62
|
+
if type(path) is not list:
|
|
63
|
+
raise ValueError("Reference path must be an array")
|
|
64
|
+
return (Input if tag == "input" else Ref)(payload[key], tuple(path))
|
|
65
|
+
if tag == "object" and type(payload) is dict:
|
|
66
|
+
return {key: _expression(item, source, f"{location}.{key}", depth + 1) for key, item in payload.items()}
|
|
67
|
+
if tag == "array" and type(payload) is list:
|
|
68
|
+
return [_expression(item, source, f"{location}[{index}]", depth + 1) for index, item in enumerate(payload)]
|
|
69
|
+
raise ValueError(f"Unsupported expression tag or payload: {tag!r}")
|
|
70
|
+
except PipelineError as error:
|
|
71
|
+
raise _error(source, location, str(error)) from error
|
|
72
|
+
except (TypeError, ValueError) as error:
|
|
73
|
+
if isinstance(error, DocumentError):
|
|
74
|
+
raise
|
|
75
|
+
raise _error(source, location, str(error)) from error
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@dataclass(frozen=True)
|
|
79
|
+
class Workflow:
|
|
80
|
+
definition: Pipeline
|
|
81
|
+
source: str
|
|
82
|
+
|
|
83
|
+
def inspect(self):
|
|
84
|
+
return self.definition.manifest
|
|
85
|
+
|
|
86
|
+
def bind(self, resolver, *, resolver_version):
|
|
87
|
+
try:
|
|
88
|
+
return self.definition.bind(resolver, resolver_version=resolver_version)
|
|
89
|
+
except PipelineError as error:
|
|
90
|
+
raise _error(self.source, "$.steps", str(error)) from error
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def loads(data: str | bytes, *, format="json", source="<memory>") -> Workflow:
|
|
94
|
+
try:
|
|
95
|
+
if format == "json":
|
|
96
|
+
document = decode_json(data, source=source)
|
|
97
|
+
elif format == "toml":
|
|
98
|
+
document = copy_json(tomllib.loads(_text(data)))
|
|
99
|
+
else:
|
|
100
|
+
raise _error(source, "$", "Format must be json or toml")
|
|
101
|
+
_object(document, {"schema", "name", "version", "steps", "outputs"}, set(), source, "$")
|
|
102
|
+
if type(document["schema"]) is not int or document["schema"] not in (1, 2):
|
|
103
|
+
raise _error(source, "$.schema", "Only workflow schemas 1 and 2 are supported")
|
|
104
|
+
if type(document["steps"]) is not list:
|
|
105
|
+
raise _error(source, "$.steps", "Steps must be an array")
|
|
106
|
+
steps = []
|
|
107
|
+
for index, item in enumerate(document["steps"]):
|
|
108
|
+
location = f"$.steps[{index}]"
|
|
109
|
+
operation_key = "operation" if document["schema"] == 2 else "capability"
|
|
110
|
+
_object(item, {"id", operation_key, "arguments"}, set(), source, location)
|
|
111
|
+
arguments = _expression(item["arguments"], source, location + ".arguments")
|
|
112
|
+
try:
|
|
113
|
+
step = Step(item["id"], item[operation_key], arguments)
|
|
114
|
+
# Validate references/duplicates at their source step before building the final definition.
|
|
115
|
+
Pipeline(document["name"], version=document["version"], steps=(*steps, step), outputs={})
|
|
116
|
+
except PipelineError as error:
|
|
117
|
+
raise _error(source, location, str(error)) from error
|
|
118
|
+
steps.append(step)
|
|
119
|
+
outputs = _expression(document["outputs"], source, "$.outputs")
|
|
120
|
+
return Workflow(Pipeline(document["name"], version=document["version"], steps=tuple(steps), outputs=outputs), source)
|
|
121
|
+
except DocumentError:
|
|
122
|
+
raise
|
|
123
|
+
except (ValueError, TypeError, UnicodeError, RecursionError) as error:
|
|
124
|
+
raise _error(source, "$", str(error)) from error
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def load(path: str | Path) -> Workflow:
|
|
128
|
+
path = Path(path)
|
|
129
|
+
try:
|
|
130
|
+
with path.open("rb") as stream:
|
|
131
|
+
data = stream.read(MAX_BYTES + 1)
|
|
132
|
+
except OSError as error:
|
|
133
|
+
raise _error(str(path), "$", str(error)) from error
|
|
134
|
+
format = path.suffix.removeprefix(".").lower()
|
|
135
|
+
return loads(data, format=format, source=str(path))
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Explicit trusted resolver selection and optional Expose Interface presentation."""
|
|
2
|
+
|
|
3
|
+
import contextlib
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from expose_interface import Interface, UsageError, option
|
|
8
|
+
from .expressions import MAX_BYTES, canonical
|
|
9
|
+
from .operations import NativeResolver, Resolver, schema_json as _schema_json
|
|
10
|
+
from .cli import _module_path
|
|
11
|
+
from importlib import import_module
|
|
12
|
+
import re
|
|
13
|
+
|
|
14
|
+
from .application import execute
|
|
15
|
+
from .workflow import decode_json, load
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def selected_resolver(target, names, version):
|
|
19
|
+
"""Import only the resolver object explicitly chosen by the trusted host."""
|
|
20
|
+
module, separator, attribute = target.partition(":")
|
|
21
|
+
if not separator or not re.fullmatch(r"[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*", module) or not attribute.isidentifier():
|
|
22
|
+
raise ValueError("Resolver must be a trusted module:attribute")
|
|
23
|
+
with _module_path():
|
|
24
|
+
resolver = getattr(import_module(module), attribute)
|
|
25
|
+
if not isinstance(resolver, Resolver):
|
|
26
|
+
raise TypeError("The selected attribute must implement operation resolution")
|
|
27
|
+
return NativeResolver({name: resolver.resolve(name) for name in dict.fromkeys(names)}, version=version)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _inputs(path):
|
|
31
|
+
with Path(path).open("rb") as stream:
|
|
32
|
+
value = decode_json(stream.read(MAX_BYTES + 1), source=path)
|
|
33
|
+
if type(value) is not dict or set(value) != {"schema", "inputs"} or type(value["schema"]) is not int or value["schema"] != 1 or type(value["inputs"]) is not dict:
|
|
34
|
+
raise ValueError("Inputs require {schema: 1, inputs: {...}}")
|
|
35
|
+
return value["inputs"]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _selection(function):
|
|
39
|
+
function = option("--resolver", required=True)(function)
|
|
40
|
+
function = option("--select", dest="select", multiple=True, required=True)(function)
|
|
41
|
+
return option("--resolver-version", required=True)(function)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def build_interface(*, select_resolver=selected_resolver, name="workflow"):
|
|
45
|
+
app = Interface(name, description="Inspect and execute explicit workflow documents.")
|
|
46
|
+
|
|
47
|
+
@app.command(name="inspect")
|
|
48
|
+
def inspect_document(path: str):
|
|
49
|
+
"""Inspect a passive document without importing any resolver."""
|
|
50
|
+
return {"schema": 1, "status": "inspected", "workflow": load(path).inspect()}
|
|
51
|
+
|
|
52
|
+
@app.command(name="list")
|
|
53
|
+
@_selection
|
|
54
|
+
def list_capabilities(*, resolver: str, select: list[str], resolver_version: str):
|
|
55
|
+
"""List only explicitly selected operations from a trusted resolver."""
|
|
56
|
+
resolver = select_resolver(resolver, select, resolver_version)
|
|
57
|
+
return {"schema": 1, "status": "listed", "resolver_version": resolver_version,
|
|
58
|
+
"operations": [{"name": name, "input": _schema_json(resolver.describe(name).input_schema),
|
|
59
|
+
"output": _schema_json(resolver.describe(name).output_schema)} for name in sorted(set(select))]}
|
|
60
|
+
|
|
61
|
+
@app.command(name="run")
|
|
62
|
+
@_selection
|
|
63
|
+
async def run_document(path: str, *, inputs: str, resolver: str, select: list[str],
|
|
64
|
+
resolver_version: str, checkpoint: str | None = None, pace: str = "auto"):
|
|
65
|
+
"""Execute a workflow; an explicit new checkpoint enables durable progress."""
|
|
66
|
+
workflow = load(path)
|
|
67
|
+
values = _inputs(inputs)
|
|
68
|
+
return await execute(workflow, select_resolver(resolver, select, resolver_version), resolver_version=resolver_version,
|
|
69
|
+
inputs=values, checkpoint=checkpoint, pace=pace)
|
|
70
|
+
|
|
71
|
+
@app.command(name="resume")
|
|
72
|
+
@_selection
|
|
73
|
+
async def resume_document(path: str, *, inputs: str, resolver: str, select: list[str],
|
|
74
|
+
resolver_version: str, checkpoint: str, pace: str = "auto",
|
|
75
|
+
retry: bool = False, restart: bool = False):
|
|
76
|
+
"""Resume existing progress; retry/restart are explicit recovery decisions."""
|
|
77
|
+
workflow = load(path)
|
|
78
|
+
values = _inputs(inputs)
|
|
79
|
+
return await execute(workflow, select_resolver(resolver, select, resolver_version), resolver_version=resolver_version,
|
|
80
|
+
inputs=values, checkpoint=checkpoint, resume=True, pace=pace, retry=retry, restart=restart)
|
|
81
|
+
|
|
82
|
+
@app.command(name="terminal")
|
|
83
|
+
@_selection
|
|
84
|
+
async def terminal_document(path: str, *, inputs: str, resolver: str, select: list[str],
|
|
85
|
+
resolver_version: str, checkpoint: str):
|
|
86
|
+
"""Open the optional Carets frontend on a supported POSIX terminal."""
|
|
87
|
+
from .terminal import run_terminal
|
|
88
|
+
|
|
89
|
+
workflow = load(path)
|
|
90
|
+
values = _inputs(inputs)
|
|
91
|
+
return await run_terminal(workflow, select_resolver(resolver, select, resolver_version), resolver_version=resolver_version,
|
|
92
|
+
inputs=values, checkpoint=checkpoint)
|
|
93
|
+
|
|
94
|
+
return app
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def main(argv=None, *, select_resolver=selected_resolver, name="workflow"):
|
|
98
|
+
try:
|
|
99
|
+
with contextlib.redirect_stdout(sys.stderr):
|
|
100
|
+
result = build_interface(select_resolver=select_resolver, name=name).invoke(argv)
|
|
101
|
+
if result is not None:
|
|
102
|
+
sys.stdout.buffer.write(canonical(result) + b"\n")
|
|
103
|
+
sys.stdout.buffer.flush()
|
|
104
|
+
except Exception as error:
|
|
105
|
+
record = {"schema": 1, "status": "error", "error": type(error).__name__, "message": str(error)}
|
|
106
|
+
sys.stderr.buffer.write(b"\n" + canonical(record) + b"\n")
|
|
107
|
+
sys.stderr.buffer.flush()
|
|
108
|
+
raise SystemExit(2 if isinstance(error, UsageError) else 1) from None
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: function-sequence
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Explicit computational composition, passive workflows and durable execution.
|
|
5
|
+
Author: ellainng
|
|
6
|
+
Author-email: ellainng <299958882+ellainng@users.noreply.github.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE.md
|
|
9
|
+
Requires-Dist: expose-interface>=0.1.0,<0.2.0 ; extra == 'cli'
|
|
10
|
+
Requires-Dist: carets>=0.2.0,<0.3.0 ; python_full_version >= '3.14' and extra == 'terminal'
|
|
11
|
+
Requires-Dist: expose-interface>=0.1.0,<0.2.0 ; extra == 'terminal'
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Project-URL: Repository, https://github.com/wispsy/function-sequence
|
|
14
|
+
Project-URL: Issues, https://github.com/wispsy/function-sequence/issues
|
|
15
|
+
Provides-Extra: cli
|
|
16
|
+
Provides-Extra: terminal
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Function Sequence
|
|
20
|
+
|
|
21
|
+
Define, bind and execute computational compositions independently of capability discovery. Native sequences, explicit pipelines and passive JSON/TOML workflows share one sequential lifecycle with cooperative pause, asynchronous execution and durable recovery.
|
|
22
|
+
|
|
23
|
+
Python 3.11+; no base runtime dependencies. The distribution and command are `function-sequence`; Python imports use `function_sequence`.
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
python -m pip install function-sequence==0.2.0
|
|
27
|
+
python -m pip install "function-sequence[cli]==0.2.0"
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Compose ordinary functions
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from function_sequence import Input, NativeResolver, Pipeline, Ref, Step
|
|
34
|
+
|
|
35
|
+
def normalize(text: str) -> str:
|
|
36
|
+
return " ".join(text.lower().split())
|
|
37
|
+
|
|
38
|
+
resolver = NativeResolver({"text.normalize": normalize}, version="text-v1")
|
|
39
|
+
definition = Pipeline("text.process", version="1", steps=(
|
|
40
|
+
Step("clean", "text.normalize", {"text": Input("text")}),
|
|
41
|
+
), outputs={"text": Ref("clean")})
|
|
42
|
+
bound = definition.bind(resolver, resolver_version="text-v1")
|
|
43
|
+
assert bound.run({"text": " Hello WORLD "}).outputs == {"text": "hello world"}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Definitions snapshot nested mappings. Inputs and earlier results use explicit paths; scalar values are not automatically wrapped or coerced. Binding checks selected operations and known argument shapes. Run preflight checks known inputs before effects; producer-dependent values are checked before their consumer starts. Each ordinary bound invocation has fresh progress and copied results.
|
|
47
|
+
|
|
48
|
+
`NativeResolver` supports ordinary functions and explicit `Operation` contracts. It checks call signatures and its supported scalar/container annotation schemas. Supply explicit contracts where interoperability requires them. Hidden Moves supplies an optional selected-catalog resolver and typed model conversion; Function Sequence never discovers or imports providers itself.
|
|
49
|
+
|
|
50
|
+
A bound composition can become a native operation through `bound.as_operation(input_schema=..., output_schema=...)`, then participate in another composition. All nesting uses finite shared execution limits. Applications can tighten local limits without expanding enclosing limits.
|
|
51
|
+
|
|
52
|
+
## Pause and recover
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from function_sequence import Script
|
|
56
|
+
|
|
57
|
+
def collect():
|
|
58
|
+
return {"text": "hello"}
|
|
59
|
+
|
|
60
|
+
def display(text):
|
|
61
|
+
return {"displayed": text}
|
|
62
|
+
|
|
63
|
+
script = Script("greeting", version="1")
|
|
64
|
+
collected = script.add_function(collect)
|
|
65
|
+
script.add_function(display, collected["text"])
|
|
66
|
+
first = script.run(checkpoint="greeting.progress.json", pace="function")
|
|
67
|
+
assert first.status == "paused"
|
|
68
|
+
complete = script.run(checkpoint="greeting.progress.json")
|
|
69
|
+
assert complete.results["display"] == {"displayed": "hello"}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`Script` retains explicitly selected progress; `arun()` awaits owned mixed steps sequentially. `bound.compile(inputs, asynchronous=True)` returns the same Script lifecycle for a pipeline. Controls, observers, pacing, checkpoint ownership and explicit recovery belong to that common engine. Applications own their event loops, resources, concurrency and authorization.
|
|
73
|
+
|
|
74
|
+
Completed work is not replayed by ordinary resume. A crash, exception, cancellation or result-write failure can leave an uncertain external effect; inspect it before explicitly choosing retry or restart. No automatic retry, rollback or exactly-once guarantee is provided. Nested composites initially have one parent recovery boundary, so parent retry can repeat inner effects.
|
|
75
|
+
|
|
76
|
+
## Passive documents and hosts
|
|
77
|
+
|
|
78
|
+
The [workflow guide](docs/workflows.md) covers schema-2 JSON/TOML documents, explicit resolvers, native command hosts and the optional Carets frontend. Valuable schema-1 documents are decoded explicitly as data. Parsing and inspection do not discover or invoke implementations.
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
function-sequence workflow inspect examples/text.json
|
|
82
|
+
function-sequence workflow run examples/text.json --inputs inputs.json --resolver examples.text_operations:resolver --select text.normalize --select text.report --resolver-version text-v1
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Install `[cli]` for workflow presentation and `[terminal]` on Python 3.14+ for Carets. The base native Script commands remain available without either profile. Imports do not start threads, install signal handlers, open terminals or create progress files.
|
|
86
|
+
|
|
87
|
+
## Contracts and verification
|
|
88
|
+
|
|
89
|
+
[Versioned semantics](specification/semantics.md) and local JSON Schemas describe operation contracts, expressions, workflows, native sequence exports and execution records. Resource limits, selection authority and completed-prefix/recovery rules also require semantic checks. Python fingerprint encoding is explicit; cross-runtime fingerprint and execution conformance remain a later track.
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
uv run --python 3.11 --locked python -m unittest discover -s tests -v
|
|
93
|
+
uv run --python 3.14 --locked --extra terminal python -m unittest discover -s terminal_tests -v
|
|
94
|
+
uv run --python 3.11 --locked --group spec python scripts/check_specification.py
|
|
95
|
+
uv build --out-dir dist
|
|
96
|
+
uv run --python 3.11 --locked python scripts/check_distribution.py dist
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
CI verifies base Linux/macOS/Windows behavior, optional workflow/terminal hosts, local schema conformance and isolated installed artifacts. The base wheel has no mandatory runtime dependencies. Schema qualification uses a development-only validator. See [native sequence details](docs/sequences.md), [storage](docs/storage.md), [releasing](docs/releasing.md) and [source provenance](docs/provenance.md).
|
|
100
|
+
|
|
101
|
+
Version 0.2.0 consolidates the useful sequence, pipeline and workflow implementations. No `func_seq`, `moveset` or `scriptty` compatibility import/distribution is provided. Hypnosis adopts the new foundation and Hidden Moves integration; other consumer adoption and native JavaScript execution remain separate work.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function_sequence/__init__.py,sha256=iqlUnP3VIrgy26po_YewwXaohIM-vLo42W_z_BtF5uE,1326
|
|
2
|
+
function_sequence/__main__.py,sha256=k1ocEWawweo1qCJWNFAAvyxz3tcY13dzvCenHszij30,48
|
|
3
|
+
function_sequence/_budget.py,sha256=2Lne4SgzXgMl5y63rEYlfqS21d7qT0Qf6xEJy4c18Rw,2309
|
|
4
|
+
function_sequence/_validation.py,sha256=-5WsHqbE6_aYGdt3LLysRQeUePtM8Wov4D9FmGPzbHc,5928
|
|
5
|
+
function_sequence/application.py,sha256=737DhRJepB1DramHLVaRmsMTSWx_5m7U4jXUhleoKpU,1989
|
|
6
|
+
function_sequence/cli.py,sha256=ftGEFcX5CWH77P91m_MSGt1s5huk_Pl5QxumyuCchPw,6267
|
|
7
|
+
function_sequence/control.py,sha256=ErYNaFw2wT3swpSeg1Mc5dvPdf2zpWgK4tbB9Xj4n9M,844
|
|
8
|
+
function_sequence/definitions.py,sha256=KqFJiuvB-C8g1fKHp7vdVA4iijyBkLlh_4rPWjYEw4I,7420
|
|
9
|
+
function_sequence/errors.py,sha256=UYoDS82ZC0jAf6EtU6j9euHq4tgdmijlQI2lbWicQXM,1638
|
|
10
|
+
function_sequence/expressions.py,sha256=VHppGfg0Anjdfywdmygbr4Yt2EVJ3OTqW4qlzHCDqgg,3795
|
|
11
|
+
function_sequence/operations.py,sha256=V9Tu6uFpzc1ZNJHurz4Q9mvTVpWEC9Mq9PEOPHQN1dQ,7893
|
|
12
|
+
function_sequence/pipeline.py,sha256=68i9NXmiR5lCkD1c_ijJ-MGUcBQcia-wmeHNpRG8rBA,11957
|
|
13
|
+
function_sequence/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
function_sequence/runtime.py,sha256=PgazUCAObKqWG073Pr5rYHJuq-o2xw038M6YmRz9Nx8,12132
|
|
15
|
+
function_sequence/storage.py,sha256=U1FjmuOPEYGG9N42HGI3a6PwYauvGNZzgHLPbS2-M3E,7103
|
|
16
|
+
function_sequence/terminal.py,sha256=JKZoS_gzQcGCTj3VU6BObvpi_du_3J1X0E53QSDxEeA,9217
|
|
17
|
+
function_sequence/values.py,sha256=NEhk_5Cnr87DXM7xRc97wwrv7xYoha5Jew7s-wJ3Gjc,3325
|
|
18
|
+
function_sequence/workflow.py,sha256=xBC9fD0GaqmO6PC7MuOfmj5_GXNAM5aS-DPE4Zoemnc,5907
|
|
19
|
+
function_sequence/workflow_cli.py,sha256=ueOjX3RDcVzcvF9tHt_2JttuR_b6JlF2BvdU39ojWiE,5419
|
|
20
|
+
function_sequence-0.2.0.dist-info/licenses/LICENSE.md,sha256=mlabKsOPaY1JvPF5gjK7uC5MWwkugPFsr23PIWJkBvg,1092
|
|
21
|
+
function_sequence-0.2.0.dist-info/WHEEL,sha256=e4_1dyBeezi8ZjfxrZ3bnVOxFDa3ksqVqH0jTHkUZ3k,81
|
|
22
|
+
function_sequence-0.2.0.dist-info/entry_points.txt,sha256=v7NW5ndAIHweg3C3hpBLeb3uye-lEqE3SXeGhUYlOco,66
|
|
23
|
+
function_sequence-0.2.0.dist-info/METADATA,sha256=9EYzz7zFmE8bx6Y9dWsoXEOgg4-vAVsSPRdbVjXr9ss,6503
|
|
24
|
+
function_sequence-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wispsy
|
|
4
|
+
Copyright (c) 2026 Ella Inng
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|