factoryhub 0.1.2__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.
@@ -0,0 +1,19 @@
1
+ node_modules/
2
+ # Cargo's build output.
3
+ /target/
4
+ .venv/
5
+ __pycache__/
6
+ *.pyc
7
+ .DS_Store
8
+ coverage/
9
+ *.tgz
10
+
11
+ # Written by local runs and packs.
12
+ *.receipt.json
13
+ author-test-results.json
14
+ /*.zip
15
+ /*.bundle.json
16
+
17
+ # The Python SDK: a library, so no lock file.
18
+ python/uv.lock
19
+ python/dist/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,16 @@
1
+ factoryhub
2
+ Copyright Mindburn Labs
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (LICENSE),
5
+ with two exceptions:
6
+
7
+ - The factories in factories/ each declare their own license in their
8
+ flow.yaml. The eight house factories declare MIT.
9
+ - The ClawHub skill files in integrations/openclaw/factoryhub/ (SKILL.md and
10
+ README.md) are released under MIT No Attribution (MIT-0), because ClawHub
11
+ publishes every skill under MIT-0. Their README holds the license text.
12
+
13
+ The factoryhub name and the artwork in assets/ (and its copy in
14
+ integrations/claude-code-plugin/assets/) identify this project. As
15
+ section 6 of the Apache License says, the license grants no permission to use
16
+ them except to describe where the work comes from.
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.4
2
+ Name: factoryhub
3
+ Version: 0.1.2
4
+ Summary: Share and run AI factories from Python: log in, push, pull, publish and run factories on factoryhub, and verify run receipts offline.
5
+ Project-URL: Homepage, https://factory.mindburn.org
6
+ Project-URL: Source, https://github.com/Mindburn-Labs/factoryhub2/tree/main/python
7
+ Project-URL: Support, https://mindburn.org/contact/
8
+ Author: Mindburn Labs
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ License-File: NOTICE
12
+ Keywords: ai-agents,ai-factories,ed25519,factoryhub,human-in-the-loop,receipts
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: cryptography>=42
21
+ Description-Content-Type: text/markdown
22
+
23
+ # factoryhub for Python
24
+
25
+ Share and run AI factories from Python: log in to factoryhub, push a factory
26
+ folder to your account, pull any factory you can open, publish yours, run
27
+ factories on factoryhub, and verify run receipts offline.
28
+
29
+ ```sh
30
+ pip install factoryhub
31
+ ```
32
+
33
+ ```python
34
+ import factoryhub
35
+
36
+ factoryhub.login() # shows a code; approve it in your browser
37
+ saved = factoryhub.push("my-factory") # private to your account
38
+ print(saved["factory"]["id"], saved["factory"]["url"])
39
+
40
+ pulled = factoryhub.pull("meeting-to-actions", dir="meeting") # every file hash-checked
41
+ outcome = factoryhub.run("meeting-to-actions", {"notes": open("notes.txt").read()})
42
+ if outcome["status"] == "done":
43
+ outcome["result"].save("follow-up.md") # and follow-up.receipt.json
44
+ print(outcome["result"].verification.valid)
45
+
46
+ check = factoryhub.verify_receipt("follow-up.receipt.json", deliverable=open("follow-up.md").read())
47
+ print(check.valid, check.problems)
48
+ ```
49
+
50
+ ## What each call does
51
+
52
+ | Call | What it does | Needs |
53
+ | --- | --- | --- |
54
+ | `login()` | Device login: prints a code and a page, returns once you approve. `login(token=...)` checks and saves a token instead. | — |
55
+ | `logout()` | Revokes the saved token on factoryhub, then forgets it. | — |
56
+ | `whoami()` | The account and the token's name, scopes and expiry. | any token |
57
+ | `push(folder, parent=None)` | Saves a factory folder privately. Nothing is published. | `factories:write` |
58
+ | `pull(id, dir=None, force=False, partial=False)` | Downloads a factory, checking every file's SHA-256 and the files together against the bundle hash in the hub's answer. A bundle that cannot be checked whole is refused unless `partial=True`. | `factories:read` for your private ones |
59
+ | `publish(id, note="")` | Publishes your factory: anyone can find and run it at once. | `factories:publish` (opt-in) |
60
+ | `run(id, inputs, on_event=None, on_decision=None)` | Runs a factory on factoryhub and follows it. | `runs:start`, `runs:read` |
61
+ | `follow_run(run_id, after=0, on_event=None)` | Follows an existing run until it finishes or waits for you. | `runs:read` |
62
+ | `runs(limit=None)` | Your recent hosted runs. | `runs:read` |
63
+ | `verify_receipt(receipt, keys=None, deliverable=None)` | Checks a receipt's Ed25519 signature; offline when you pass `keys`. | — |
64
+
65
+ `Hub(base_url=..., token=..., access_key=...)` keeps one connection with the
66
+ same methods.
67
+
68
+ ## Tokens
69
+
70
+ The token comes from, in order: `token=`, `FACTORYHUB_TOKEN`, or the login
71
+ saved in `${XDG_CONFIG_HOME:-~/.config}/factoryhub/credentials.json`. The
72
+ factoryhub CLI uses the same file, so `factoryhub login` in a terminal works
73
+ here too. On macOS and Linux the file is written with mode 0600, and one
74
+ other users can read is refused; on Windows no permissions are set, so it is
75
+ as private as your user folder. `FACTORYHUB_TOKEN` is sent only to
76
+ https://factory.mindburn.org or to the hub `FACTORYHUB_BASE_URL` names. A
77
+ token is sent only in the `Authorization` header, only over https (or http
78
+ to this machine), and never printed; one that is not shaped like a token is
79
+ refused before any request. Redirects are followed only within the hub, so
80
+ neither the token nor the preview key reaches another site.
81
+
82
+ A later `login()` revokes the token an earlier device login saved. A token
83
+ you passed in with `login(token=...)` is never revoked for you: it may be in
84
+ use elsewhere.
85
+
86
+ While factoryhub is in private preview, every request also needs the access
87
+ key you were given, in `FACTORYHUB_ACCESS_KEY`.
88
+
89
+ ## Decisions stay yours
90
+
91
+ A factory can stop at a step for a person's approval. `run()` never decides
92
+ for you: at such a step it calls `on_decision(waiting)` with the exact text,
93
+ and sends only what that function returns, the person's own
94
+ `{"decision": "approve" | "revise" | "reject", "note": "..."}`. Return
95
+ `None`, or pass no `on_decision`, and the run waits; decide on its page.
96
+ When the hub sent only part of the text (`waiting["complete"]` is not
97
+ `True`), an approval is refused: read and decide on the run page. Sending a
98
+ decision needs a token with the opt-in `runs:decide` scope.
99
+
100
+ Keep the run ID and the last event index (`event["i"]`) you processed. After
101
+ a disconnect, pass that index as `after` to `follow_run`. If a previous follow
102
+ returned while waiting, use its `cursor` to follow again after the decision
103
+ on the run page. The Hub returns at most the latest 60 events per read.
104
+
105
+ ## Receipts
106
+
107
+ A hosted run's receipt is signed with Ed25519 over the canonical JSON of the
108
+ receipt (keys sorted, JavaScript number and string forms, as RFC 8785
109
+ describes). `verify_receipt` runs the same checks as the factoryhub engine,
110
+ with the same messages, and both are tested against the same fixtures in
111
+ [`test/fixtures/sdk`](https://github.com/Mindburn-Labs/factoryhub2/tree/main/test/fixtures/sdk).
112
+ With `keys`, it checks against exactly those. Without, it checks the receipt
113
+ as one from the hub at `base_url`: from https://factory.mindburn.org only
114
+ against the production keys pinned in this package (`verification.trust ==
115
+ "pinned"`), from any other hub against the keys it publishes at
116
+ `/.well-known/factory-hub-keys.json` (`"published"`), and its `issuer`
117
+ against the hub's host either way. `verification.verdict` says which.
118
+
119
+ A pulled bundle's hashes prove the files arrived as the hub answered; they
120
+ are not a signature and do not prove who wrote the factory.
121
+
122
+ ## Develop
123
+
124
+ ```sh
125
+ cd python
126
+ uv run --python 3.12 python -m unittest discover -s tests
127
+ ```
128
+
129
+ The tests start a stand-in factoryhub on localhost; they never reach the
130
+ network or a model.
131
+
132
+ ## License
133
+
134
+ Apache-2.0.
@@ -0,0 +1,112 @@
1
+ # factoryhub for Python
2
+
3
+ Share and run AI factories from Python: log in to factoryhub, push a factory
4
+ folder to your account, pull any factory you can open, publish yours, run
5
+ factories on factoryhub, and verify run receipts offline.
6
+
7
+ ```sh
8
+ pip install factoryhub
9
+ ```
10
+
11
+ ```python
12
+ import factoryhub
13
+
14
+ factoryhub.login() # shows a code; approve it in your browser
15
+ saved = factoryhub.push("my-factory") # private to your account
16
+ print(saved["factory"]["id"], saved["factory"]["url"])
17
+
18
+ pulled = factoryhub.pull("meeting-to-actions", dir="meeting") # every file hash-checked
19
+ outcome = factoryhub.run("meeting-to-actions", {"notes": open("notes.txt").read()})
20
+ if outcome["status"] == "done":
21
+ outcome["result"].save("follow-up.md") # and follow-up.receipt.json
22
+ print(outcome["result"].verification.valid)
23
+
24
+ check = factoryhub.verify_receipt("follow-up.receipt.json", deliverable=open("follow-up.md").read())
25
+ print(check.valid, check.problems)
26
+ ```
27
+
28
+ ## What each call does
29
+
30
+ | Call | What it does | Needs |
31
+ | --- | --- | --- |
32
+ | `login()` | Device login: prints a code and a page, returns once you approve. `login(token=...)` checks and saves a token instead. | — |
33
+ | `logout()` | Revokes the saved token on factoryhub, then forgets it. | — |
34
+ | `whoami()` | The account and the token's name, scopes and expiry. | any token |
35
+ | `push(folder, parent=None)` | Saves a factory folder privately. Nothing is published. | `factories:write` |
36
+ | `pull(id, dir=None, force=False, partial=False)` | Downloads a factory, checking every file's SHA-256 and the files together against the bundle hash in the hub's answer. A bundle that cannot be checked whole is refused unless `partial=True`. | `factories:read` for your private ones |
37
+ | `publish(id, note="")` | Publishes your factory: anyone can find and run it at once. | `factories:publish` (opt-in) |
38
+ | `run(id, inputs, on_event=None, on_decision=None)` | Runs a factory on factoryhub and follows it. | `runs:start`, `runs:read` |
39
+ | `follow_run(run_id, after=0, on_event=None)` | Follows an existing run until it finishes or waits for you. | `runs:read` |
40
+ | `runs(limit=None)` | Your recent hosted runs. | `runs:read` |
41
+ | `verify_receipt(receipt, keys=None, deliverable=None)` | Checks a receipt's Ed25519 signature; offline when you pass `keys`. | — |
42
+
43
+ `Hub(base_url=..., token=..., access_key=...)` keeps one connection with the
44
+ same methods.
45
+
46
+ ## Tokens
47
+
48
+ The token comes from, in order: `token=`, `FACTORYHUB_TOKEN`, or the login
49
+ saved in `${XDG_CONFIG_HOME:-~/.config}/factoryhub/credentials.json`. The
50
+ factoryhub CLI uses the same file, so `factoryhub login` in a terminal works
51
+ here too. On macOS and Linux the file is written with mode 0600, and one
52
+ other users can read is refused; on Windows no permissions are set, so it is
53
+ as private as your user folder. `FACTORYHUB_TOKEN` is sent only to
54
+ https://factory.mindburn.org or to the hub `FACTORYHUB_BASE_URL` names. A
55
+ token is sent only in the `Authorization` header, only over https (or http
56
+ to this machine), and never printed; one that is not shaped like a token is
57
+ refused before any request. Redirects are followed only within the hub, so
58
+ neither the token nor the preview key reaches another site.
59
+
60
+ A later `login()` revokes the token an earlier device login saved. A token
61
+ you passed in with `login(token=...)` is never revoked for you: it may be in
62
+ use elsewhere.
63
+
64
+ While factoryhub is in private preview, every request also needs the access
65
+ key you were given, in `FACTORYHUB_ACCESS_KEY`.
66
+
67
+ ## Decisions stay yours
68
+
69
+ A factory can stop at a step for a person's approval. `run()` never decides
70
+ for you: at such a step it calls `on_decision(waiting)` with the exact text,
71
+ and sends only what that function returns, the person's own
72
+ `{"decision": "approve" | "revise" | "reject", "note": "..."}`. Return
73
+ `None`, or pass no `on_decision`, and the run waits; decide on its page.
74
+ When the hub sent only part of the text (`waiting["complete"]` is not
75
+ `True`), an approval is refused: read and decide on the run page. Sending a
76
+ decision needs a token with the opt-in `runs:decide` scope.
77
+
78
+ Keep the run ID and the last event index (`event["i"]`) you processed. After
79
+ a disconnect, pass that index as `after` to `follow_run`. If a previous follow
80
+ returned while waiting, use its `cursor` to follow again after the decision
81
+ on the run page. The Hub returns at most the latest 60 events per read.
82
+
83
+ ## Receipts
84
+
85
+ A hosted run's receipt is signed with Ed25519 over the canonical JSON of the
86
+ receipt (keys sorted, JavaScript number and string forms, as RFC 8785
87
+ describes). `verify_receipt` runs the same checks as the factoryhub engine,
88
+ with the same messages, and both are tested against the same fixtures in
89
+ [`test/fixtures/sdk`](https://github.com/Mindburn-Labs/factoryhub2/tree/main/test/fixtures/sdk).
90
+ With `keys`, it checks against exactly those. Without, it checks the receipt
91
+ as one from the hub at `base_url`: from https://factory.mindburn.org only
92
+ against the production keys pinned in this package (`verification.trust ==
93
+ "pinned"`), from any other hub against the keys it publishes at
94
+ `/.well-known/factory-hub-keys.json` (`"published"`), and its `issuer`
95
+ against the hub's host either way. `verification.verdict` says which.
96
+
97
+ A pulled bundle's hashes prove the files arrived as the hub answered; they
98
+ are not a signature and do not prove who wrote the factory.
99
+
100
+ ## Develop
101
+
102
+ ```sh
103
+ cd python
104
+ uv run --python 3.12 python -m unittest discover -s tests
105
+ ```
106
+
107
+ The tests start a stand-in factoryhub on localhost; they never reach the
108
+ network or a model.
109
+
110
+ ## License
111
+
112
+ Apache-2.0.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ # Pinned: a release builds with exactly this backend.
3
+ requires = ["hatchling==1.27.0"]
4
+ build-backend = "hatchling.build"
5
+
6
+ [project]
7
+ name = "factoryhub"
8
+ version = "0.1.2"
9
+ description = "Share and run AI factories from Python: log in, push, pull, publish and run factories on factoryhub, and verify run receipts offline."
10
+ readme = "README.md"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE", "NOTICE"]
13
+ requires-python = ">=3.10"
14
+ authors = [{ name = "Mindburn Labs" }]
15
+ keywords = ["factoryhub", "ai-factories", "ai-agents", "human-in-the-loop", "receipts", "ed25519"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Typing :: Typed",
23
+ ]
24
+ # Ed25519 for receipt verification. HTTP uses the standard library.
25
+ dependencies = ["cryptography>=42"]
26
+
27
+ [project.urls]
28
+ Homepage = "https://factory.mindburn.org"
29
+ Source = "https://github.com/Mindburn-Labs/factoryhub2/tree/main/python"
30
+ Support = "https://mindburn.org/contact/"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/factoryhub"]
34
+
35
+ [tool.hatch.build.targets.sdist]
36
+ include = ["src/factoryhub", "README.md", "LICENSE", "NOTICE", "pyproject.toml"]
@@ -0,0 +1,109 @@
1
+ """factoryhub: share and run AI factories from Python.
2
+
3
+ import factoryhub
4
+
5
+ factoryhub.login() # a code you approve in your browser
6
+ saved = factoryhub.push("my-factory") # private to your account
7
+ factoryhub.pull("meeting-to-actions", dir="meeting") # every file checked
8
+ outcome = factoryhub.run("meeting-to-actions", {"notes": "..."})
9
+ factoryhub.verify_receipt("result.receipt.json", deliverable=open("result.md").read())
10
+
11
+ Every function takes ``base_url=``, ``token=`` and ``access_key=``; by default
12
+ they come from FACTORYHUB_BASE_URL, FACTORYHUB_TOKEN (then the saved login,
13
+ shared with the factoryhub CLI) and FACTORYHUB_ACCESS_KEY.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ __version__ = "0.1.2"
19
+
20
+ from pathlib import Path
21
+ from typing import Any, Callable, Iterable, List, Mapping, Optional, Union
22
+
23
+ from ._bundle import bundle_hash, from_envelope, read_folder
24
+ from ._canonical import canonical, sha256
25
+ from .credentials import credentials_path
26
+ from .hub import DEFAULT_HUB, OPT_IN_SCOPES, SCOPES, Hub, HubError, Pulled, RunResult
27
+ from .receipts import Verification, load_receipt, verify_receipt_with_keys
28
+
29
+ __all__ = [
30
+ "DEFAULT_HUB", "OPT_IN_SCOPES", "SCOPES", "Hub", "HubError", "Pulled", "RunResult", "Verification",
31
+ "login", "logout", "whoami", "push", "pull", "publish", "run", "follow_run", "runs", "verify_receipt",
32
+ "canonical", "sha256", "bundle_hash", "from_envelope", "read_folder", "credentials_path", "__version__",
33
+ ]
34
+
35
+
36
+ def _hub(base_url: Optional[str], token: Optional[str], access_key: Optional[str]) -> Hub:
37
+ return Hub(base_url, token=token, access_key=access_key)
38
+
39
+
40
+ def login(token: Optional[str] = None, *, scopes: Optional[Iterable[str]] = None, name: Optional[str] = None, days: Optional[int] = None,
41
+ on_code: Optional[Callable[[dict], None]] = None, save: bool = True, base_url: Optional[str] = None, access_key: Optional[str] = None) -> dict:
42
+ """Logs in by device code (or checks ``token``) and saves the token for the CLI and SDKs."""
43
+ return Hub(base_url, access_key=access_key).login(token, scopes=scopes, name=name, days=days, on_code=on_code, save=save)
44
+
45
+
46
+ def logout(*, base_url: Optional[str] = None, access_key: Optional[str] = None) -> bool:
47
+ """Revokes the saved token on the hub, then forgets it."""
48
+ return Hub(base_url, access_key=access_key).logout()
49
+
50
+
51
+ def whoami(*, base_url: Optional[str] = None, token: Optional[str] = None, access_key: Optional[str] = None) -> dict:
52
+ """The account and token the token acts for."""
53
+ return _hub(base_url, token, access_key).whoami()
54
+
55
+
56
+ def push(source: Union[str, Path, Mapping[str, str]], *, parent: Optional[str] = None, base_url: Optional[str] = None,
57
+ token: Optional[str] = None, access_key: Optional[str] = None) -> dict:
58
+ """Saves a factory folder to your account, privately. Nothing is published."""
59
+ return _hub(base_url, token, access_key).push(source, parent=parent)
60
+
61
+
62
+ def pull(factory_id: str, *, dir: Optional[Union[str, Path]] = None, force: bool = False, partial: bool = False, base_url: Optional[str] = None, # noqa: A002
63
+ token: Optional[str] = None, access_key: Optional[str] = None) -> Pulled:
64
+ """Downloads a factory you can open, checking every file's hash; with ``dir``, writes it there.
65
+
66
+ A bundle that cannot be checked whole is refused unless ``partial=True``.
67
+ """
68
+ return _hub(base_url, token, access_key).pull(factory_id, dir=dir, force=force, partial=partial)
69
+
70
+
71
+ def publish(factory_id: str, *, note: str = "", base_url: Optional[str] = None, token: Optional[str] = None, access_key: Optional[str] = None) -> dict:
72
+ """Publishes one of your factories: anyone can find and run it at once."""
73
+ return _hub(base_url, token, access_key).publish(factory_id, note=note)
74
+
75
+
76
+ def run(factory_id: str, inputs: Optional[Mapping[str, str]] = None, *, on_event: Optional[Callable[[dict], None]] = None,
77
+ on_decision: Optional[Callable[[dict], Optional[Mapping[str, str]]]] = None, base_url: Optional[str] = None,
78
+ token: Optional[str] = None, access_key: Optional[str] = None) -> dict:
79
+ """Runs a factory on factoryhub and follows it; ``on_decision`` relays the person's own decisions."""
80
+ return _hub(base_url, token, access_key).run(factory_id, inputs, on_event=on_event, on_decision=on_decision)
81
+
82
+
83
+ def follow_run(run_id: str, *, after: int = 0, on_event: Optional[Callable[[dict], None]] = None, every: float = 2.0,
84
+ base_url: Optional[str] = None, token: Optional[str] = None, access_key: Optional[str] = None) -> dict:
85
+ """Follows an existing hosted run and returns its outcome and cursor."""
86
+ return _hub(base_url, token, access_key).follow_run(run_id, after=after, on_event=on_event, every=every)
87
+
88
+
89
+ def runs(*, limit: Optional[int] = None, base_url: Optional[str] = None, token: Optional[str] = None, access_key: Optional[str] = None) -> List[dict]:
90
+ """Your recent hosted runs."""
91
+ return _hub(base_url, token, access_key).runs(limit=limit)
92
+
93
+
94
+ def verify_receipt(receipt: Union[Mapping[str, Any], str, Path], *, keys: Optional[List[dict]] = None, deliverable: Optional[str] = None,
95
+ base_url: Optional[str] = None, access_key: Optional[str] = None) -> Verification:
96
+ """Checks a run receipt's Ed25519 signature, offline when ``keys`` are given.
97
+
98
+ ``receipt`` is a dict, a JSON text or a path. With ``deliverable``, also
99
+ checks the text against the hash the receipt records. The same checks and
100
+ messages as the engine's verifyReceipt. Without ``keys``, it is checked as
101
+ a receipt from the hub at ``base_url``: on https://factory.mindburn.org
102
+ against the production keys pinned in this package, elsewhere against the
103
+ keys that hub publishes, and its issuer against the hub's host.
104
+ """
105
+ if keys is None:
106
+ return Hub(base_url, access_key=access_key).verify_receipt(receipt, deliverable=deliverable)
107
+ result = verify_receipt_with_keys(load_receipt(receipt), keys, deliverable)
108
+ result.trust = "given"
109
+ return result