function-sequence 0.2.0__tar.gz

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.
Files changed (65) hide show
  1. function_sequence-0.2.0/LICENSE.md +22 -0
  2. function_sequence-0.2.0/PKG-INFO +101 -0
  3. function_sequence-0.2.0/README.md +83 -0
  4. function_sequence-0.2.0/conformance/values.json +31 -0
  5. function_sequence-0.2.0/docs/provenance.md +7 -0
  6. function_sequence-0.2.0/docs/releasing.md +46 -0
  7. function_sequence-0.2.0/docs/sequences.md +185 -0
  8. function_sequence-0.2.0/docs/storage.md +79 -0
  9. function_sequence-0.2.0/docs/terminal.md +33 -0
  10. function_sequence-0.2.0/docs/workflows.md +17 -0
  11. function_sequence-0.2.0/examples/__init__.py +1 -0
  12. function_sequence-0.2.0/examples/greeting.py +17 -0
  13. function_sequence-0.2.0/examples/text.json +10 -0
  14. function_sequence-0.2.0/examples/text.toml +14 -0
  15. function_sequence-0.2.0/examples/text_operations.py +13 -0
  16. function_sequence-0.2.0/pyproject.toml +47 -0
  17. function_sequence-0.2.0/pyproject.toml.orig +36 -0
  18. function_sequence-0.2.0/scripts/check_distribution.py +148 -0
  19. function_sequence-0.2.0/scripts/check_specification.py +50 -0
  20. function_sequence-0.2.0/specification/contract.schema.json +89 -0
  21. function_sequence-0.2.0/specification/execution.schema.json +73 -0
  22. function_sequence-0.2.0/specification/expression.schema.json +140 -0
  23. function_sequence-0.2.0/specification/operation.schema.json +85 -0
  24. function_sequence-0.2.0/specification/semantics.md +37 -0
  25. function_sequence-0.2.0/specification/sequence.schema.json +150 -0
  26. function_sequence-0.2.0/specification/workflow.schema.json +89 -0
  27. function_sequence-0.2.0/src/function_sequence/__init__.py +26 -0
  28. function_sequence-0.2.0/src/function_sequence/__main__.py +3 -0
  29. function_sequence-0.2.0/src/function_sequence/_budget.py +66 -0
  30. function_sequence-0.2.0/src/function_sequence/_validation.py +125 -0
  31. function_sequence-0.2.0/src/function_sequence/application.py +33 -0
  32. function_sequence-0.2.0/src/function_sequence/cli.py +146 -0
  33. function_sequence-0.2.0/src/function_sequence/control.py +31 -0
  34. function_sequence-0.2.0/src/function_sequence/definitions.py +191 -0
  35. function_sequence-0.2.0/src/function_sequence/errors.py +58 -0
  36. function_sequence-0.2.0/src/function_sequence/expressions.py +114 -0
  37. function_sequence-0.2.0/src/function_sequence/operations.py +191 -0
  38. function_sequence-0.2.0/src/function_sequence/pipeline.py +279 -0
  39. function_sequence-0.2.0/src/function_sequence/py.typed +0 -0
  40. function_sequence-0.2.0/src/function_sequence/runtime.py +302 -0
  41. function_sequence-0.2.0/src/function_sequence/storage.py +164 -0
  42. function_sequence-0.2.0/src/function_sequence/terminal.py +193 -0
  43. function_sequence-0.2.0/src/function_sequence/values.py +77 -0
  44. function_sequence-0.2.0/src/function_sequence/workflow.py +135 -0
  45. function_sequence-0.2.0/src/function_sequence/workflow_cli.py +108 -0
  46. function_sequence-0.2.0/terminal_tests/test_terminal.py +106 -0
  47. function_sequence-0.2.0/tests/lifecycle_worker.py +29 -0
  48. function_sequence-0.2.0/tests/test_application.py +31 -0
  49. function_sequence-0.2.0/tests/test_async.py +167 -0
  50. function_sequence-0.2.0/tests/test_cli.py +112 -0
  51. function_sequence-0.2.0/tests/test_composites.py +32 -0
  52. function_sequence-0.2.0/tests/test_conformance.py +17 -0
  53. function_sequence-0.2.0/tests/test_definitions.py +75 -0
  54. function_sequence-0.2.0/tests/test_documentation.py +30 -0
  55. function_sequence-0.2.0/tests/test_execution_limits.py +31 -0
  56. function_sequence-0.2.0/tests/test_expressions.py +39 -0
  57. function_sequence-0.2.0/tests/test_operation_boundaries.py +38 -0
  58. function_sequence-0.2.0/tests/test_operations.py +48 -0
  59. function_sequence-0.2.0/tests/test_pipeline.py +164 -0
  60. function_sequence-0.2.0/tests/test_pipeline_execution.py +37 -0
  61. function_sequence-0.2.0/tests/test_pipeline_recovery.py +108 -0
  62. function_sequence-0.2.0/tests/test_runtime.py +215 -0
  63. function_sequence-0.2.0/tests/test_storage.py +248 -0
  64. function_sequence-0.2.0/tests/test_workflow.py +103 -0
  65. function_sequence-0.2.0/tests/test_workflow_cli.py +51 -0
@@ -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.
@@ -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,83 @@
1
+ # Function Sequence
2
+
3
+ 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.
4
+
5
+ Python 3.11+; no base runtime dependencies. The distribution and command are `function-sequence`; Python imports use `function_sequence`.
6
+
7
+ ```sh
8
+ python -m pip install function-sequence==0.2.0
9
+ python -m pip install "function-sequence[cli]==0.2.0"
10
+ ```
11
+
12
+ ## Compose ordinary functions
13
+
14
+ ```python
15
+ from function_sequence import Input, NativeResolver, Pipeline, Ref, Step
16
+
17
+ def normalize(text: str) -> str:
18
+ return " ".join(text.lower().split())
19
+
20
+ resolver = NativeResolver({"text.normalize": normalize}, version="text-v1")
21
+ definition = Pipeline("text.process", version="1", steps=(
22
+ Step("clean", "text.normalize", {"text": Input("text")}),
23
+ ), outputs={"text": Ref("clean")})
24
+ bound = definition.bind(resolver, resolver_version="text-v1")
25
+ assert bound.run({"text": " Hello WORLD "}).outputs == {"text": "hello world"}
26
+ ```
27
+
28
+ 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.
29
+
30
+ `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.
31
+
32
+ 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.
33
+
34
+ ## Pause and recover
35
+
36
+ ```python
37
+ from function_sequence import Script
38
+
39
+ def collect():
40
+ return {"text": "hello"}
41
+
42
+ def display(text):
43
+ return {"displayed": text}
44
+
45
+ script = Script("greeting", version="1")
46
+ collected = script.add_function(collect)
47
+ script.add_function(display, collected["text"])
48
+ first = script.run(checkpoint="greeting.progress.json", pace="function")
49
+ assert first.status == "paused"
50
+ complete = script.run(checkpoint="greeting.progress.json")
51
+ assert complete.results["display"] == {"displayed": "hello"}
52
+ ```
53
+
54
+ `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.
55
+
56
+ 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.
57
+
58
+ ## Passive documents and hosts
59
+
60
+ 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.
61
+
62
+ ```sh
63
+ function-sequence workflow inspect examples/text.json
64
+ 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
65
+ ```
66
+
67
+ 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.
68
+
69
+ ## Contracts and verification
70
+
71
+ [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.
72
+
73
+ ```sh
74
+ uv run --python 3.11 --locked python -m unittest discover -s tests -v
75
+ uv run --python 3.14 --locked --extra terminal python -m unittest discover -s terminal_tests -v
76
+ uv run --python 3.11 --locked --group spec python scripts/check_specification.py
77
+ uv build --out-dir dist
78
+ uv run --python 3.11 --locked python scripts/check_distribution.py dist
79
+ ```
80
+
81
+ 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).
82
+
83
+ 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,31 @@
1
+ {
2
+ "schema": 1,
3
+ "valid": [
4
+ null,
5
+ true,
6
+ 0,
7
+ -17,
8
+ 1.5,
9
+ "日本語",
10
+ {
11
+ "ref": {
12
+ "step": "literal"
13
+ }
14
+ },
15
+ [
16
+ {
17
+ "x": [
18
+ 1,
19
+ 2
20
+ ]
21
+ }
22
+ ]
23
+ ],
24
+ "invalid_documents": [
25
+ "{\"x\":1,\"x\":2}",
26
+ "NaN",
27
+ "1e999",
28
+ "\"\\ud800\"",
29
+ "{} {}"
30
+ ]
31
+ }
@@ -0,0 +1,7 @@
1
+ # Source provenance
2
+
3
+ The consolidated foundation retains the existing sequence implementation and history from revision ae1a73db7420349692583768128eb3dca01761df. Explicit pipeline mappings and behavior tests originate in Moveset revision 3d496fdf913cf21c811c8ee47f407a50995b8752; passive workflow documents and command/terminal behavior originate in Scriptty revision 92caefdbd21b176b5d1f10c92d88527c21a00ca4. Those sources use the MIT license with the 2026 Ella Inng notice, retained in the combined LICENSE.md alongside the original sequence notice.
4
+
5
+ The passive contract validator derives from the existing Hidden Moves schema subset, under its MIT notice. The independent composition core does not import that framework. Selected capability binding, provider hosting and composite exposure remain in its optional integration.
6
+
7
+ No legacy namespace or compatibility distribution is shipped. Historic Git source and private retirement backups preserve provenance; canonical installed behavior is qualified from the Function Sequence wheel and source archive.
@@ -0,0 +1,46 @@
1
+ # Releases
2
+
3
+ The distribution is `function-sequence`, the Python import is `function_sequence`, the builder is
4
+ `Script`, and the console entry point is `function-sequence`. Version 0.2.0 is the first canonical consolidated release. No legacy compatibility distribution is published.
5
+
6
+ ## Candidate verification
7
+
8
+ Use Python 3.14 and the committed lockfile:
9
+
10
+ ```console
11
+ uv sync --locked
12
+ uv run --locked python -m unittest discover -s tests -v
13
+ uv build --no-sources
14
+ uv run --locked python scripts/check_distribution.py dist --tag v0.2.0
15
+ uvx --from twine twine check --strict dist/*
16
+ ```
17
+
18
+ The distribution check validates the source/wheel allowlists, metadata identity,
19
+ empty mandatory runtime dependency list, RECORD hashes, source parity and release tag.
20
+ It installs the wheel into a new environment, runs the API/CLI outside the source
21
+ checkout, proves resume does not repeat completed calls, then runs all tests
22
+ from the source archive against the installed package. The wheel is built from
23
+ the source archive. CI checks the 3.11 floor and current 3.14 platforms, optional workflow/terminal profiles and local schema conformance.
24
+
25
+ ## Publication
26
+
27
+ 1. Merge the reviewed release preparation and require passing final-main CI.
28
+ 2. Create an immutable `v<version>` tag on that exact commit.
29
+ 3. Publish the GitHub release for that tag. This starts `release.yaml`.
30
+ 4. The build job verifies the tag/version, builds and tests the distributions,
31
+ checks metadata, and saves the exact artifacts. It has no publishing token.
32
+ 5. The publish job downloads those artifacts and uses PyPI Trusted Publishing
33
+ through the `pypi` environment. Only this job has `id-token: write`.
34
+ 6. Verify both PyPI SHA256 digests against the workflow artifacts, perform a fresh
35
+ registry install, and attach the verified distributions to the GitHub release.
36
+
37
+ The PyPI publisher must identify owner `wispsy`, repository `function-sequence`,
38
+ workflow `release.yaml`, and environment `pypi`. The GitHub environment permits
39
+ version tags. No long-lived PyPI API token is stored in this repository.
40
+ See [PyPI Trusted Publishing](https://docs.pypi.org/trusted-publishers/using-a-publisher/).
41
+
42
+ Manual `workflow_dispatch` runs verify a candidate and save artifacts without
43
+ publishing. Publishing is enabled only for a published stable GitHub release.
44
+ Do not move a released tag or overwrite artifacts; use a new version for changes.
45
+ If publication fails, inspect the job before retrying. If a partial upload exists,
46
+ confirm the existing files match the reviewed artifacts before taking any action.
@@ -0,0 +1,185 @@
1
+ # Native sequences and recovery
2
+
3
+ Run ordered Python functions, pass JSON results forward, pause at function
4
+ boundaries, and resume from saved progress. Python 3.11+; no runtime dependencies.
5
+
6
+ Install with `pip install function-sequence`. The import package is `function_sequence`, and the
7
+ console command is `function-sequence`.
8
+
9
+ ## Start with a script
10
+
11
+ From the source checkout, run `uv sync`. Save this as `greeting.py`:
12
+
13
+ ```python
14
+ from function_sequence import Script
15
+
16
+ def collect():
17
+ return {"message": "Hello from function_sequence!"}
18
+
19
+ def display(message):
20
+ print(message)
21
+ return {"displayed": True}
22
+
23
+ script = Script("greeting", version="1")
24
+ collected = script.add_function(collect)
25
+ script.add_function(display, collected["message"])
26
+
27
+ if __name__ == "__main__":
28
+ first = script.run(checkpoint="greeting.progress.json", pace="function")
29
+ assert first.status == "paused"
30
+ result = script.run(checkpoint="greeting.progress.json")
31
+ assert result.results["display"] == {"displayed": True}
32
+ ```
33
+
34
+ `add_function` queues a call and returns a `Ref` to its eventual result. It does
35
+ not execute the function. References select string dictionary keys or nonnegative
36
+ list indexes and must point to earlier function steps. Arguments can contain
37
+ references inside lists and dictionaries. `step_id="..."` overrides the default
38
+ function name; IDs must be unique. Wrap functions that need a keyword named
39
+ `step_id` to avoid the registration option of the same name.
40
+
41
+ Functions return strict JSON values: `None`, booleans, integers, finite floats,
42
+ Unicode strings, lists and dictionaries with string keys. Tuples, classes,
43
+ bytes, open files and native handles are rejected. Arguments and outputs are
44
+ copied so one step cannot mutate saved prior results. Missing result paths fail
45
+ before the dependent function runs.
46
+
47
+ The [workflow guide](docs/workflows.md) covers immutable pipelines, passive JSON/TOML documents, explicit resolvers and optional command/terminal hosts. Hidden Moves supplies an optional selected-capability integration; the composition core remains independent.
48
+
49
+ ## Pause and continue
50
+
51
+ | `pace` | Behavior |
52
+ | --- | --- |
53
+ | `auto` | Continue until completion, failure or an external pause request. |
54
+ | `function` | Complete at most one function, then return paused if work remains. |
55
+ | `pause` | Continue until `pause()` is called or a queued pause marker completes. |
56
+
57
+ `script.add_pause(step_id="review")` queues a visible marker. Its output is
58
+ `None`, and it cannot be used as a result reference. `from function_sequence import pause`
59
+ provides `pause()` inside a function. It requests a pause after the function
60
+ returns, so subsequent lines still run. It does nothing outside a running script
61
+ or with another pace. Completion takes precedence if no work remains.
62
+
63
+ Pass `control=Control()` to either runner. An input adapter or another thread
64
+ may call `control.request_pause()`. The current function can finish, but another
65
+ function will not start. Call `control.reset()` before continuing with that same
66
+ control. Split long actions into smaller functions to improve stop latency.
67
+ There is no forced thread termination, line debugger or global keyboard listener.
68
+
69
+ Importing the library starts no threads, opens no desktop sessions, installs no
70
+ signal handlers and creates no files. `console_log=True` prints structural events;
71
+ a synchronous `observer(event)` receives `kind`, `script`, `step_id` and `next_step`.
72
+ Events contain no arguments or results. User functions are responsible for their
73
+ own prints and logs. Observer exceptions propagate; committed steps stay completed.
74
+
75
+ ## Progress and recovery
76
+
77
+ An explicit `checkpoint=` enables durable progress in an existing parent directory.
78
+ Without it, progress lives only in that `Script` instance. Repeated calls continue;
79
+ a completed run returns saved results without repeating calls. Choose storage on
80
+ the first invocation and keep using it. To switch storage, build a fresh definition
81
+ or explicitly restart. Definitions cannot be changed after execution begins.
82
+
83
+ `RunResult` exposes `status`, `next_step` (the next queue index), `completed`
84
+ (step IDs), `results` (a copied dictionary keyed by step ID) and `run_id`.
85
+ Successful runner calls return paused or completed.
86
+
87
+ Progress is bounded, versioned JSON written atomically under an exclusive lock.
88
+ It contains no serialized callables and is never unpickled. A manifest fingerprint
89
+ detects changes to script name/version, step order, callable names and registered
90
+ arguments. **Bump `Script(..., version="2")` when function behavior, captured values,
91
+ defaults or relevant environment configuration changes.** The fingerprint does
92
+ not hash function source or prove an unchanged environment.
93
+
94
+ An in-flight marker is saved before a function begins. A crash, exception, invalid
95
+ return, cancellation or failed result write can leave the action uncertain.
96
+ Ordinary resume raises `RecoveryRequiredError`. Inspect external effects, then
97
+ choose `retry=True` to repeat that action or `restart=True` to discard progress
98
+ and repeat the whole script. These options are mutually exclusive.
99
+ `StepFailedError` exposes `step_id` and a chained cause. Interrupts/cancellation
100
+ propagate after recording the interrupted step. Corrupt or incompatible progress
101
+ always fails explicitly.
102
+
103
+ Retry and restart do not roll back effects or guarantee exactly-once execution.
104
+ Use application-level idempotency keys or external receipts when repetition matters.
105
+ `script.delete_progress()` removes its bound file and resets its memory;
106
+ `CheckpointStore(path).delete()` removes a selected file without executing code.
107
+ Deletion does not undo actions.
108
+
109
+ Hard termination may leave `<checkpoint>.lock`. Confirm the original process has
110
+ stopped before manually removing it. The runner does not infer safety from an old
111
+ PID or lock. See the [storage contract](docs/storage.md) for schema and limits.
112
+
113
+ ## Asynchronous functions
114
+
115
+ ```python
116
+ import asyncio
117
+ from function_sequence import Script
118
+
119
+ async def collect():
120
+ return {"value": 3}
121
+
122
+ def double(value):
123
+ return value * 2
124
+
125
+ async def main():
126
+ script = Script("async-example")
127
+ collected = script.add_function(collect)
128
+ script.add_function(double, collected["value"])
129
+ result = await script.arun()
130
+ assert result.results["double"] == 6
131
+
132
+ asyncio.run(main())
133
+ ```
134
+
135
+ `arun()` awaits mixed steps sequentially. Synchronous functions and checkpoint
136
+ writes run on the calling thread; blocking work blocks the event loop. Steps
137
+ must own and await their work rather than leave detached tasks after completion.
138
+ Cancellation preserves uncertainty and propagates `asyncio.CancelledError`.
139
+ Use `await script.arun()` inside an existing event loop; `run()` rejects async
140
+ functions instead of creating another loop.
141
+
142
+ ## Command line
143
+
144
+ Run the bundled example from the checkout:
145
+
146
+ ```console
147
+ uv run function-sequence run examples.greeting:script --checkpoint greeting.progress.json --interactive
148
+ uv run function-sequence status greeting.progress.json
149
+ uv run function-sequence run examples.greeting:script --checkpoint greeting.progress.json
150
+ uv run function-sequence delete greeting.progress.json
151
+ ```
152
+
153
+ `run` imports an explicitly selected **trusted** `module:attribute`. The current
154
+ directory is searched first, and the attribute must be a `Script`. Imports and
155
+ calls execute ordinary Python code; this command is not a sandbox. Use
156
+ `greeting:script` for your saved example. `status` and `delete` manage only data
157
+ and never import that script. CLI summaries omit stored outputs.
158
+
159
+ `--interactive` uses function pacing: Return continues; any text, EOF or Ctrl-C
160
+ at the prompt leaves progress paused. Without it, the command never reads stdin.
161
+ During execution Ctrl-C requests a cooperative pause and waits for the function
162
+ to return. The prior signal handler is restored afterward. A function that blocks
163
+ indefinitely cannot be forced to finish by cooperative STOP.
164
+
165
+ Use `--async` for async sequences, `--pace function` or `--pace pause` for a single
166
+ paced invocation, and `--console-log` for structural events. `--restart` and
167
+ `--retry` authorize repetition. Completion/cooperative pause returns exit code 0;
168
+ errors return 2; KeyboardInterrupt at the prompt returns 130.
169
+ `python -m function_sequence` provides the same commands. The library intercepts no signals.
170
+
171
+ ## Development
172
+
173
+ ```console
174
+ uv run python -m unittest discover -s tests -v
175
+ uv build --out-dir dist
176
+ uv run python scripts/check_distribution.py dist
177
+ ```
178
+
179
+ CI checks Python 3.11 on Linux/Windows and 3.14 on Linux, macOS and Windows, distribution contents and an
180
+ isolated installed CLI. Tests use synthetic functions and temporary files. There
181
+ are no real desktop actions. See the [release process](docs/releasing.md) for
182
+ version tags and PyPI publication. License selection, desktop listeners and
183
+ recording formats retain separate decisions in the
184
+ [roadmap](https://github.com/wispsy/function-sequence/issues/1) and
185
+ [Project](https://github.com/orgs/wispsy/projects/9).
@@ -0,0 +1,79 @@
1
+ # Local progress storage
2
+
3
+ The caller selects a local file in an existing parent directory. Keep that
4
+ directory private. JSON is plaintext and unauthenticated: schema validation
5
+ cannot stop a malicious local writer from fabricating plausible results. Avoid
6
+ storing secrets in results. Reading progress never imports script code.
7
+
8
+ ## Schema version 1
9
+
10
+ | Field | Contract |
11
+ | --- | --- |
12
+ | `schema` | Integer 1; unknown versions and extra fields fail. |
13
+ | `fingerprint` | Lowercase SHA256 of the canonical definition manifest. |
14
+ | `run_id` | Canonical UUID4 retained across resumes. |
15
+ | `status` | `ready`, `running`, `paused`, `completed`, `failed`, `interrupted`. |
16
+ | `cursor` | Nonnegative integer indexing the next queued step. |
17
+ | `active_step` | Current uncertain step ID, otherwise null. |
18
+ | `results` | Exact completed prefix of IDs to copied JSON values. |
19
+ | `error_type` | Exception class name for failed/interrupted steps; otherwise null. |
20
+
21
+ No exception message, traceback, function object or reconstruction recipe is
22
+ stored. Results remain application data and can contain sensitive values.
23
+ Status inspection reports counts and failure metadata, excluding outputs.
24
+ Names are visible metadata and should not contain secrets.
25
+
26
+ Documents are limited to 4 MiB of UTF-8 and 64 levels of nesting. Parsing rejects
27
+ duplicate keys, non-finite numbers and invalid Unicode. The runner validates
28
+ the completed prefix, queue bounds, active-step identity and completed status
29
+ against the trusted definition. Pause-marker outputs must be null.
30
+
31
+ ## Write boundaries
32
+
33
+ 1. Resolve inputs and notify observers before invoking an action.
34
+ 2. Persist running state with an active step.
35
+ 3. Execute the function and validate its result.
36
+ 4. Persist the result, advance the cursor and clear the active marker.
37
+ 5. Persist paused or completed at the appropriate boundary.
38
+
39
+ Running state with no active step can occur between commits and is safe to
40
+ continue: the prior result is committed. Failed/interrupted states retain an
41
+ active step. Normal resume refuses every active step, including a running marker
42
+ left by process death. Retry explicitly clears uncertainty before repeating it;
43
+ the runner cannot determine what happened in an external application.
44
+
45
+ A failure before the active marker is saved never invokes the function. After
46
+ invocation, failure preserves that marker or a failed state. If the failure write
47
+ also fails, the pre-call marker remains. If only the terminal completed-status
48
+ write fails after committing an output, normal resume finalizes completion
49
+ without repeating the action. There are no automatic retries or rollbacks.
50
+
51
+ ## Ownership and filesystem assumptions
52
+
53
+ An exclusive `<checkpoint>.lock` is created with mode 0600 and held through the
54
+ invocation. It contains a PID for inspection and is removed on normal exit,
55
+ exceptions and async cancellation. Hard exit may leave it. Independently confirm
56
+ its owner has stopped before manually removing it; no automatic stale-lock
57
+ breaking is attempted.
58
+
59
+ Each write uses a same-directory temporary file with restrictive permissions,
60
+ flush/fsync and atomic replacement. POSIX also fsyncs the directory. Temporary
61
+ files are cleaned on ordinary failure; process death can leave dot-prefixed
62
+ temporary files, which are never loaded as progress. Replacement adopts the
63
+ temporary file's permissions. Windows ACLs follow the parent directory's policy.
64
+
65
+ Progress/lock paths must be regular files, not symlinks. Reads check identity at
66
+ open time; lock release checks its ownership. These checks assume a trusted
67
+ parent directory. Hostile directory mutation, privileged writers, network
68
+ filesystem locks and filesystems without replacement/fsync support are outside
69
+ this storage contract. Use a local filesystem.
70
+
71
+ Restart explicitly replaces malformed or incompatible progress with a new run,
72
+ while retaining path and ownership checks. Deletion removes only the selected
73
+ file under the same lock. It never follows checkpoint-supplied paths, removes
74
+ directories or undoes actions.
75
+
76
+ Python's [pickle documentation](https://docs.python.org/3.14/library/pickle.html)
77
+ explains why object reconstruction is unsuitable for passive progress. Signing
78
+ pickle can authenticate a producer but cannot make reconstruction passive.
79
+ There is no pickle compatibility mode.
@@ -0,0 +1,33 @@
1
+ # Optional workflow terminal
2
+
3
+ Install the `terminal` profile on Python 3.14+. The native host requires supported
4
+ POSIX TTY input; synthetic fixtures qualify the model on Linux/macOS/Windows.
5
+
6
+ ```sh
7
+ function-sequence terminal examples/text.json --inputs inputs.json --checkpoint progress.json --provider wispsy-reference --select text.normalize --select text.report --resolver-version text-v1
8
+ ```
9
+
10
+ Tab moves between the JSON input editor, required operations and actions. Use
11
+ up/down and space to explicitly select every required operation before execution.
12
+ Enter on actions starts a new run; r resumes existing progress, t explicitly retries
13
+ an uncertain action, and R restarts. p requests a cooperative pause. q/Ctrl-C during
14
+ execution requests pause and closes after that boundary; otherwise it closes the
15
+ session. Synchronous functions cannot be preempted while blocking the UI thread.
16
+
17
+ Inputs use the same schema-1 envelope as CLI execution. Workflow files are still
18
+ passive; the host selects trusted installed providers and exact resolver names.
19
+ Carets owns input, focus, rendering, terminal state and command lifetime. The same
20
+ application.execute API and Function Sequence Script/Control own execution/progress/recovery.
21
+ There is no additional parser, executor, checkpoint format or desktop listener.
22
+
23
+ The native host owns raw mode, alternate screen, cursor and bracketed paste only
24
+ for its session. UI rendering uses the explicitly selected stderr stream; trusted
25
+ diagnostics are buffered and flushed after terminal restoration, and the final
26
+ versioned outcome uses the CLI stdout contract. Visible input/progress control
27
+ characters are escaped. Library construction installs no terminal or signal hooks.
28
+
29
+ WorkflowTerminal is an ordinary update/view model. Attach it to a Carets Program
30
+ and supply the same workflow, resolver version, inputs and explicit checkpoint.
31
+ Installed tests use TestProgram to prove input edits, selection gates, resize,
32
+ progress, cooperative pause, completed-step non-replay and explicit uncertain retry.
33
+ All library and CLI execution remains available without this optional frontend.
@@ -0,0 +1,17 @@
1
+ # Passive workflows and explicit hosts
2
+
3
+ Install `function-sequence[cli]` for the optional workflow commands. The native Script commands remain available in the dependency-free base package.
4
+
5
+ ```sh
6
+ function-sequence workflow inspect examples/text.json
7
+ function-sequence workflow list --resolver examples.text_operations:resolver --select text.normalize --select text.report --resolver-version text-v1
8
+ 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
9
+ ```
10
+
11
+ Inputs use `{"schema":1,"inputs":{"text":" Hello WORLD "}}`. The resolver is an explicitly selected trusted Python object. Loading it can execute ordinary Python imports; inspecting a workflow imports no resolver. Exact operation selection is required for list/run/resume/terminal. Hidden Moves providers are configured by its optional composition integration, outside the independent core.
12
+
13
+ A new `--checkpoint progress.json --pace function` run pauses after one operation. `workflow resume` uses the same document, resolver version, inputs and checkpoint. `--retry` and `--restart` explicitly permit repetition after uncertainty. Changed identities fail; ordinary resume does not replay completed work. No automatic rollback or retry is provided.
14
+
15
+ Outcomes are schema-1 UTF-8 JSON on stdout, including status, fingerprint, completed IDs, results, explicit outputs and run ID. Paused outputs are null. Trusted operation diagnostics go to stderr. Errors end with a schema-1 JSON stderr record and a nonzero status; CLI usage returns 2. Help is on stderr. Application hosts can call `function_sequence.application.execute` directly without stdin, terminal or signal ownership.
16
+
17
+ The optional terminal profile reuses Carets and the same application API. Core imports do not open a session. Nested composite invocation initially has one parent recovery boundary and a shared finite operation/nesting budget; retry may repeat inner effects. Numerical tensors, models and native resource handles remain outside JSON progress.
@@ -0,0 +1 @@
1
+ """Synthetic function sequences that perform no desktop operations."""
@@ -0,0 +1,17 @@
1
+ """Run with: function-sequence run examples.greeting:script --checkpoint greeting.progress.json"""
2
+
3
+ from function_sequence import Script
4
+
5
+
6
+ def collect():
7
+ return {"message": "Hello from function_sequence!"}
8
+
9
+
10
+ def display(message):
11
+ print(message)
12
+ return {"displayed": True}
13
+
14
+
15
+ script = Script("greeting", version="1")
16
+ collected = script.add_function(collect)
17
+ script.add_function(display, collected["message"])
@@ -0,0 +1,10 @@
1
+ {
2
+ "schema": 2,
3
+ "name": "text-report",
4
+ "version": "1",
5
+ "steps": [
6
+ {"id": "normalize", "operation": "text.normalize", "arguments": {"object": {"text": {"input": {"name": "text"}}}}},
7
+ {"id": "report", "operation": "text.report", "arguments": {"object": {"text": {"ref": {"step": "normalize"}}}}}
8
+ ],
9
+ "outputs": {"object": {"report": {"ref": {"step": "report"}}}}
10
+ }