open-refinery 0.1.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.
- open_refinery/__init__.py +22 -0
- open_refinery/audit.py +35 -0
- open_refinery/authz.py +30 -0
- open_refinery/cli.py +33 -0
- open_refinery/factory.py +73 -0
- open_refinery/provenance.py +44 -0
- open_refinery-0.1.0.dist-info/METADATA +94 -0
- open_refinery-0.1.0.dist-info/RECORD +11 -0
- open_refinery-0.1.0.dist-info/WHEEL +4 -0
- open_refinery-0.1.0.dist-info/entry_points.txt +2 -0
- open_refinery-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""open-refinery — a factory for producing artifacts under governance."""
|
|
2
|
+
|
|
3
|
+
from .audit import AuditSink, JsonlSink, MemorySink
|
|
4
|
+
from .authz import AllowAll, AllowList, Authorizer, Unauthorized
|
|
5
|
+
from .factory import Factory, UnknownRecipe
|
|
6
|
+
from .provenance import Record
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Factory",
|
|
12
|
+
"UnknownRecipe",
|
|
13
|
+
"Record",
|
|
14
|
+
"Authorizer",
|
|
15
|
+
"AllowAll",
|
|
16
|
+
"AllowList",
|
|
17
|
+
"Unauthorized",
|
|
18
|
+
"AuditSink",
|
|
19
|
+
"MemorySink",
|
|
20
|
+
"JsonlSink",
|
|
21
|
+
"__version__",
|
|
22
|
+
]
|
open_refinery/audit.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Audit sink — append-only trail of production events."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Protocol
|
|
8
|
+
|
|
9
|
+
from .provenance import Record
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AuditSink(Protocol):
|
|
13
|
+
def write(self, record: Record) -> None: ...
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class MemorySink:
|
|
17
|
+
"""In-memory trail. Default; useful for tests and ephemeral runs."""
|
|
18
|
+
|
|
19
|
+
def __init__(self) -> None:
|
|
20
|
+
self.records: list[Record] = []
|
|
21
|
+
|
|
22
|
+
def write(self, record: Record) -> None:
|
|
23
|
+
self.records.append(record)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class JsonlSink:
|
|
27
|
+
"""Append each record as one JSON line. The durable audit trail."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, path: str | Path) -> None:
|
|
30
|
+
self.path = Path(path)
|
|
31
|
+
self.path.parent.mkdir(parents=True, exist_ok=True)
|
|
32
|
+
|
|
33
|
+
def write(self, record: Record) -> None:
|
|
34
|
+
with self.path.open("a", encoding="utf-8") as fh:
|
|
35
|
+
fh.write(json.dumps(record.to_dict(), sort_keys=True) + "\n")
|
open_refinery/authz.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Authorization — the gate checked before a recipe runs."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Unauthorized(Exception):
|
|
9
|
+
"""Raised when an actor may not run a recipe."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Authorizer(Protocol):
|
|
13
|
+
def allows(self, actor: str, recipe: str) -> bool: ...
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AllowAll:
|
|
17
|
+
"""Default authorizer — permits every actor. Replace in production."""
|
|
18
|
+
|
|
19
|
+
def allows(self, actor: str, recipe: str) -> bool:
|
|
20
|
+
return True
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AllowList:
|
|
24
|
+
"""Permit only (actor, recipe) pairs present in the grant set."""
|
|
25
|
+
|
|
26
|
+
def __init__(self, grants: set[tuple[str, str]]) -> None:
|
|
27
|
+
self._grants = grants
|
|
28
|
+
|
|
29
|
+
def allows(self, actor: str, recipe: str) -> bool:
|
|
30
|
+
return (actor, recipe) in self._grants
|
open_refinery/cli.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Demo CLI — produces one artifact and prints its provenance record."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import logging
|
|
8
|
+
|
|
9
|
+
from .factory import Factory
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def main(argv: list[str] | None = None) -> int:
|
|
13
|
+
parser = argparse.ArgumentParser(prog="open-refinery")
|
|
14
|
+
parser.add_argument("--actor", default="demo-user")
|
|
15
|
+
parser.add_argument("--text", default="hello", help="text to refine")
|
|
16
|
+
args = parser.parse_args(argv)
|
|
17
|
+
|
|
18
|
+
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
|
19
|
+
|
|
20
|
+
factory = Factory()
|
|
21
|
+
|
|
22
|
+
@factory.recipe("upper")
|
|
23
|
+
def upper(text: str) -> str:
|
|
24
|
+
return text.upper()
|
|
25
|
+
|
|
26
|
+
artifact, record = factory.produce("upper", actor=args.actor, text=args.text)
|
|
27
|
+
print(f"artifact: {artifact!r}")
|
|
28
|
+
print(json.dumps(record.to_dict(), indent=2, sort_keys=True))
|
|
29
|
+
return 0
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if __name__ == "__main__":
|
|
33
|
+
raise SystemExit(main())
|
open_refinery/factory.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Factory — produces artifacts, wrapping each output in governance."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
from .audit import AuditSink, MemorySink
|
|
9
|
+
from .authz import AllowAll, Authorizer, Unauthorized
|
|
10
|
+
from .provenance import Record
|
|
11
|
+
|
|
12
|
+
log = logging.getLogger("open_refinery")
|
|
13
|
+
|
|
14
|
+
Recipe = Callable[..., object]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class UnknownRecipe(KeyError):
|
|
18
|
+
"""Raised when producing from an unregistered recipe."""
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Factory:
|
|
22
|
+
"""Registers recipes and produces artifacts under governance.
|
|
23
|
+
|
|
24
|
+
Every ``produce`` call is authorized, run, recorded with provenance and
|
|
25
|
+
ownership, and appended to the audit trail — in that order.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def __init__(
|
|
29
|
+
self,
|
|
30
|
+
authorizer: Authorizer | None = None,
|
|
31
|
+
audit: AuditSink | None = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
self._recipes: dict[str, Recipe] = {}
|
|
34
|
+
self._authorizer = authorizer or AllowAll()
|
|
35
|
+
self._audit = audit or MemorySink()
|
|
36
|
+
|
|
37
|
+
def register(self, name: str, recipe: Recipe) -> None:
|
|
38
|
+
self._recipes[name] = recipe
|
|
39
|
+
|
|
40
|
+
def recipe(self, name: str) -> Callable[[Recipe], Recipe]:
|
|
41
|
+
"""Decorator form of :meth:`register`."""
|
|
42
|
+
|
|
43
|
+
def decorate(fn: Recipe) -> Recipe:
|
|
44
|
+
self.register(name, fn)
|
|
45
|
+
return fn
|
|
46
|
+
|
|
47
|
+
return decorate
|
|
48
|
+
|
|
49
|
+
def produce(
|
|
50
|
+
self,
|
|
51
|
+
name: str,
|
|
52
|
+
*,
|
|
53
|
+
actor: str,
|
|
54
|
+
owner: str | None = None,
|
|
55
|
+
**inputs: object,
|
|
56
|
+
) -> tuple[object, Record]:
|
|
57
|
+
if name not in self._recipes:
|
|
58
|
+
raise UnknownRecipe(name)
|
|
59
|
+
if not self._authorizer.allows(actor, name):
|
|
60
|
+
raise Unauthorized(f"{actor} may not run {name}")
|
|
61
|
+
|
|
62
|
+
owner = owner or actor
|
|
63
|
+
artifact = self._recipes[name](**inputs)
|
|
64
|
+
record = Record.of(name, actor, owner, inputs, artifact)
|
|
65
|
+
self._audit.write(record)
|
|
66
|
+
log.info(
|
|
67
|
+
"produced recipe=%s artifact=%s actor=%s owner=%s",
|
|
68
|
+
name,
|
|
69
|
+
record.artifact_id,
|
|
70
|
+
actor,
|
|
71
|
+
owner,
|
|
72
|
+
)
|
|
73
|
+
return artifact, record
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Provenance record — the governance metadata attached to every produced artifact."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import uuid
|
|
8
|
+
from dataclasses import asdict, dataclass, field
|
|
9
|
+
from datetime import datetime, timezone
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _digest(value: object) -> str:
|
|
13
|
+
"""Stable SHA-256 of any JSON-serializable value; repr fallback for the rest."""
|
|
14
|
+
try:
|
|
15
|
+
payload = json.dumps(value, sort_keys=True, default=repr)
|
|
16
|
+
except TypeError:
|
|
17
|
+
payload = repr(value)
|
|
18
|
+
return hashlib.sha256(payload.encode()).hexdigest()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True)
|
|
22
|
+
class Record:
|
|
23
|
+
"""Immutable provenance for a single production event."""
|
|
24
|
+
|
|
25
|
+
recipe: str
|
|
26
|
+
actor: str
|
|
27
|
+
owner: str
|
|
28
|
+
input_digest: str
|
|
29
|
+
output_digest: str
|
|
30
|
+
artifact_id: str = field(default_factory=lambda: uuid.uuid4().hex)
|
|
31
|
+
created_at: str = field(default_factory=lambda: datetime.now(timezone.utc).isoformat())
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def of(cls, recipe: str, actor: str, owner: str, inputs: dict, output: object) -> Record:
|
|
35
|
+
return cls(
|
|
36
|
+
recipe=recipe,
|
|
37
|
+
actor=actor,
|
|
38
|
+
owner=owner,
|
|
39
|
+
input_digest=_digest(inputs),
|
|
40
|
+
output_digest=_digest(output),
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> dict:
|
|
44
|
+
return asdict(self)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: open-refinery
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A factory for producing artifacts under governance — provenance, ownership, authorization, and an append-only audit trail on every output.
|
|
5
|
+
Project-URL: Homepage, https://github.com/tacoda/open-refinery
|
|
6
|
+
Project-URL: Repository, https://github.com/tacoda/open-refinery
|
|
7
|
+
Author-email: Ian Johnson <ian@tacoda.dev>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: audit,factory,governance,observability,provenance
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# open-refinery
|
|
22
|
+
|
|
23
|
+
A factory for producing artifacts under governance. Every output carries its
|
|
24
|
+
**provenance**, an **owner**, and an **audit trail**; every production is
|
|
25
|
+
**authorized** before it runs and **logged** as it happens.
|
|
26
|
+
|
|
27
|
+
> Status: **0.1.0 — proof of concept.** The core loop (authorize → produce →
|
|
28
|
+
> record → audit) is real and tested. Policy-based governance, richer
|
|
29
|
+
> observability, and pluggable sinks are on the roadmap.
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uv add open-refinery # or: pip install open-refinery
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Use
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from open_refinery import Factory
|
|
41
|
+
|
|
42
|
+
factory = Factory()
|
|
43
|
+
|
|
44
|
+
@factory.recipe("upper")
|
|
45
|
+
def upper(text: str) -> str:
|
|
46
|
+
return text.upper()
|
|
47
|
+
|
|
48
|
+
artifact, record = factory.produce("upper", actor="ian", text="hello")
|
|
49
|
+
# artifact -> "HELLO"
|
|
50
|
+
# record -> Record(recipe="upper", actor="ian", owner="ian",
|
|
51
|
+
# artifact_id=..., input_digest=..., output_digest=..., created_at=...)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Try the demo CLI:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
uv run open-refinery --actor ian --text hello
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Pillars
|
|
61
|
+
|
|
62
|
+
| Pillar | Where it lives |
|
|
63
|
+
|-----------------|-------------------------------------------------------------|
|
|
64
|
+
| Authorization | `Authorizer` (`AllowAll`, `AllowList`) — checked before produce |
|
|
65
|
+
| Provenance | `Record` — recipe, actor, timestamp, input/output digests |
|
|
66
|
+
| Ownership | `owner` on every record (defaults to the actor) |
|
|
67
|
+
| Auditability | `AuditSink` (`MemorySink`, `JsonlSink`) — append-only trail |
|
|
68
|
+
| Logging | stdlib `logging`, logger name `open_refinery` |
|
|
69
|
+
| Observability | *(roadmap)* read-model / metrics over the audit trail |
|
|
70
|
+
| Governance | *(roadmap)* policy layer that constrains what may be produced |
|
|
71
|
+
|
|
72
|
+
## Durable audit trail
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from open_refinery import Factory, JsonlSink
|
|
76
|
+
|
|
77
|
+
factory = Factory(audit=JsonlSink("audit.jsonl"))
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Each production appends one JSON line — a replayable record of who produced
|
|
81
|
+
what, from which inputs, and when.
|
|
82
|
+
|
|
83
|
+
## Development
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
uv sync --extra dev
|
|
87
|
+
uv run pytest
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) and [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
[MIT](LICENSE) © Ian Johnson
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
open_refinery/__init__.py,sha256=lhwREQ2MS0Z3p2SaErwp1KD2OpB_Rkn4TwfKmAbwMys,499
|
|
2
|
+
open_refinery/audit.py,sha256=NpK-qR6qxmgeHty5I625v2qhyGVVSuDve22bFouetdc,932
|
|
3
|
+
open_refinery/authz.py,sha256=IrB40i0pB2BjAA241QoEhEvUKuTho0mRokVLQ_oojy0,759
|
|
4
|
+
open_refinery/cli.py,sha256=9ibkkGsxvZ9Jx2hlHj74wRWpUMiwW5XA0AdXhDH68zI,899
|
|
5
|
+
open_refinery/factory.py,sha256=N9LoFo67cIB9Ko6WGnbICjGSYvITdBqIW1qmlYkjHY0,2055
|
|
6
|
+
open_refinery/provenance.py,sha256=-p-fbdr_X9CB98Z4uY5OXYftl6K5Zi-7JCX74Z_3y9k,1280
|
|
7
|
+
open_refinery-0.1.0.dist-info/METADATA,sha256=2QsF_tLAjbNhE3qCqg4Ak_UCj4GUII4iEa5hI6ufrdE,3067
|
|
8
|
+
open_refinery-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
9
|
+
open_refinery-0.1.0.dist-info/entry_points.txt,sha256=_zQm8vxboggTwoCl26M0_WAqcMU5EmcT7nZrGFTYaSU,57
|
|
10
|
+
open_refinery-0.1.0.dist-info/licenses/LICENSE,sha256=letU8CJjd8PcS8eMmUx6RVzrmzVEaYmFmtRtuJVrKHI,1068
|
|
11
|
+
open_refinery-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ian Johnson
|
|
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.
|