active-lang 1.4.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.
- LICENSE-APACHE +201 -0
- LICENSE-MIT +21 -0
- active.py +290 -0
- active.pyi +48 -0
- active_lang-1.4.0.dist-info/METADATA +71 -0
- active_lang-1.4.0.dist-info/RECORD +7 -0
- active_lang-1.4.0.dist-info/WHEEL +4 -0
LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Active Language Authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
active.py
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"""Active Python binding, WASM-first (CHECKLIST 1.004-1.006).
|
|
2
|
+
|
|
3
|
+
Zero native compilation: the binding drives the zero-import
|
|
4
|
+
``active_wasm.wasm`` module through wasmtime and exposes the agent-loop
|
|
5
|
+
surface with opaque handles, an ABI major gate, and Allocator Model A
|
|
6
|
+
(the module's ``active_free`` frees everything the module allocated).
|
|
7
|
+
|
|
8
|
+
Ownership rules: a ``Module`` owns one instantiated evaluator confined to
|
|
9
|
+
the creating thread. One module per thread; never share a module across
|
|
10
|
+
threads, locking or not — the engine state is thread-confined by
|
|
11
|
+
construction. Use it as a context manager or call ``close()`` explicitly.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
import wasmtime
|
|
21
|
+
|
|
22
|
+
ABI_MAJOR = 1
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _binding_version() -> str:
|
|
26
|
+
"""Distribution version for release-asset URLs. Reads the installed
|
|
27
|
+
package metadata when available so the hint can never drift from
|
|
28
|
+
the shipped version; falls back to the workspace version in-repo."""
|
|
29
|
+
try:
|
|
30
|
+
from importlib.metadata import version
|
|
31
|
+
|
|
32
|
+
return version("active-lang")
|
|
33
|
+
except Exception:
|
|
34
|
+
return "1.4.0"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class ActiveError(Exception):
|
|
38
|
+
"""Any failure surfaced by the Active module or the binding."""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Diagnostic:
|
|
42
|
+
"""One structured diagnostic from an evaluation envelope.
|
|
43
|
+
|
|
44
|
+
``message`` is the full diagnostics text (kept for prose readers);
|
|
45
|
+
``line``/``column``/``end_line``/``end_column`` carry the structured
|
|
46
|
+
span when the core attributed one (None when spanless), and
|
|
47
|
+
``severity`` is the core severity string (error/warning/info/hint).
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
code: str,
|
|
53
|
+
message: str,
|
|
54
|
+
line: int | None = None,
|
|
55
|
+
column: int | None = None,
|
|
56
|
+
end_line: int | None = None,
|
|
57
|
+
end_column: int | None = None,
|
|
58
|
+
severity: str | None = None,
|
|
59
|
+
) -> None:
|
|
60
|
+
self.code = code
|
|
61
|
+
self.message = message
|
|
62
|
+
self.line = line
|
|
63
|
+
self.column = column
|
|
64
|
+
self.end_line = end_line
|
|
65
|
+
self.end_column = end_column
|
|
66
|
+
self.severity = severity
|
|
67
|
+
|
|
68
|
+
def __repr__(self) -> str: # pragma: no cover - debugging aid
|
|
69
|
+
return f"Diagnostic({self.code}: {self.message[:80]})"
|
|
70
|
+
|
|
71
|
+
def span(self) -> tuple[int, int, int, int] | None:
|
|
72
|
+
"""Structured span tuple, or None when the core left it spanless.
|
|
73
|
+
|
|
74
|
+
Only complete spans are returned: a partial span (any slot
|
|
75
|
+
missing) degrades to None rather than a tuple containing None,
|
|
76
|
+
which callers treat identically to spanless.
|
|
77
|
+
"""
|
|
78
|
+
parts = (self.line, self.column, self.end_line, self.end_column)
|
|
79
|
+
if any(p is None for p in parts):
|
|
80
|
+
return None
|
|
81
|
+
return (self.line, self.column, self.end_line, self.end_column) # type: ignore[return-value]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _repo_root() -> Path:
|
|
85
|
+
return Path(__file__).resolve().parents[2]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def default_wasm_path() -> Path:
|
|
89
|
+
"""Resolve the evaluator WASM module for installed-package use.
|
|
90
|
+
|
|
91
|
+
Order: ``$ACTIVE_WASM_PATH`` first, then a bundled
|
|
92
|
+
``active_wasm.wasm`` next to this file (placed there by
|
|
93
|
+
``packaging/fetch-wasm.py`` when the distributable is built),
|
|
94
|
+
then the in-repo debug/release build (development). Packaged
|
|
95
|
+
installs never depend on the repo target directory.
|
|
96
|
+
"""
|
|
97
|
+
env = os.environ.get("ACTIVE_WASM_PATH")
|
|
98
|
+
if env:
|
|
99
|
+
return Path(env)
|
|
100
|
+
bundled = Path(__file__).resolve().parent / "active_wasm.wasm"
|
|
101
|
+
if bundled.is_file():
|
|
102
|
+
return bundled
|
|
103
|
+
return (
|
|
104
|
+
_repo_root()
|
|
105
|
+
/ "target"
|
|
106
|
+
/ "wasm32-unknown-unknown"
|
|
107
|
+
/ "release"
|
|
108
|
+
/ "active_wasm.wasm"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class Module:
|
|
113
|
+
"""One instantiated Active evaluator (opaque handle, do not share threads)."""
|
|
114
|
+
|
|
115
|
+
def __init__(self, wasm_path: Path | str | None = None) -> None:
|
|
116
|
+
path = Path(wasm_path) if wasm_path is not None else default_wasm_path()
|
|
117
|
+
if not path.is_file():
|
|
118
|
+
raise ActiveError(
|
|
119
|
+
f"wasm module not found: {path} "
|
|
120
|
+
"(pass wasm_path=..., set ACTIVE_WASM_PATH, or place "
|
|
121
|
+
"active_wasm.wasm next to the package — see packaging/fetch-wasm.py "
|
|
122
|
+
"or the release asset at "
|
|
123
|
+
f"https://github.com/Active-Official/active/releases/tag/v{_binding_version()})"
|
|
124
|
+
)
|
|
125
|
+
self._store = wasmtime.Store()
|
|
126
|
+
module = wasmtime.Module.from_file(self._store.engine, str(path))
|
|
127
|
+
instance = wasmtime.Instance(self._store, module, [])
|
|
128
|
+
exports = {e[0]: e[1] for e in instance.exports(self._store).items()}
|
|
129
|
+
for name in (
|
|
130
|
+
"active_alloc",
|
|
131
|
+
"active_eval_json",
|
|
132
|
+
"active_free",
|
|
133
|
+
"active_abi_version",
|
|
134
|
+
):
|
|
135
|
+
if name not in exports:
|
|
136
|
+
raise ActiveError(f"module missing export: {name}")
|
|
137
|
+
self._alloc = exports["active_alloc"]
|
|
138
|
+
self._eval = exports["active_eval_json"]
|
|
139
|
+
self._free = exports["active_free"]
|
|
140
|
+
self._mem = instance.exports(self._store)["memory"]
|
|
141
|
+
major = exports["active_abi_version"](self._store)
|
|
142
|
+
if major != ABI_MAJOR:
|
|
143
|
+
raise ActiveError(
|
|
144
|
+
f"ABI major mismatch: module reports {major}, "
|
|
145
|
+
f"binding expects {ABI_MAJOR}"
|
|
146
|
+
)
|
|
147
|
+
self._closed = False
|
|
148
|
+
|
|
149
|
+
def __enter__(self) -> Module:
|
|
150
|
+
return self
|
|
151
|
+
|
|
152
|
+
def __exit__(self, *exc: object) -> None:
|
|
153
|
+
self.close()
|
|
154
|
+
|
|
155
|
+
def close(self) -> None:
|
|
156
|
+
self._closed = True
|
|
157
|
+
|
|
158
|
+
def _write(self, data: bytes) -> tuple[int, int]:
|
|
159
|
+
if self._closed:
|
|
160
|
+
raise ActiveError("module is closed")
|
|
161
|
+
ptr = self._alloc(self._store, len(data))
|
|
162
|
+
self._mem.write(self._store, data, ptr)
|
|
163
|
+
return ptr, len(data)
|
|
164
|
+
|
|
165
|
+
def _read(self, ptr: int, size: int) -> bytes:
|
|
166
|
+
# wasmtime read(store, start, stop) returns the byte range.
|
|
167
|
+
try:
|
|
168
|
+
return bytes(self._mem.read(self._store, ptr, ptr + size))
|
|
169
|
+
except Exception as e:
|
|
170
|
+
raise ActiveError(f"memory read failed: {e}") from e
|
|
171
|
+
|
|
172
|
+
def _u32(self, ptr: int) -> int:
|
|
173
|
+
try:
|
|
174
|
+
return int.from_bytes(self._read(ptr, 4), "little")
|
|
175
|
+
except ActiveError:
|
|
176
|
+
raise
|
|
177
|
+
except Exception as e:
|
|
178
|
+
raise ActiveError(f"length slot unreadable: {e}") from e
|
|
179
|
+
|
|
180
|
+
def _call_eval(self, source: str) -> dict:
|
|
181
|
+
src = source.encode("utf-8")
|
|
182
|
+
# Pointers start null so the finally below frees exactly what was
|
|
183
|
+
# allocated: if _write raises (closed module), there is no module
|
|
184
|
+
# allocation to free and no UnboundLocalError masks the real error.
|
|
185
|
+
sptr: int | None = None
|
|
186
|
+
sn: int = 0
|
|
187
|
+
slot: int | None = None
|
|
188
|
+
res: int = 0
|
|
189
|
+
env_len: int = 0
|
|
190
|
+
try:
|
|
191
|
+
sptr, sn = self._write(src)
|
|
192
|
+
slot, _ = self._write(b"\x00" * 4)
|
|
193
|
+
try:
|
|
194
|
+
res = self._eval(self._store, sptr, sn, slot)
|
|
195
|
+
except Exception as e:
|
|
196
|
+
# wasmtime traps (OOM, stack exhaustion) surface as the
|
|
197
|
+
# binding's own error type, never a bare host exception.
|
|
198
|
+
raise ActiveError(f"evaluation trapped: {e}") from e
|
|
199
|
+
try:
|
|
200
|
+
env_len = self._u32(slot)
|
|
201
|
+
raw = self._read(res, env_len)
|
|
202
|
+
finally:
|
|
203
|
+
# Registry-backed free is size-agnostic; a zero length
|
|
204
|
+
# here only means the length slot itself was unreadable.
|
|
205
|
+
self._free(self._store, res, env_len)
|
|
206
|
+
try:
|
|
207
|
+
env = json.loads(raw)
|
|
208
|
+
except Exception as e:
|
|
209
|
+
raise ActiveError(f"envelope is not JSON: {e}") from e
|
|
210
|
+
if not isinstance(env, dict):
|
|
211
|
+
raise ActiveError("envelope is not an object")
|
|
212
|
+
return env
|
|
213
|
+
finally:
|
|
214
|
+
if sptr is not None:
|
|
215
|
+
self._free(self._store, sptr, sn)
|
|
216
|
+
if slot is not None:
|
|
217
|
+
self._free(self._store, slot, 4)
|
|
218
|
+
|
|
219
|
+
def check(self, source: str) -> list[Diagnostic]:
|
|
220
|
+
"""Parse and evaluate; return structured diagnostics (empty if clean).
|
|
221
|
+
|
|
222
|
+
The module runs the hermetic engine (resilient default), so this
|
|
223
|
+
surfaces errors and repair warnings alike. One Diagnostic per
|
|
224
|
+
envelope item, in core order (no dedup: recovery can legitimately
|
|
225
|
+
repeat a code, and strict hosts compare the full list). Fail closed:
|
|
226
|
+
an envelope without items is a version-skewed module, never a
|
|
227
|
+
clean bill — returning [] here would be a false clean.
|
|
228
|
+
"""
|
|
229
|
+
env = self._call_eval(source)
|
|
230
|
+
if not isinstance(env.get("items"), list):
|
|
231
|
+
raise ActiveError("envelope without items: rebuild active_wasm.wasm")
|
|
232
|
+
text = env.get("diagnostics", "") or ""
|
|
233
|
+
out = []
|
|
234
|
+
for item in env["items"]:
|
|
235
|
+
if not isinstance(item, dict) or not item.get("code"):
|
|
236
|
+
# A code-less item is envelope corruption, not a clean
|
|
237
|
+
# diagnostic: fail closed instead of emitting an empty code.
|
|
238
|
+
raise ActiveError("envelope item without code")
|
|
239
|
+
span = item.get("span")
|
|
240
|
+
if span is not None and not isinstance(span, dict):
|
|
241
|
+
raise ActiveError("envelope item with bad span")
|
|
242
|
+
span = span or {}
|
|
243
|
+
out.append(
|
|
244
|
+
Diagnostic(
|
|
245
|
+
item["code"],
|
|
246
|
+
item.get("message") or text,
|
|
247
|
+
line=span.get("line"),
|
|
248
|
+
column=span.get("column"),
|
|
249
|
+
end_line=span.get("end_line"),
|
|
250
|
+
end_column=span.get("end_column"),
|
|
251
|
+
severity=item.get("severity"),
|
|
252
|
+
)
|
|
253
|
+
)
|
|
254
|
+
return out
|
|
255
|
+
|
|
256
|
+
def validate(self, source: str) -> list[Diagnostic]:
|
|
257
|
+
"""Validation step of the agent loop: the hermetic verdict.
|
|
258
|
+
|
|
259
|
+
Returns the same structured diagnostics as check(): on this
|
|
260
|
+
embedding the hermetic engine validates during evaluation, so
|
|
261
|
+
check (diagnose) and validate (verify) share one verdict path
|
|
262
|
+
and must always agree — the differential harness pins that.
|
|
263
|
+
|
|
264
|
+
Budgets, three layers, all fail-closed:
|
|
265
|
+
* iteration budget: enforced by the caller (reference loops pass
|
|
266
|
+
max_iters and stop on stuck codes);
|
|
267
|
+
* engine budgets: the hermetic engine ships hard defaults
|
|
268
|
+
(nodes, depth, array length, wall clock); exceeding them
|
|
269
|
+
refuses instead of truncating;
|
|
270
|
+
* custom per-call budgets: not a parameter here by design. The
|
|
271
|
+
zero-import WASM module runs fixed hermetic defaults so every
|
|
272
|
+
host sees identical verdicts. Hosts that need custom budgets
|
|
273
|
+
drive the C ABI surface (active_check with ActiveBudget),
|
|
274
|
+
which is the same core with a budget pointer.
|
|
275
|
+
"""
|
|
276
|
+
return self.check(source)
|
|
277
|
+
|
|
278
|
+
def eval(self, source: str) -> dict:
|
|
279
|
+
"""Evaluate and return the redacted JSON value (raises on refusal).
|
|
280
|
+
|
|
281
|
+
A malformed ok:true envelope (missing or non-dict value) raises
|
|
282
|
+
instead of returning a plausible-looking empty dict.
|
|
283
|
+
"""
|
|
284
|
+
env = self._call_eval(source)
|
|
285
|
+
if not env.get("ok", False):
|
|
286
|
+
raise ActiveError(f"refused: {env.get('diagnostics', '')[:200]}")
|
|
287
|
+
value = env.get("json")
|
|
288
|
+
if not isinstance(value, dict):
|
|
289
|
+
raise ActiveError("envelope ok without a JSON object value")
|
|
290
|
+
return value
|
active.pyi
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Type stubs for the Active Python binding (Phase A, PROPOSAL §1.2).
|
|
2
|
+
|
|
3
|
+
Mirrors bindings/python/active.py exactly: same public functions,
|
|
4
|
+
classes, methods, and signatures. test_active.py::test_stub_matches_runtime
|
|
5
|
+
pins the mapping (names, arity, and defaults); keep both files in sync.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
ABI_MAJOR: int
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def default_wasm_path() -> Path: ...
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ActiveError(Exception): ...
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Diagnostic:
|
|
21
|
+
code: str
|
|
22
|
+
message: str
|
|
23
|
+
line: int | None
|
|
24
|
+
column: int | None
|
|
25
|
+
end_line: int | None
|
|
26
|
+
end_column: int | None
|
|
27
|
+
severity: str | None
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
code: str,
|
|
31
|
+
message: str,
|
|
32
|
+
line: int | None = ...,
|
|
33
|
+
column: int | None = ...,
|
|
34
|
+
end_line: int | None = ...,
|
|
35
|
+
end_column: int | None = ...,
|
|
36
|
+
severity: str | None = ...,
|
|
37
|
+
) -> None: ...
|
|
38
|
+
def span(self) -> tuple[int, int, int, int] | None: ...
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Module:
|
|
42
|
+
def __init__(self, wasm_path: Path | str | None = ...) -> None: ...
|
|
43
|
+
def __enter__(self) -> Module: ...
|
|
44
|
+
def __exit__(self, *exc: object) -> None: ...
|
|
45
|
+
def close(self) -> None: ...
|
|
46
|
+
def check(self, source: str) -> list[Diagnostic]: ...
|
|
47
|
+
def validate(self, source: str) -> list[Diagnostic]: ...
|
|
48
|
+
def eval(self, source: str) -> dict: ...
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: active-lang
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: Active: explicit, deterministic, hermetic configuration language (WASM-first Python binding)
|
|
5
|
+
Project-URL: Homepage, https://github.com/Active-Official/active
|
|
6
|
+
Project-URL: Repository, https://github.com/Active-Official/active
|
|
7
|
+
Project-URL: Documentation, https://github.com/Active-Official/active
|
|
8
|
+
Author: Active Language Team
|
|
9
|
+
License: MIT OR Apache-2.0
|
|
10
|
+
Keywords: agents,config,configuration,language,wasm
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Requires-Dist: wasmtime<50,>=47
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Active Python Binding — WASM-first (CHECKLIST 1.004-1.006, PROPOSAL §2.1, §2.3)
|
|
20
|
+
|
|
21
|
+
Zero native compilation. The binding drives the zero-import
|
|
22
|
+
`active_wasm.wasm` module through `wasmtime` (pip-installable, no compiler
|
|
23
|
+
needed) and exposes the agent-loop surface with opaque handles, an ABI
|
|
24
|
+
major gate, and Allocator Model A (the module's `active_free` frees
|
|
25
|
+
everything the module allocated).
|
|
26
|
+
|
|
27
|
+
## Decision (DERIVED, owner authority)
|
|
28
|
+
|
|
29
|
+
WASM-first instead of cffi/PyO3: no per-platform wheels, no compiler on the
|
|
30
|
+
user machine, identical semantics to every other embedding by construction.
|
|
31
|
+
A native extension remains an option if profiling ever justifies it; nothing
|
|
32
|
+
in this layout precludes adding one later behind the same API.
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from active import Module
|
|
38
|
+
|
|
39
|
+
with Module() as m: # or Module(path_to_wasm)
|
|
40
|
+
diags = m.check(source) # [Diagnostic(code, message)]
|
|
41
|
+
value = m.eval(source) # redacted dict, raises on refusal
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`Module` instances are confined to the creating thread. `check` returns
|
|
45
|
+
`[]` when clean. `eval` raises `ActiveError` on refusal with the
|
|
46
|
+
diagnostics text. Secrets always render `***SECRET***`.
|
|
47
|
+
|
|
48
|
+
## Tests
|
|
49
|
+
|
|
50
|
+
`test_active.py` drives the shipped module: ABI gate, eval value, units
|
|
51
|
+
refusal with stable code T001, secret redaction with no raw leak (including
|
|
52
|
+
refusal paths), closed-module fail-closed behavior on every entry point,
|
|
53
|
+
double-eval determinism, structured spans on diagnostics, `validate`/`check`
|
|
54
|
+
agreement, and `.pyi` stub fidelity to the runtime API (9 tests green).
|
|
55
|
+
Run from the repo root:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
python bindings/python/test_active.py
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Requires `wasmtime` (`pip install wasmtime`) and a built module
|
|
62
|
+
(`cargo build -p active-wasm --target wasm32-unknown-unknown --release`).
|
|
63
|
+
|
|
64
|
+
## Ownership and lifetime (normative for this binding)
|
|
65
|
+
|
|
66
|
+
- **Opaque handles:** a `Module` owns exactly one wasmtime instance. One `Module` per thread; never share a module across threads, with or without locking. The underlying engine state (including the module's live-buffer registry) is thread-confined by construction, so sharing would corrupt frees even under a lock.
|
|
67
|
+
- **Allocator Model A:** every allocation the module makes is freed inside the module through the official `active_free` export. The host never frees module memory with any other function, and module memory is never exposed as writable host buffers beyond the single input copy per call.
|
|
68
|
+
- **ABI gate:** `Module()` construction reads `active_abi_version` and raises `ActiveError` unless the major version is 1. A stale or foreign `.wasm` cannot be used silently.
|
|
69
|
+
- **Error mapping:** evaluation refusal surfaces as `ActiveError` (never a bare `None` or an empty dict); a missing module or envelope-shape mismatch also raises `ActiveError`, so misuse fails loudly instead of returning plausible-looking data.
|
|
70
|
+
- **Close discipline:** use the module as a context manager or call `close()` explicitly. Using a closed module raises `ActiveError`.
|
|
71
|
+
- **Budgets:** the module runs the hermetic engine with shipped hard budgets (fail-closed on exhaustion). `validate()` is the explicit validation step of the agent loop and shares `check()`'s verdict path; the reference loops additionally enforce an iteration budget (`max_iters`) with stuck-loop detection. Hosts that need custom per-call budgets drive the C ABI surface (`active_check` with `ActiveBudget`), which is the same core with a budget pointer.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE-APACHE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
2
|
+
LICENSE-MIT,sha256=oos4W1ActgAo4-XejlkTtsXg8QD1bsDlNHQCr-4QJOI,1084
|
|
3
|
+
active.py,sha256=pU2asSCj-t4WqUtYzT-45oc1FqIUQj9Q8UlXVj1tLec,11412
|
|
4
|
+
active.pyi,sha256=dYfTCxU9p4D4zRMb2QV0pu_DDJSQfnxshKG7v0sgZBM,1282
|
|
5
|
+
active_lang-1.4.0.dist-info/METADATA,sha256=UDeJH6_Pa3KlK5WXoll-0w1lrc2SUfMkorg6gFhcqjU,4251
|
|
6
|
+
active_lang-1.4.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
7
|
+
active_lang-1.4.0.dist-info/RECORD,,
|